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

📄 tut8.html

📁 win32汇编教程 希望各位多多支持
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    <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>&nbsp;POPUP 
    "&amp;PopUp"</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    {</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM "&amp;Say Hello",IDM_HELLO</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM "Say &amp;GoodBye", IDM_GOODBYE</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM SEPARATOR</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM "E&amp;xit",IDM_EXIT</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;MENUITEM 
    "&amp;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>&nbsp; 
  <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>&nbsp; 
  <dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>#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*/</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>&nbsp;</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>&nbsp;POPUP 
    "&amp;PopUp"</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    {</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM "&amp;Say Hello",IDM_HELLO</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM "Say &amp;GoodBye", IDM_GOODBYE</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM SEPARATOR</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    MENUITEM "E&amp;xit",IDM_EXIT</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</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>&nbsp;MENUITEM 
    "&amp;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>&nbsp; 
  <dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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.</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>&nbsp;</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>&nbsp; 
  <dl><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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</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>&nbsp;</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>&nbsp;&nbsp;&nbsp; 
    .ELSEIF uMsg==WM_COMMAND</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    mov eax,wParam</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .IF ax==IDM_TEST</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .ELSEIF ax==IDM_HELLO</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .ELSEIF ax==IDM_GOODBYE</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .ELSE</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke DestroyWindow,hWnd</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .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>&nbsp; 
  <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 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    ; handle of our menu</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b>&nbsp;</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>&nbsp;<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke LoadMenu, hInst, OFFSET MenuName</b></font></font></font> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    mov&nbsp;&nbsp;&nbsp; hMenu,eax</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\</font></font></font></b> 
    <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\</font></font></font></b> <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,\</font></font></font></b> 
    <br>
    <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    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 + -