Примеры. WinAPI: Окна, типы (FASM)11.09.2021 13:16
format PE GUI 4.0
entry Start
include 'win32ax.inc'
section '.code' code readable writeable executable
proc WinProc, hWnd, msg, wParam, lParam
cmp [msg], WM_CLOSE
jne @f
invoke DestroyWindow, [hWnd]
jmp .Exit
@@:
cmp [msg], WM_DESTROY
jne @f
invoke ExitProcess,0
@@:
cmp [msg], WM_COMMAND
jne @f
mov eax, [hwndButton]
cmp [lParam], eax
jne @f
invoke MessageBox, 0, 'Hi', 'Hello', MB_OK
@@:
.Exit:
invoke DefWindowProc, [hWnd], [msg], [wParam], [lParam]
ret
endp
Start:
invoke GetModuleHandle, 0
mov [wnd.hInstance], eax
invoke RegisterClass, wnd
test eax, eax
jnz @f
invoke MessageBox, 0, Error.FailRegisterClass, Error.Text, MB_OK+MB_ICONERROR
jmp Exit
@@:
invoke CreateWindowEx, 0, ClassName, WindowName, WS_OVERLAPPEDWINDOW + WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, 0, 0, [wnd.hInstance], 0
test eax, eax
jnz @f
invoke MessageBox, 0, Error.FailCreateWindow, Error.Text, MB_OK+MB_ICONERROR
jmp Exit
@@:
mov [hwnd], eax
invoke CreateWindowEx, 0, ClassButton, ButtonName, WS_VISIBLE+WS_CHILD, 10, 10, 50, 30, eax, 0, [wnd.hInstance], 0
mov [hwndButton], eax
@@:
invoke GetMessage, msg, [hwnd], 0, 0
test eax, eax
jz @f
invoke TranslateMessage, msg
invoke DispatchMessage, msg
jmp @b
@@:
Exit:
invoke ExitProcess,0
section '.data' data readable writeable
ClassName db 'WinClass',0
WindowName db 'Window Proj',0
ClassButton db 'BUTTON',0
ButtonName db 'Hello',0
hwnd dd 0
hwndButton dd 0
msg MSG
wnd WNDCLASS 0, WinProc, 0, 0, 0, 0, 0, COLOR_WINDOW, 0, ClassName
Error:
.Text db 'Error',0
.FailRegisterClass db 'RegisterClassA - Fail',0
.FailCreateWindow db 'CreateWindowExA - Fail',0
section '.idata' import readable writeable
library kernel, 'kernel32.dll',\
user, 'user32.dll'
import kernel,\
ExitProcess, 'ExitProcess',\
GetModuleHandle, 'GetModuleHandleA'
import user,\
MessageBox, 'MessageBoxA',\
RegisterClass, 'RegisterClassA',\
CreateWindowEx, 'CreateWindowExA',\
GetMessage, 'GetMessageA',\
TranslateMessage, 'TranslateMessage',\
DispatchMessage, 'DispatchMessageA',\
DestroyWindow, 'DestroyWindow',\
PostQuitMessage, 'PostQuitMessage',\
DefWindowProc, 'DefWindowProcA'
© Habrahabr.ru