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

📄 tut8.html

📁 win32汇编教程 希望各位多多支持
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="Iczelion">
   <meta name="GENERATOR" content="Mozilla/4.51 [en] (Win95; I) [Netscape]">
   <title>Iczelion's Win32 Assembly Tutorial 8: Menu</title>
</head>
<body text="#FFFFFF" bgcolor="#000000" link="#FFFF00" vlink="#C0C0C0" alink="#C0FFC0">

<center>
<h1>
<font face="Arial,Helvetica"><font color="#999900">Tutorial 8: Menu</font></font></h1></center>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In this
tutorial, we will learn how to incorporate a menu into our window.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Download
the <a href="files/tut08-1.zip">example 1</a> and <a href="files/tut08-2.zip">example
2.</a></font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=+0>Theory:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Menu is
one of the most important component in your window. Menu presents a list
of services a program offers to the user. The user doesn't have to read
the manual included with the program to be able to use it, he can peruse
the menu to get an overview of the capability of a particular program and
start playing with it immediately. Since a menu is a tool to get the user
up and running quickly, you should follow the standard. Succintly put,
the first two menu items should be
File and Edit and the last should be
Help. You can insert your own menu items between Edit and Help. If a menu
item invokes a dialog box, you should append an ellipsis (...) to the menu
string.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Menu
is a kind of resource. There are several kinds of resources such as dialog
box, string table, icon, bitmap, menu etc. Resources are described in a
separated file called a resource file which normally has .rc extension.
You then combine the resources with the source code during the link stage.
The final product is an executable file which contains both instructions
and resources.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You
can write resource scripts using any text editor. They're composed of phrases
which describe the appearances and other attributes of the resources used
in a particular program Although you can write resource scripts with a
text editor, it's rather cumbersome. A better alternative is to use a resource
editor which lets you visually design resources with ease. Resource editors
are usually included in compiler packages such as Visual C++, Borland C++,
etc.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You
describe a menu resource like this:</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>&nbsp;
<ul><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MyMenu&nbsp;
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;&nbsp;
[menu list here]</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>}</font></font></font></b></ul>
<font face="Arial,Helvetica"><font size=-1><font color="#CCCCCC">C programmers
may recognize that it is similar to declaring a structure. </font><b><font color="#999900">MyMenu</font></b><font color="#CCCCCC">
being a menu name followed by <b>MENU</b> keyword and menu list within
curly brackets. Alternatively, you can use BEGIN and END instead of the
curly brackets if you wish. This syntax is more palatable to Pascal programmers.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Menu
list can be either <b>MENUITEM</b> or <b>POPUP</b> statement.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>MENUITEM</b>
statement defines a menu bar which doesn't invoke a popup menu when selected.The
syntax is as follows:</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MENUITEM
"&amp;text", ID [,options]</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>It begins
by MENUITEM keyword followed by the text you want to use as menu bar string.
Note the ampersand. It causes the character that follows it to be underlined.
Following the text string is the ID of the menu item. The ID is a number
that will be used to identify the menu item in the message sent to the
window procedure when the menu item is selected. As such, each menu ID
must be unique among themselves.</font></font></font>
<br>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Options are optional. 
Available options are as follows:</font></font></font> 
<dl> 
  <ul>
    <li> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>GRAYED</b>&nbsp; 
      The menu item is inactive, and it does not generate a WM_COMMAND message. 
      The text is grayed.</font></font></font></li>
    <li> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>INACTIVE</b> 
      The menu item is inactive, and it does not generate a WM_COMMAND message. 
      The text is displayed normally.</font></font></font></li>
    <li> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>MENUBREAK</b>&nbsp; 
      This item and the following items appear on a new line of the menu.</font></font></font></li>
    <li> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>HELP</b>&nbsp; 
      This item and the following items are right-justified.</font></font></font></li>
  </ul>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You can use 
  one of the above option or combine them with "or" operator. Beware that <b>INACTIVE</b> 
  and <b>GRAYED</b> cannot be combined together.</font></font></font> <br>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>POPUP </b>statement 
  has the following syntax:</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>POPUP 
    "&amp;text" [,options]</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; 
    [menu list]</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>POPUP statement 
  defines a menu bar that, when selected, drops down a list of menu items in a 
  small popup window. The menu list can be a <b>MENUTIEM</b> or <b>POPUP</b> statement. 
  There's a special kind of <b>MENUITEM</b> statement, <b>MENUITEM SEPARATOR</b>, 
  which will draw a horizontal line in the popup window.</font></font></font> 
  <br>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The next step 
  after you are finished with the menu resource script is to reference it in your 
  program.</font></font></font> <br>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You can do 
  this in two different places in your program.</font></font></font> 
  <ul>
    <li> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In lpszMenuName 
      member of WNDCLASSEX structure. Say, if you have a menu named "FirstMenu", 
      you can assigned the menu to your window like this:</font></font></font></li>
    <ul>
      <ul>
        <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.DATA</font></font></font></b> 
        <ul>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MenuName&nbsp; 
          db "FirstMenu",0</font></font></font></b> 
        </ul>
        <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>...........................</font></font></font></b> 
        <br>
        <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.CODE</font></font></font></b> 
        <ul>
          <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>mov&nbsp;&nbsp; 
          wc.lpszMenuName, OFFSET MenuName</font></font></font></b> <br>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>...........................</font></font></font></b> 
        </ul>
      </ul>
    </ul>
    <li> <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In menu 
      handle parameter of CreateWindowEx like this:</font></font></font></li>
    <ul>
      <ul>
        <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.DATA</font></font></font></b> 
        <ul>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MenuName&nbsp; 
          db "FirstMenu",0</font></font></font></b> <br>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hMenu 
          HMENU ?</font></font></font></b> 
        </ul>
        <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>...........................</font></font></font></b> 
        <br>
        <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.CODE</font></font></font></b> 
        <ul>
          <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>invoke 
          LoadMenu, hInst, OFFSET MenuName</font></font></font></b> <br>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>mov&nbsp;&nbsp; 
          hMenu, eax</font></font></font></b> <br>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>invoke 
          CreateWindowEx,NULL,OFFSET ClsName,\</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; 
          OFFSET Caption, WS_OVERLAPPEDWINDOW,\</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; 
          CW_USEDEFAULT,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;&nbsp; 
          CW_USEDEFAULT,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;&nbsp; 
          NULL,\</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; 
          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;&nbsp; 
          hInst,\</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; 
          NULL\</font></font></font></b> <br>
          <b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>...........................</font></font></font></b> 
        </ul>
      </ul>
    </ul>
  </ul>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>So you may 
  ask, what's the difference between these two methods?</font></font></font> <br>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>When you reference 
  the menu in the WNDCLASSEX structure, the menu becomes the "default" menu for 
  the window class. Every window of that class will have the same menu.</font></font></font> 
  <br>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>If you want 
  each window created from the same class to have different menus, you must choose 
  the second form. In this case, any window that is passed a menu handle in its 
  CreateWindowEx function will have a menu that "overrides" the default menu defined 
  in the WNDCLASSEX structure.</font></font></font> <br>
  <font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Next we will 
  examine how a menu notifies the window procedure when the user selects a menu 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -