📄 tut8.html
字号:
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>WndProc
endp</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>end start</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>**************************************************************************************************************************</font></font></font></b>
<center>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Menu.rc</font></font></font></b>
</center>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>**************************************************************************************************************************</font></font></font></b><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_TEST 1</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_HELLO 2</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_GOODBYE 3</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_EXIT 4</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>FirstMenu
MENU</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>{</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> POPUP
"&PopUp"</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
{</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM "&Say Hello",IDM_HELLO</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM "Say &GoodBye", IDM_GOODBYE</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM SEPARATOR</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM "E&xit",IDM_EXIT</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
}</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> MENUITEM
"&Test", IDM_TEST</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>}</font></font></font></b>
<br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<h3> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=+0>Analysis:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Let's analyze
the resource file first.</font></font></font> <br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_TEST 1
/* equal to IDM_TEST equ 1*/</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_HELLO 2</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_GOODBYE 3</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#define
IDM_EXIT 4</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b> </dl>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The above lines
define the menu IDs used by the menu script. You can assign any value to the
ID as long as the value is unique in the menu.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>FirstMenu
MENU</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Declare
your menu with MENU keyword.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> POPUP
"&PopUp"</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
{</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM "&Say Hello",IDM_HELLO</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM "Say &GoodBye", IDM_GOODBYE</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM SEPARATOR</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
MENUITEM "E&xit",IDM_EXIT</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
}</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Define a
popup menu with four menu items, the third one is a menu separator.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> MENUITEM
"&Test", IDM_TEST</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Define a
menu bar in the main menu.</font></font></font> <br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Next we will
examine the source code.</font></font></font> <br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MenuName
db "FirstMenu",0
; The name of our menu in the resource file.</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Test_string
db "You selected Test menu item",0</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Hello_string
db "Hello, my friend",0</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Goodbye_string
db "See you again, bye",0</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b> </dl>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MenuName is
the name of the menu in the resource file. Note that you can define more than
one menu in the resource file so you must specify which menu you want to use.
The remaining three lines define the text strings to be displayed in message
boxes that are invoked when the appropriate menu item is selected by the user.</font></font></font>
<br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_TEST
equ 1
; Menu IDs</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_HELLO
equ 2</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_GOODBYE
equ 3</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_EXIT
equ 4</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b> </dl>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Define menu
IDs for use in the window procedure. These values MUST be identical to those
defined in the resource file.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF uMsg==WM_COMMAND</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov eax,wParam</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF ax==IDM_TEST</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke MessageBox,NULL,ADDR Test_string,OFFSET AppName,MB_OK</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF ax==IDM_HELLO</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke MessageBox, NULL,ADDR Hello_string, OFFSET AppName,MB_OK</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF ax==IDM_GOODBYE</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke MessageBox,NULL,ADDR Goodbye_string, OFFSET AppName, MB_OK</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSE</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke DestroyWindow,hWnd</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ENDIF</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In the window
procedure, we process WM_COMMAND messages. When the user selects a menu item,
the menu ID of that menu item is sended to the window procedure in the low
word of wParam along with the WM_COMMAND message. So when we store the value
of wParam in eax, we compare the value in ax to the menu IDs we defined previously
and act accordingly. In the first three cases, when the user selects Test,
Say Hello, and Say GoodBye menu items, we just display a text string in a
message box.</font></font></font> <br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>If the user
selects Exit menu item, we call DestroyWindow with the handle of our window
as its parameter which will close our window.</font></font></font> <br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>As you can
see, specifying menu name in a window class is quite easy and straightforward.
However you can also use an alternate method to load a menu in your window.
I won't show the entire source code here. The resource file is the same in
both methods. There are some minor changes in the source file which I 'll
show below.</font></font></font> <br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.data?</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hInstance
HINSTANCE ?</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>CommandLine
LPSTR ?</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hMenu
HMENU ?
; handle of our menu</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b> </dl>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Define a variable
of type HMENU to store our menu handle.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> <b>
invoke LoadMenu, hInst, OFFSET MenuName</b></font></font></font> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov hMenu,eax</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,\</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
hInst,NULL</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Before calling
CreateWindowEx, we call LoadMenu with the instance handle and a pointer to
the name of our menu. LoadMenu returns the handle of our menu in the resource
file which we pass to CreateWindowEx.</font></font></font> <br>
<hr WIDTH="100%">
<center>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>[<a href="http://win32asm.cjb.net">Iczelion's
Win32 Assembly HomePage</a>]</font></font></font></b>
</center>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></dl>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -