flat assembler
Message board for the users of flat assembler.

Index > Windows > Scrollbar problems

Author
Thread Post new topic Reply to topic
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
Hi,

The following test code opens a window containing a seperate vertical scrollbar control. I can set the scrollbar thumb where I want, capturing the following messages...

SB_LINEUP
SB_LINEDOWN
SB_PAGEUP
SB_PAGEDOWN

and then using SetScrollInfo to set the thumb to the correct position.

However, when I capture the following message

SB_THUMBPOSITION

and then use GetScrollPos to determine where the scroll thumb is, I get an error if the thumb started at position 0. If it started at any other position, there is no error reported. Whichever the starting position, the scroll thumb returns to the starting position instead of remaining where it has been moved to.

Any help would be greatly appreciated, as a search here for GetScrollPos returned 0 results Sad

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.code' code readable executable

  start:
        mov     dword [hWndMain], 00
        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  RegisterClass,wc
        invoke  CreateWindowEx, WS_EX_CLIENTEDGE, myClass, myTitle, WS_VISIBLE+WS_OVERLAPPEDWINDOW-WS_MAXIMIZEBOX-WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, [wc.hInstance], NULL
        mov     [hWndMain], eax
        invoke  GetCurrentProcess
        mov     [hProcess], eax
  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateAccelerator, [hWndMain], [hAccel], msg
        or      eax, eax
        jnz     msg_loop
        invoke  IsDialogMessage, [hWndMain], msg
        or      eax, eax
        jnz     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop
  end_loop:
        invoke  ExitProcess,[msg.wParam]

ShowError:
        pushad
        invoke  GetLastError
        invoke  FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM+FORMAT_MESSAGE_ALLOCATE_BUFFER,NULL,eax,LANG_NEUTRAL,ErrStrBuff,0,NULL
        invoke  MessageBox,HWND_DESKTOP,[ErrStrBuff],NULL,MB_ICONERROR+MB_OK
        popad
        ret

proc wndProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      .wmDESTROY
        cmp     [wmsg],WM_CREATE
        je      .wmCREATE
        cmp     [wmsg], WM_VSCROLL
        je      .wmVSCROLL
    .wmDEFAULT:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .wmBYE
    .wmVSCROLL:
        mov     eax, [wparam]
        and     eax, 0xFFFF
        cmp     eax, SB_LINEUP
        je      .sbLINEUP
        cmp     eax, SB_LINEDOWN
        je      .sbLINEDOWN
        cmp     eax, SB_PAGEUP
        je      .sbPAGEUP
        cmp     eax, SB_PAGEDOWN
        je      .sbPAGEDOWN
        cmp     eax, SB_THUMBPOSITION
        je      .sbvTHUMBPOSITION
        jmp     .wmDEFAULT
    .sbLINEUP:
        dec     [ScrollInfo.nPos]
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        jmp     .wmBYE
    .sbLINEDOWN:
        inc     [ScrollInfo.nPos]
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        jmp     .wmBYE
    .sbPAGEUP:
        mov     eax, [ScrollInfo.nPage]
        sub     [ScrollInfo.nPos], eax
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        jmp     .wmBYE
    .sbPAGEDOWN:
        mov     eax, [ScrollInfo.nPage]
        add     [ScrollInfo.nPos], eax
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        jmp     .wmBYE
    .sbvTHUMBPOSITION:
        invoke  GetScrollPos, [VtSBhWnd], SB_CTL
        or      eax, eax
        jnz     @f
        call    ShowError
        jmp     .wmBYE
    @@:
        mov     [ScrollInfo.nPos], eax
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        jmp     .wmBYE
    .wmCREATE:
        invoke  GetSystemMetrics, SM_CYVTHUMB
        mov     [szThumb], eax
        push    eax
        invoke  GetClientRect, [hwnd], rcClient
        pop     eax
        sub     [rcClient.bottom], eax
        push    eax
        invoke  CreateWindowEx, 0, ScrollBarClass, NULL, WS_VISIBLE+WS_CHILD+SBS_RIGHTALIGN+SBS_VERT, [rcClient.left], [rcClient.top], [rcClient.right], [rcClient.bottom], [hwnd], NULL, [wc.hInstance], NULL
        mov     [VtSBhWnd], eax
        pop     eax
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        invoke  ShowWindow, [hwnd], SW_SHOWNORMAL
        jmp     .wmBYE
    .wmDESTROY:
        invoke  PostQuitMessage,0
        xor     eax,eax
    .wmBYE:
        pop     edi esi ebx
        ret
endp


section '.data' data readable writeable
  hWndMain              dd ?
  hProcess              dd ?
  hAccel                dd ?
  myTitle               db 'Title',0
  myClass               db 'MyClass',0
  ScrollBarClass        db 'SCROLLBAR', 0
  ErrStrBuff            dd ?
  wc                    WNDCLASS 0,wndProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,myClass
  msg                   MSG
  rcClient              RECT
  VtSBhWnd              dd ?
  szThumb               dd ?
  ScrollInfo            SCROLLINFO sizeof.SCROLLINFO, SIF_ALL, 0, 500, 50, 0, 0

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL',\
        gdi32,   'GDI32.DLL'

include '%fasminc%\apia\Kernel32.inc'
include '%fasminc%\apia\User32.inc'
include '%fasminc%\apia\Gdi32.inc'
    
Post 21 Jul 2006, 10:24
View user's profile Send private message Reply with quote
moriman



Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman
OK, got it figured and I'll leave the code here for anyone else that needs it Very Happy
This returns the 32-bit position of the thumb and works with both SB_THUMBPOSITION and in realtime with SB_THUMBTRACK, which according to my copy of the Win32API.hlp, can't be done Confused

Code:
    .sbvTHUMBPOSITION:
        mov     [ScrollInfo.fMask], SIF_TRACKPOS
        invoke  GetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo
        push    [ScrollInfo.nTrackPos]
        pop     [ScrollInfo.nPos]
        mov     [ScrollInfo.fMask], SIF_ALL
        invoke  SetScrollInfo, [VtSBhWnd], SB_CTL, ScrollInfo, TRUE
        jmp     .wmBYE
    

[/b][/i]
Post 21 Jul 2006, 11:22
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter
I once had this problem, too. Win32API.hlp misinforms programmers in the GetScrollInfo article, saying that "there is no function to retrieve the 32-bit position scroll-box position as the user moves the scroll box". SIF_TRACKPOS can be used for this purpose and it works even in Windows 95. The newer editions of Platform SDK had corrected the description for GetScrollInfo.
Post 22 Jul 2006, 13:51
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.