(一)
Invoke checkmenuitem,hmenu,ebx,eax
.elseif eax>=IDM_BIG&&eax<=DM_DETAIL
invokecheckmenuradioitem,hmenu,IDM_BIG,IDM_DETAIL,eax,MF_BYCOMMAND
.endif
重点与难点:
1、关于checkmenuitem
The CheckMenuItem function sets the state of the specified menuitem's check-mark attribute to either selected or clear.
设置菜单项的check状态的选择或清除
Syntax
DWORD CheckMenuItem(
HMENU hmenu,
UINT uIDCheckItem,
UINT uCheck
);
参数说明
UCHECK如下:
MF_BYCOMMAND uIDCheckItem参数为为命令ID
Indicates that the uIDCheckItem parameter gives the identifier ofthe menu item. The MF_BYCOMMAND flag is the default, if neither theMF_BYCOMMAND nor MF_BYPOSITION flag is specified.
MF_BYPOSITION uIDCheckItem参数为从0起始的菜单序号
Indicates that the uIDCheckItem parameter gives the zero-basedrelative position of the menu item.
MF_CHECKED 设置菜单项为选择
Sets the check-mark attribute to the selected state.
MF_UNCHECKED 设置菜单项为没有选择
Sets the check-mark attribute to the clear state
2、关于checkmenuradioitem
The CheckMenuRadioItem function checks a specified menu item andmakes it a radio item. At the same time, the function clears allother menu items in the associated group and clears the radio-itemtype flag for those items
用于radio类型的菜单项选择,选中某一项并清除其它项的选择标志,其它项由 UINT idFirst,
UINT idLast两个参数指定。
Syntax
BOOL CheckMenuRadioItem(
HMENU hmenu,
UINT idFirst,
UINT idLast,
UINT idCheck,
UINT uFlags
);
uFlags 参数:If this parameter is MF_BYCOMMAND, the other parametersspecify menu item identifiers(命令ID). If it is MF_BYPOSITION, theother parameters specify the menu item positions(菜单序号)
(二)
.elseif eax==wm_bycommand
mov eax,wparam
movzx eax,ax
..if eax==IDM_HELP||IDM_ABOUT
invoke _displaymenuitem,wparam
.else
invoke defwindowproc,hwnd,umsg,wparam,lparam;交给默认窗口处理程序处理
ret
.endif
.elseif
(三)右键弹出菜单
.elseif eax==WM_RBUTTONDOWN
invoke getcursorpos,addr @stpos;
invoketrackpopupmenu,hsubmenu,TPM_LEFT,@stops.x,@stops.y,null,hwnd,null;
.elseif eax==wm_close
call _quit
.else
invoke defwindowproc,hwnd,umsg,wparam,lparam;交给默认窗口处理程序处理
ret
.endif
重点与难点:
1、 the GetCursorPos function retrieves the cursor's position, inscreen coordinates.
返回当前光标位置,即鼠标位置是是相对于屏幕的座标。
Syntax
BOOL GetCursorPos(
LPPOINT lpPoint
);
2、 trackpopupmenu
The TrackPopupMenu function displays a shortcut menu at thespecified location and tracks the selection of items on the menu.The shortcut menu can appear anywhere on the screen.
在屏幕的任何指定位置显示一个弹出菜单。
Syntax
BOOL TrackPopupMenu(
HMENU hMenu,
UINT uFlags,
int x,
int y,
int nReserved,
HWND hWnd,
HWND prcRect
);
参数说明
(1) uFlags
TPM_CENTERALIGN
If this flag is set, the function centers the shortcut menuhorizontally relative to the coordinate specified by the xparameter.
TPM_LEFTALIGN
If this flag is set, the function positions the shortcut menu sothat its left side is aligned with the coordinate specified by thex parameter.
TPM_RIGHTALIGN
Positions the shortcut menu so that its right side is aligned withthe coordinate specified by the x parameter.
Use one of the following flags to specify how the functionpositions the shortcut menu vertically.
TPM_BOTTOMALIGN
If this flag is set, the function positions the shortcut menu sothat its bottom side is aligned with the coordinate specified bythe y parameter.
TPM_TOPALIGN
If this flag is set, the function positions the shortcut menu sothat its top side is aligned with the coordinate specified by the yparameter.
TPM_VCENTERALIGN
If this flag is set, the function centers the shortcut menuvertically relative to the coordinate specified by the yparameter.
Use the following flags to determine the user selection withouthaving to set up a parent window for the menu.
以上为菜单显示时的对齐方式相对于x、y参数
TPM_NONOTIFY用户选择菜单项时不发送通知消息
If this flag is set, the function does not send notificationmessages when the user clicks on a menu item.
TPM_RETURNCMD 返回命令ID
If this flag is set, the function returns the menu item identifierof the user's selection in the return value.
Use one of the following flags to specify which mouse button theshortcut menu tracks.
TPM_LEFTBUTTON 左键键选择菜单
If this flag is set, the user can select menu items with only theleft mouse button.
TPM_RIGHTBUTTON 右键选择菜单
If this flag is set, the user can select menu items with both theleft and right mouse buttons.
Windows 98/Me, Windows 2000/XP:Use any reasonable combination ofthe following flags to modify the animation of a menu. For example,by selecting a horizontal and a vertical flag you can achievediagonal animation. 可以用下列参数来展示菜单显示的动态效果
TPM_HORNEGANIMATION
Animates the menu from right to left.
TPM_HORPOSANIMATION
Animates the menu from left to right.
TPM_NOANIMATION
Displays menu without animation.
TPM_VERNEGANIMATION
Animates the menu from bottom to top.
TPM_VERPOSANIMATION
Animates the menu from top to bottom
(2) nReserved
Reserved; must be zero. 必须为null
(3) hWnd 要弹出菜单的句柄
[in] Handle to the window that owns the shortcut menu. This windowreceives all messages from the menu. The window does not receive aWM_COMMAND message from the menu until the function returns. If youspecify TPM_NONOTIFY in the uFlags parameter, the function does notsend messages to the window identified by hWnd. However, you muststill pass a window handle in hWnd. It can be any window handlefrom your application
仅指窗口的弹出菜单类型,在本函数返回后,窗口才会接收到wm_command消息,但POPUP类型的菜单只能在第二层中定义,如文件属于第一层,打开、新建等才属于第二层,所以hdunmrnu参数取得了子菜单句柄,invokegetsubmenu.hnemu,npos
,mov hsubmenu,eax。npos指定要取得的第一层菜单的序号,如第一层有2个菜单项,文件和查看,则文件为0,查看为1。
Invoke checkmenuitem,hmenu,ebx,eax
.elseif eax>=IDM_BIG&&eax<=DM_DETAIL
invokecheckmenuradioitem,hmenu,IDM_BIG,IDM_DETAIL,eax,MF_BYCOMMAND
.endif
重点与难点:
1、关于checkmenuitem
The CheckMenuItem function sets the state of the specified menuitem's check-mark attribute to either selected or clear.
设置菜单项的check状态的选择或清除
Syntax
DWORD CheckMenuItem(
HMENU hmenu,
UINT uIDCheckItem,
UINT uCheck
);
参数说明
UCHECK如下:
MF_BYCOMMAND uIDCheckItem参数为为命令ID
Indicates that the uIDCheckItem parameter gives the identifier ofthe menu item. The MF_BYCOMMAND flag is the default, if neither theMF_BYCOMMAND nor MF_BYPOSITION flag is specified.
MF_BYPOSITION uIDCheckItem参数为从0起始的菜单序号
Indicates that the uIDCheckItem parameter gives the zero-basedrelative position of the menu item.
MF_CHECKED 设置菜单项为选择
Sets the check-mark attribute to the selected state.
MF_UNCHECKED 设置菜单项为没有选择
Sets the check-mark attribute to the clear state
2、关于checkmenuradioitem
The CheckMenuRadioItem function checks a specified menu item andmakes it a radio item. At the same time, the function clears allother menu items in the associated group and clears the radio-itemtype flag for those items
用于radio类型的菜单项选择,选中某一项并清除其它项的选择标志,其它项由 UINT idFirst,
UINT idLast两个参数指定。
Syntax
BOOL CheckMenuRadioItem(
HMENU hmenu,
UINT idFirst,
UINT idLast,
UINT idCheck,
UINT uFlags
);
uFlags 参数:If this parameter is MF_BYCOMMAND, the other parametersspecify menu item identifiers(命令ID). If it is MF_BYPOSITION, theother parameters specify the menu item positions(菜单序号)
(二)
.elseif eax==wm_bycommand
mov eax,wparam
movzx eax,ax
..if eax==IDM_HELP||IDM_ABOUT
invoke _displaymenuitem,wparam
.else
invoke defwindowproc,hwnd,umsg,wparam,lparam;交给默认窗口处理程序处理
ret
.endif
.elseif
(三)右键弹出菜单
.elseif eax==WM_RBUTTONDOWN
invoke getcursorpos,addr @stpos;
invoketrackpopupmenu,hsubmenu,TPM_LEFT,@stops.x,@stops.y,null,hwnd,null;
.elseif eax==wm_close
call _quit
.else
invoke defwindowproc,hwnd,umsg,wparam,lparam;交给默认窗口处理程序处理
ret
.endif
重点与难点:
1、 the GetCursorPos function retrieves the cursor's position, inscreen coordinates.
返回当前光标位置,即鼠标位置是是相对于屏幕的座标。
Syntax
BOOL GetCursorPos(
LPPOINT lpPoint
);
2、 trackpopupmenu
The TrackPopupMenu function displays a shortcut menu at thespecified location and tracks the selection of items on the menu.The shortcut menu can appear anywhere on the screen.
在屏幕的任何指定位置显示一个弹出菜单。
Syntax
BOOL TrackPopupMenu(
HMENU hMenu,
UINT uFlags,
int x,
int y,
int nReserved,
HWND hWnd,
HWND prcRect
);
参数说明
(1) uFlags
TPM_CENTERALIGN
If this flag is set, the function centers the shortcut menuhorizontally relative to the coordinate specified by the xparameter.
TPM_LEFTALIGN
If this flag is set, the function positions the shortcut menu sothat its left side is aligned with the coordinate specified by thex parameter.
TPM_RIGHTALIGN
Positions the shortcut menu so that its right side is aligned withthe coordinate specified by the x parameter.
Use one of the following flags to specify how the functionpositions the shortcut menu vertically.
TPM_BOTTOMALIGN
If this flag is set, the function positions the shortcut menu sothat its bottom side is aligned with the coordinate specified bythe y parameter.
TPM_TOPALIGN
If this flag is set, the function positions the shortcut menu sothat its top side is aligned with the coordinate specified by the yparameter.
TPM_VCENTERALIGN
If this flag is set, the function centers the shortcut menuvertically relative to the coordinate specified by the yparameter.
Use the following flags to determine the user selection withouthaving to set up a parent window for the menu.
以上为菜单显示时的对齐方式相对于x、y参数
TPM_NONOTIFY用户选择菜单项时不发送通知消息
If this flag is set, the function does not send notificationmessages when the user clicks on a menu item.
TPM_RETURNCMD 返回命令ID
If this flag is set, the function returns the menu item identifierof the user's selection in the return value.
Use one of the following flags to specify which mouse button theshortcut menu tracks.
TPM_LEFTBUTTON 左键键选择菜单
If this flag is set, the user can select menu items with only theleft mouse button.
TPM_RIGHTBUTTON 右键选择菜单
If this flag is set, the user can select menu items with both theleft and right mouse buttons.
Windows 98/Me, Windows 2000/XP:Use any reasonable combination ofthe following flags to modify the animation of a menu. For example,by selecting a horizontal and a vertical flag you can achievediagonal animation. 可以用下列参数来展示菜单显示的动态效果
TPM_HORNEGANIMATION
Animates the menu from right to left.
TPM_HORPOSANIMATION
Animates the menu from left to right.
TPM_NOANIMATION
Displays menu without animation.
TPM_VERNEGANIMATION
Animates the menu from bottom to top.
TPM_VERPOSANIMATION
Animates the menu from top to bottom
(2) nReserved
Reserved; must be zero. 必须为null
(3) hWnd 要弹出菜单的句柄
[in] Handle to the window that owns the shortcut menu. This windowreceives all messages from the menu. The window does not receive aWM_COMMAND message from the menu until the function returns. If youspecify TPM_NONOTIFY in the uFlags parameter, the function does notsend messages to the window identified by hWnd. However, you muststill pass a window handle in hWnd. It can be any window handlefrom your application
仅指窗口的弹出菜单类型,在本函数返回后,窗口才会接收到wm_command消息,但POPUP类型的菜单只能在第二层中定义,如文件属于第一层,打开、新建等才属于第二层,所以hdunmrnu参数取得了子菜单句柄,invokegetsubmenu.hnemu,npos
,mov hsubmenu,eax。npos指定要取得的第一层菜单的序号,如第一层有2个菜单项,文件和查看,则文件为0,查看为1。
_procwinmain endp
_winmaing proc
local @stwndclass:wndclassex
local @stmsg:MSG
local @haccelerator
invoke getmodulehandle,null
mov hinstance,eax
invoke loadmenu,hinstance,IDM_MIAN;加载菜单
mov hmenu,eax
invoke loadaccelerators,hinstance,IDA_MAIN;加载加速键
mov @haccelerator,eax
;注册窗口类和建立显示窗口省略
;...............
;...............
;重点:消息循环
.while true
invoke getmessage,addr @stmsg,null,0,0
.break .if eax==0
invoke translateaccelerator,hwinmain,@haccelerator,addr@stmsg
;关于translateaccelerator
;-----------
The TranslateAccelerator function processes accelerator keys formenu commands. The function translates a WM_KEYDOWN orWM_SYSKEYDOWN message to a WM_COMMAND or WM_SYSCOMMAND message (ifthere is an entry for the key in the specified accelerator table)and then sends the WM_COMMAND or WM_SYSCOMMAND message directly tothe appropriate window procedure. TranslateAccelerator does notreturn until the window procedure has processed the message.
对菜单的快键进行预处理,将WM_KEYDOWN或WM_SYSKEYDOWN消息处理成为WM_COMMAND或WM_SYSCOMMAND,并直接将消息送到窗口过程处理,直到窗口过程处理该消息后才返回.
Syntax
int TranslateAccelerator( HWND hWnd,
HACCEL hAccTable,加速键表的资源句柄
LPMSG lpMsg
);
Parameters
hWnd
[in] Handle to the window whose messages are to betranslated.
hAccTable
[in] Handle to the accelerator table. The accelerator table musthave been loaded by a call to the LoadAccelerators function orcreated by a call to the CreateAcceleratorTable function.
lpMsg
[in] Pointer to an MSG structure that contains message informationretrieved from the calling thread's message queue using theGetMessage or PeekMessage function.
[Return Value]
If the function succeeds, the return value isnonzero.执行成功返回非0
If the function fails, the return value is zero.不成功返回0
;-----------
;如果不属于加速键消息或处理失败,则进行标准的处理方案,否则以下不执行,因为该函数直接把
;消息发送到窗口过程,再进行发送
.if eax==0
invoke translatemessage,addr @stmsg
invoke dispatchmessage.addr @stmsg
.endif
.endw
ret
_winmain endp
start:
call _winmain
invoke exitprocess,null
end start
_winmaing proc
local @stwndclass:wndclassex
local @stmsg:MSG
local @haccelerator
invoke getmodulehandle,null
mov hinstance,eax
invoke loadmenu,hinstance,IDM_MIAN;加载菜单
mov hmenu,eax
invoke loadaccelerators,hinstance,IDA_MAIN;加载加速键
mov @haccelerator,eax
;注册窗口类和建立显示窗口省略
;...............
;...............
;重点:消息循环
.while true
invoke getmessage,addr @stmsg,null,0,0
.break .if eax==0
invoke translateaccelerator,hwinmain,@haccelerator,addr@stmsg
;关于translateaccelerator
;-----------
The TranslateAccelerator function processes accelerator keys formenu commands. The function translates a WM_KEYDOWN orWM_SYSKEYDOWN message to a WM_COMMAND or WM_SYSCOMMAND message (ifthere is an entry for the key in the specified accelerator table)and then sends the WM_COMMAND or WM_SYSCOMMAND message directly tothe appropriate window procedure. TranslateAccelerator does notreturn until the window procedure has processed the message.
对菜单的快键进行预处理,将WM_KEYDOWN或WM_SYSKEYDOWN消息处理成为WM_COMMAND或WM_SYSCOMMAND,并直接将消息送到窗口过程处理,直到窗口过程处理该消息后才返回.
Syntax
int TranslateAccelerator( HWND hWnd,
HACCEL hAccTable,加速键表的资源句柄
LPMSG lpMsg
);
Parameters
hWnd
[in] Handle to the window whose messages are to betranslated.
hAccTable
[in] Handle to the accelerator table. The accelerator table musthave been loaded by a call to the LoadAccelerators function orcreated by a call to the CreateAcceleratorTable function.
lpMsg
[in] Pointer to an MSG structure that contains message informationretrieved from the calling thread's message queue using theGetMessage or PeekMessage function.
[Return Value]
If the function succeeds, the return value isnonzero.执行成功返回非0
If the function fails, the return value is zero.不成功返回0
;-----------
;如果不属于加速键消息或处理失败,则进行标准的处理方案,否则以下不执行,因为该函数直接把
;消息发送到窗口过程,再进行发送
.if eax==0
invoke translatemessage,addr @stmsg
invoke dispatchmessage.addr @stmsg
.endif
.endw
ret
_winmain endp
start:
call _winmain
invoke exitprocess,null
end start