Win32 Assembly
TESTC param1 param2 param3 param4
' param1 param2 param3 param4', 0Dh
int main(int argc, char *argv[])
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
LPSTR lpCmdLine, int nCmdShow);
WINAPI equ STDCALL
WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD
WinMain PROTO :HINSTANCE, :HINSTANCE, :LPSTR, :SDWORD
LPTSTR GetCommandLine(void);
call GetModuleHandleA, NULL ; trova l'handle del modulo MAINWIN.EXE mov hInstance, eax ; e lo salva in hInstance call GetCommandLineA ; trova l'indirizzo della command line mov commandLine, eax ; e lo salva in commandLine call WinMain, hInstance, NULL, commandLine, SW_SHOWNORMAL call ExitProcess, eax ; exit code restituito da WinMain |
WNDCLASSEX STRUC cbSize UINT ? ; dimensione struttura in byte style UINT ? ; stile della classe finestra lpfnWndProc WNDPROC ? ; puntatore alla window procedure cbClsExtra LONG ? ; extra byte per la classe finestra cbWndExtra LONG ? ; extra byte per la finestra hInstance HANDLE ? ; handle dell'applicazione hIcon HICON ? ; handle dell'icona; hCursor HCURSOR ? ; handle del cursore del mouse hbrBackground HBRUSH ? ; colore di sfondo lpszMenuName LPCTSTR ? ; puntatore alla risorsa menu lpszClassName LPCTSTR ? ; puntatore alla stringa di classe hIconSm HICON ? ; handle dell'icona piccola WNDCLASSEX ENDS |
wc WNDCLASSEX < ? >
LOCAL wc :WNDCLASSEX
mov wc.cbSize, SIZE WNDCLASSEX
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW OR CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, 0
mov wc.cbWndExtra, 0
mov wc.hInstance, hInstance
MOV32 MACRO Destinazione, Sorgente push dword ptr Sorgente pop dword ptr Destinazione ENDM |
MOV32 wc.hInstance, hInstance
MOV32 MACRO Destinazione, Sorgente mov eax, Sorgente mov Destinazione, eax ENDM |
HICON LoadIconA(HINSTANCE hInst, LPCTSTR lpIconName);
invoke LoadIconA, NULL, IDI_WINLOGO mov wc.hIcon, eax |
HCURSOR LoadCursorA(HINSTANCE hInst, LPCTSTR lpCursorName);
invoke LoadCursorA, NULL, IDC_ARROW mov wc.hCursor, eax |
mov wc.hbrBackground, COLOR_WINDOW + 1
mov wc.lpszMenuName, NULL
className db 'MainWin', 0
mov wc.lpszClassName, offset className
mov wc.hIconSm, NULL
ATOM RegisterClassExA(CONST WNDCLASSEX *lpwcx);
call RegisterClassExA, offset wc
lea eax, wc call RegisterClassExA, eax |
invoke RegisterClassExA, ADDR wc
lea eax, wc push eax call RegisterClassExA |
invoke RegisterClassExA, ADDR wc ; richiesta di registrazione test eax, eax ; errore ? jz exitWinMain ; termina con eax = 0 |
HWND CreateWindowEx( DWORD dwExStyle, /* extended window style */ LPCTSTR lpClassName, /* pointer to registered class name */ LPCTSTR lpWindowName, /* pointer to window name */ DWORD dwStyle, /* window style */ int x, /* horizontal position of window */ int y, /* vertical position of window */ int nWidth, /* window width */ int nHeight, /* window height */ HWND hWndParent, /* handle to parent or owner window */ HMENU hMenu, /* handle to menu, or child-window identifier */ HINSTANCE hInstance, /* handle to application instance */ LPVOID lpParam /* pointer to window-creation data */ ); |
BOOL ShowWindow(HWND hWnd, int nCmdShow);
BOOL UpdateWindow(HWND hWnd);
call CreateWindowExA, WS_EX_OVERLAPPEDWINDOW, \ offset className, \ offset winTitle, \ WS_OVERLAPPEDWINDOW, \ CW_USEDEFAULT, \ CW_USEDEFAULT, \ CW_USEDEFAULT, \ CW_USEDEFAULT, \ NULL, \ NULL, \ hInstance, \ NULL test eax, eax ; errore ? jz exitWinMain ; termina con eax = 0 mov hWindow, eax ; salva l'handle della finestra call ShowWindow, hWindow, nCmdShow ; visualizza la finestra call UpdateWindow, hWindow ; aggiorna l'area client test eax, eax ; errore ? jz exitWinMain ; termina con eax = 0 |
MSG STRUC hwnd HWND ? ; handle della finestra destinataria message UINT ? ; codice messaggio wParam WPARAM ? ; informazioni addizionali lParam LPARAM ? ; informazioni addizionali time DWORD ? ; ora esatta di invio del messaggio pt POINT < ? > ; posizione del cursore del mouse MSG ENDS |
POINT STRUC x LONG ? ; ascissa y LONG ? ; ordinata POINT ENDS |
BOOL GetMessage(LPMSG lpMsg, HWND hWnd,
UINT wMsgFilterMin, UINT wMsgFilterMax);
BOOL TranslateMessage(CONST MSG *lpMsg);
BOOL DispatchMessage(CONST MSG *lpMsg);
LOCAL msg :MSG
MessageLoop: invoke GetMessage, ADDR msg, NULL, 0, 0 ; estrazione prossimo messaggio test eax, eax ; eax = 0 ? jz exitMessageLoop ; fine del loop (WM_QUIT) invoke TranslateMessage, ADDR msg ; decodifica messaggio invoke DispatchMessage, ADDR msg ; invio messaggio alla WinProc jmp MessageLoop ; ripeti exitMessageLoop: mov eax, msg.wParam ; exit code = OK exitWinMain: ; exit code = 0 (errore) |
LRESULT NomeWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_AAAA) /* se il messaggio e' WM_AAAA */ ...................... /* elabora il messaggio WM_AAAA */ else if (uMsg == WM_BBBB) /* se invece il messaggio e' WM_BBBB */ ...................... /* elabora il messaggio WM_BBBB */ ......................... ...................... else /* altrimenti chiama DefWindowProc */ return DefWindowProc(hWnd, uMsg, wParam, lParam); return 0; /* valore di ritorno di WndProc */ } |
VOID PostQuitMessage(int nExitCode);
UNICODE = 0
MessageBoxA PROTO :DWORD, :DWORD, :DWORD, :DWORD MessageBox equ < MessageBoxA > |