moriman
Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
|
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
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'
|