.elseif lparam==wm_lbuttondblclk
invoke sendmessage,hwnd,wm_command,idm_restore,0
.endif
.endif
.else
invoke defwindowproc,hwnd,umsg,wparam,lparam
ret
.endif
xor eax,eax
ret
wndproc endp
end start
analysis:
the program will display a simple window. when you press the minimize button, it will hide itself and put an icon into the system tray. when you double-click on the icon, the program will restore itself and remove the icon from the system tray. when you right-click on it, a popup menu is displayed. you can choose to restore the program or exit it. .if umsg==wm_create
invoke createpopupmenu
mov hpopupmenu,eax
invoke appendmenu,hpopupmenu,mf_string,idm_restore,addr restorestring
invoke appendmenu,hpopupmenu,mf_string,idm_exit,addr exitstring
when the main window is created, it creates a popup menu and append two menu items. appendmenu has the following syntax:
appendmenu proto hmenu:dword, uflags:dword, uidnewitem:dword, lpnewitem:dwordafter the popup menu is created, the main window waits patiently for the user to press minimize button.
- hmenu is the handle of the menu you want to append the item to
- uflags tells windows about the menu item to be appended to the menu whether it is a bitmap or a string or an owner-draw item, enabled, grayed or disable etc. you can get the complete list from win32 api reference. in our example, we use mf_string which means the menu item is a string.
- uidnewitem is the id of the menu item. this is a user-defined value that is used to represent the menu item.
- lpnewitem specifies the content of the menu item, depending on what you specify in uflags member. since we specify mf_string in uflags member, lpnewitem must contain the pointer to the string to be displayed in the popup menu.
when a window is minimized, it receives wm_size message with size_minimized value in wparam.
.elseif umsg==wm_size
.if wparam==size_minimized
mov note.cbsize,sizeof notifyicondata
push hwnd
pop note.hwnd
mov note.uid,idi_tray
mov note.uflags,nif_icon+nif_message+nif_tip
mov note.ucallbackmessage,wm_shellnotify
invoke loadicon,null,idi_winlogo
mov note.hicon,eax
invoke lstrcpy,addr note.sztip,addr appname
invoke showwindow,hwnd,sw_hide
invoke shell_notifyicon,nim_add,addr note