Steward
分享是一種喜悅、更是一種幸福
程式語言 - Netwide Assembler (NASM) - Win32 API - Set Scrollbar
參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html
當視窗的可視區域(如:320x240像素)小於顯示圖片大小(如:640x480像素)時,這時可以使用Windows視窗元件Scrollbar,用來做顯示位置調整的動作,Scrollbar元件有垂直和水平兩種方向並且提供視窗事件回報機制(WM_VSCROLL、WM_HSCROLL),因此,這裡的Scrollbar元件並不能夠自動幫忙做顯示位置調整的動作,取而代之的是,在收到WM_VSCROLL、WM_HSCROLL事件時,使用者必須自己決定哪些東西要顯示在視窗的可視區域上
main.asm
%include "/opt/wadk/nasm/inc/windows.inc"
section .data
hWin DD 0
pCmdLine DD 0
hInstance DD 0
pDefWndProc DD 0
szAppName DB "main",0
SLUP DB "LINE++",0
SLDN DB "LINE--",0
SPUP DB "PAGE++",0
SPDN DB "PAGE--",0
msg istruc MSG
at .hwnd, DD 0
at .message, DD 0
at .wParam, DD 0
at .lParam, DD 0
at .time, DD 0
at .pt, DD 0, 0
iend
section .text
WndProc:
enter 0, 0
cmp DWORD [ebp + ARG2], WM_VSCROLL
je .vscroll
cmp DWORD [ebp + ARG2], WM_CLOSE
je .close
cmp DWORD [ebp + ARG2], WM_DESTROY
je .destroy
jmp .default
.vscroll:
cmp word [ebp + ARG3], SB_LINEUP
je .line_up
cmp word [ebp + ARG3], SB_LINEDOWN
je .line_down
cmp word [ebp + ARG3], SB_PAGEUP
je .page_up
cmp word [ebp + ARG3], SB_PAGEDOWN
je .page_down
jmp .finish
.line_up:
push SLUP
push DWORD [ebp + ARG1]
call SetWindowText
jmp .finish
.line_down:
push SLDN
push DWORD [ebp + ARG1]
call SetWindowText
jmp .finish
.page_up:
push SPUP
push DWORD [ebp + ARG1]
call SetWindowText
jmp .finish
.page_down:
push SPDN
push DWORD [ebp + ARG1]
call SetWindowText
jmp .finish
.close:
push DWORD [ebp + ARG1]
call DestroyWindow
xor eax, eax
jmp .finish
.destroy:
push 0
call PostQuitMessage
xor eax, eax
jmp .finish
.default:
push DWORD [ebp + ARG4]
push DWORD [ebp + ARG3]
push DWORD [ebp + ARG2]
push DWORD [ebp + ARG1]
push DWORD [pDefWndProc]
call CallWindowProc
.finish:
leave
ret 16
WinMain:
enter 0, 0
push NULL
push NULL
push NULL
push NULL
push 240
push 320
push 0
push 0
push WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_VSCROLL
push szAppName
push WC_DIALOG
push WS_EX_LEFT
call CreateWindowEx
mov [hWin], eax
push WndProc
push GWL_WNDPROC
push DWORD [hWin]
call SetWindowLong
mov [pDefWndProc], eax
push 0
push 100
push 0
push SB_VERT
push DWORD [hWin]
call SetScrollRange
push 1
push 50
push SB_VERT
push DWORD [hWin]
call SetScrollPos
.loop:
push 0
push 0
push 0
push msg
call GetMessage
cmp eax, 0
je .exit
push msg
call DispatchMessage
jmp .loop
.exit:
mov eax, [msg + MSG.wParam]
leave
ret 16
_start:
push 0
call GetModuleHandle
mov [hInstance], eax
call GetCommandLine
mov [pCmdLine], eax
push SW_SHOWNORMAL
push DWORD [pCmdLine]
push 0
push DWORD [hInstance]
call WinMain
push 0
call ExitProcess
完成