; Menu.asm Iczelion's example, slightly enhanced FASMW version
format PE GUI 4.0
entry start
include '%include%\win32a.inc'
IDM_MAIN = 10000
IDM_HELLO = 11
IDM_GOODBYE = 12
IDM_EXIT = 13
IDM_TEST = 14
;---------------------------------------------
section '.data' data readable writeable
_title db 'Menu Demo',0
_class db 'SimpleWinClass',0
mainhwnd dd ?
hinstance dd ?
msg MSG
wc WNDCLASS
_Test_string db 'You selected Test menu item',0
_Hello_string db 'Hello, my friend',0
_Goodbye_string db 'See you again, bye',0
;---------------------------------------------
section '.code' code readable executable
start:
invoke GetModuleHandle,0
mov [hinstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_WINDOW+1
mov [wc.lpszMenuName], IDM_MAIN
mov [wc.lpszClassName],_class
invoke RegisterClass,wc
invoke CreateWindowEx, 0, _class, _title, WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT, CW_USEDEFAULT , CW_USEDEFAULT, CW_USEDEFAULT,\
NULL, NULL, [hinstance], NULL
mov [mainhwnd],eax
invoke ShowWindow, [mainhwnd], SW_SHOWNORMAL
invoke UpdateWindow, [mainhwnd]
msg_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
end_loop:
invoke ExitProcess,[msg.wParam]
;---------------------------------------------
proc WindowProc, hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_COMMAND
je wmcommand
cmp [wmsg],WM_DESTROY
je wmdestroy
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish
wmcommand:
mov eax, [wparam]
and eax, 0FFFh
cmp eax, IDM_HELLO
je hello
cmp eax, IDM_GOODBYE
je goodbye
cmp eax, IDM_TEST
je teststr
cmp eax, IDM_EXIT
je wmdestroy
jmp defwndproc
hello:
invoke MessageBox, HWND_DESKTOP,\
_Hello_string, _title, MB_ICONINFORMATION+MB_OK
jmp finish
goodbye:
invoke MessageBox, HWND_DESKTOP,\
_Goodbye_string, _title, MB_ICONINFORMATION+MB_OK
jmp finish
teststr:
invoke MessageBox, HWND_DESKTOP,\
_Test_string, _title, MB_ICONINFORMATION+MB_OK
jmp finish
wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
return
;-----------------------------------------------
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'
import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'
import user,\
RegisterClass,'RegisterClassA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetMessage,'GetMessageA',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
LoadIcon,'LoadIconA',\
PostQuitMessage,'PostQuitMessage',\
ShowWindow,'ShowWindow',\
UpdateWindow, 'UpdateWindow',\
MessageBox,'MessageBoxA'
;-----------------------------------------------
section '.rsrc' resource data readable
directory RT_MENU, menu1
resource menu1,\
IDM_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu
menu main_menu
menuitem '&PopUp',0,MFR_POPUP
menuitem '&Say Hello',IDM_HELLO,0
menuitem 'Say &Goodbye',IDM_GOODBYE,0
menuseparator
menuitem 'E&xit',IDM_EXIT, MFR_END
menuitem '&Help', IDM_TEST,MFR_POPUP + MFR_END
menuitem '&Test...',IDM_TEST,MFR_END
;====================================================