📄 lion-tutorial08.htm
字号:
<b> mov wc.lpfnWndProc, OFFSET WndProc</b> <br>
<b> mov wc.cbClsExtra,NULL</b> <br>
<b> mov wc.cbWndExtra,NULL</b> <br>
<b> push hInst</b> <br>
<b> pop wc.hInstance</b> <br>
<b> mov wc.hbrBackground,COLOR_WINDOW+1</b>
<br>
<b> mov wc.lpszMenuName,OFFSET MenuName
; Put our menu name here</b> <br>
<b> mov wc.lpszClassName,OFFSET ClassName</b>
<br>
<b> invoke LoadIcon,NULL,IDI_APPLICATION</b> <br>
<b> mov wc.hIcon,eax</b> <br>
<b> mov wc.hIconSm,eax</b> <br>
<b> invoke LoadCursor,NULL,IDC_ARROW</b> <br>
<b> mov wc.hCursor,eax</b> <br>
<b> invoke RegisterClassEx, addr wc</b> <br>
<b> invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\</b>
<br>
<b> WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\</b>
<br>
<b> CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\</b>
<br>
<b> hInst,NULL</b>
<br>
<b> mov hwnd,eax</b> <br>
<b> invoke ShowWindow, hwnd,SW_SHOWNORMAL</b> <br>
<b> invoke UpdateWindow, hwnd</b> <br>
<b> .WHILE TRUE</b> <br>
<b>
invoke GetMessage, ADDR msg,NULL,0,0</b> <br>
<b>
.BREAK .IF (!eax)</b> <br>
<b>
invoke DispatchMessage, ADDR msg</b> <br>
<b> .ENDW</b> <br>
<b> mov eax,msg.wParam</b> <br>
<b> ret</b> <br>
<b>WinMain endp</b>
<p><b>WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</b> <br>
<b> .IF uMsg==WM_DESTROY</b> <br>
<b> invoke PostQuitMessage,NULL</b>
<br>
<b> .ELSEIF uMsg==WM_COMMAND</b> <br>
<b> mov eax,wParam</b> <br>
<b> .IF ax==IDM_TEST</b> <br>
<b> invoke
MessageBox,NULL,ADDR Test_string,OFFSET AppName,MB_OK</b> <br>
<b> .ELSEIF ax==IDM_HELLO</b> <br>
<b> invoke
MessageBox, NULL,ADDR Hello_string, OFFSET AppName,MB_OK</b> <br>
<b> .ELSEIF ax==IDM_GOODBYE</b>
<br>
<b> invoke
MessageBox,NULL,ADDR Goodbye_string, OFFSET AppName, MB_OK</b> <br>
<b> .ELSE</b> <br>
<b> invoke
DestroyWindow,hWnd</b> <br>
<b> .ENDIF</b> <br>
<b> .ELSE</b> <br>
<b> invoke DefWindowProc,hWnd,uMsg,wParam,lParam</b>
<br>
<b> ret</b> <br>
<b> .ENDIF</b> <br>
<b> xor eax,eax</b> <br>
<b> ret</b> <br>
<b>WndProc endp</b> <br>
<b>end start</b> <br>
<b>**************************************************************************************************************************</b>
<center>
<b>Menu.rc</b>
</center>
<b>**************************************************************************************************************************</b>
<p><b>#define IDM_TEST 1</b> <br>
<b>#define IDM_HELLO 2</b> <br>
<b>#define IDM_GOODBYE 3</b> <br>
<b>#define IDM_EXIT 4</b>
<p><b>FirstMenu MENU</b> <br>
<b>{</b> <br>
<b> POPUP "&PopUp"</b> <br>
<b> {</b> <br>
<b> MENUITEM "&Say Hello",IDM_HELLO</b>
<br>
<b> MENUITEM "Say &GoodBye",
IDM_GOODBYE</b> <br>
<b> MENUITEM SEPARATOR</b>
<br>
<b> MENUITEM "E&xit",IDM_EXIT</b>
<br>
<b> }</b> <br>
<b> MENUITEM "&Test", IDM_TEST</b> <br>
<b>}</b> <br>
<h3> Analysis:</h3>
Let's analyze the resource file first. <br>
<dl><b>#define IDM_TEST 1
/* equal to IDM_TEST equ 1*/</b> <br>
<b>#define IDM_HELLO 2</b> <br>
<b>#define IDM_GOODBYE 3</b> <br>
<b>#define IDM_EXIT 4</b> <br>
</dl>
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.
<p><b>FirstMenu MENU</b>
<p>Declare your menu with MENU keyword.
<p><b> POPUP "&PopUp"</b> <br>
<b> {</b> <br>
<b> MENUITEM "&Say Hello",IDM_HELLO</b>
<br>
<b> MENUITEM "Say &GoodBye",
IDM_GOODBYE</b> <br>
<b> MENUITEM SEPARATOR</b>
<br>
<b> MENUITEM "E&xit",IDM_EXIT</b>
<br>
<b> }</b>
<p>Define a popup menu with four menu items, the third one is a menu separator.
<p><b> MENUITEM "&Test", IDM_TEST</b>
<p>Define a menu bar in the main menu. <br>
Next we will examine the source code. <br>
<dl><b>MenuName db "FirstMenu",0
; The name of our menu in the resource file.</b> <br>
<b>Test_string db "You selected Test menu item",0</b> <br>
<b>Hello_string db "Hello, my friend",0</b> <br>
<b>Goodbye_string db "See you again, bye",0</b> <br>
</dl>
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. <br>
<dl><b>IDM_TEST equ 1
; Menu IDs</b> <br>
<b>IDM_HELLO equ 2</b> <br>
<b>IDM_GOODBYE equ 3</b> <br>
<b>IDM_EXIT equ 4</b> <br>
</dl>
Define menu IDs for use in the window procedure. These values MUST be identical
to those defined in the resource file.
<p><b> .ELSEIF uMsg==WM_COMMAND</b> <br>
<b> mov eax,wParam</b> <br>
<b> .IF ax==IDM_TEST</b> <br>
<b> invoke
MessageBox,NULL,ADDR Test_string,OFFSET AppName,MB_OK</b> <br>
<b> .ELSEIF ax==IDM_HELLO</b> <br>
<b> invoke
MessageBox, NULL,ADDR Hello_string, OFFSET AppName,MB_OK</b> <br>
<b> .ELSEIF ax==IDM_GOODBYE</b>
<br>
<b> invoke
MessageBox,NULL,ADDR Goodbye_string, OFFSET AppName, MB_OK</b> <br>
<b> .ELSE</b> <br>
<b> invoke
DestroyWindow,hWnd</b> <br>
<b> .ENDIF</b>
<p>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. <br>
If the user selects Exit menu item, we call DestroyWindow with the handle
of our window as its parameter which will close our window. <br>
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. <br>
<dl><b>.data?</b> <br>
<b>hInstance HINSTANCE ?</b> <br>
<b>CommandLine LPSTR ?</b> <br>
<b>hMenu HMENU ?
; handle of our menu</b> <br>
</dl>
Define a variable of type HMENU to store our menu handle.
<p> <b> invoke LoadMenu, hInst, OFFSET
MenuName</b> <br>
<b> mov hMenu,eax</b>
<br>
<b> INVOKE CreateWindowEx,NULL,ADDR
ClassName,ADDR AppName,\</b> <br>
<b> WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\</b>
<br>
<b> CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,\</b>
<br>
<b> hInst,NULL</b>
<p>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
</dl>
<hr size="1">
<div align="center"> This article come from Iczelion's asm page, Welcom to <a href="http://asm.yeah.net">http://asm.yeah.net</a></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -