⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lion-tutorial08.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 2 页
字号:
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.lpfnWndProc, OFFSET WndProc</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.cbClsExtra,NULL</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.cbWndExtra,NULL</b> <br>
    <b>&nbsp;&nbsp;&nbsp; push&nbsp; hInst</b> <br>
    <b>&nbsp;&nbsp;&nbsp; pop&nbsp;&nbsp; wc.hInstance</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.hbrBackground,COLOR_WINDOW+1</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.lpszMenuName,OFFSET MenuName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    ; Put our menu name here</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.lpszClassName,OFFSET ClassName</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp; invoke LoadIcon,NULL,IDI_APPLICATION</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.hIcon,eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.hIconSm,eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke LoadCursor,NULL,IDC_ARROW</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; wc.hCursor,eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke RegisterClassEx, addr wc</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hInst,NULL</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; hwnd,eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke ShowWindow, hwnd,SW_SHOWNORMAL</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke UpdateWindow, hwnd</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .WHILE TRUE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke GetMessage, ADDR msg,NULL,0,0</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .BREAK .IF (!eax)</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke DispatchMessage, ADDR msg</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .ENDW</b> <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp; eax,msg.wParam</b> <br>
    <b>&nbsp;&nbsp;&nbsp; ret</b> <br>
    <b>WinMain endp</b> 
  <p><b>WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .IF uMsg==WM_DESTROY</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke PostQuitMessage,NULL</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp; .ELSEIF uMsg==WM_COMMAND</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,wParam</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF ax==IDM_TEST</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    MessageBox,NULL,ADDR Test_string,OFFSET AppName,MB_OK</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF ax==IDM_HELLO</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    MessageBox, NULL,ADDR Hello_string, OFFSET AppName,MB_OK</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF ax==IDM_GOODBYE</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    MessageBox,NULL,ADDR Goodbye_string, OFFSET AppName, MB_OK</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    DestroyWindow,hWnd</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .ELSE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke DefWindowProc,hWnd,uMsg,wParam,lParam</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .ENDIF</b> <br>
    <b>&nbsp;&nbsp;&nbsp; xor&nbsp;&nbsp;&nbsp; eax,eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; 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>&nbsp;POPUP "&amp;PopUp"</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "&amp;Say Hello",IDM_HELLO</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "Say &amp;GoodBye", 
    IDM_GOODBYE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM SEPARATOR</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "E&amp;xit",IDM_EXIT</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b> <br>
    <b>&nbsp;MENUITEM "&amp;Test", IDM_TEST</b> <br>
    <b>}</b> <br>
    &nbsp; 
  <h3> Analysis:</h3>
  Let's analyze the resource file first. <br>
  &nbsp; 
  <dl><b>#define IDM_TEST 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    /* 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>
    &nbsp;</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>&nbsp;POPUP "&amp;PopUp"</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "&amp;Say Hello",IDM_HELLO</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "Say &amp;GoodBye", 
    IDM_GOODBYE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM SEPARATOR</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "E&amp;xit",IDM_EXIT</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b> 
  <p>Define a popup menu with four menu items, the third one is a menu separator. 
  <p><b>&nbsp;MENUITEM "&amp;Test", IDM_TEST</b> 
  <p>Define a menu bar in the main menu. <br>
    Next we will examine the source code. <br>
    &nbsp; 
  <dl><b>MenuName db "FirstMenu",0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    ; 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>
    &nbsp;</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>
  &nbsp; 
  <dl><b>IDM_TEST equ 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    ; 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>
    &nbsp;</dl>
  Define menu IDs for use in the window procedure. These values MUST be identical 
  to those defined in the resource file. 
  <p><b>&nbsp;&nbsp;&nbsp; .ELSEIF uMsg==WM_COMMAND</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,wParam</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF ax==IDM_TEST</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    MessageBox,NULL,ADDR Test_string,OFFSET AppName,MB_OK</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF ax==IDM_HELLO</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    MessageBox, NULL,ADDR Hello_string, OFFSET AppName,MB_OK</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF ax==IDM_GOODBYE</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    MessageBox,NULL,ADDR Goodbye_string, OFFSET AppName, MB_OK</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
    DestroyWindow,hWnd</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .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>
    &nbsp; 
  <dl><b>.data?</b> <br>
    <b>hInstance HINSTANCE ?</b> <br>
    <b>CommandLine LPSTR ?</b> <br>
    <b>hMenu HMENU ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    ; handle of our menu</b> <br>
    &nbsp;</dl>
  Define a variable of type HMENU to store our menu handle. 
  <p>&nbsp;<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke LoadMenu, hInst, OFFSET 
    MenuName</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp; hMenu,eax</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INVOKE CreateWindowEx,NULL,ADDR 
    ClassName,ADDR AppName,\</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,\</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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 + -