📄 right11-2.htm
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 11 章</title>
<base target="rbottom">
<style>
<!--
.右标题 { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容 { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin:
0 }
-->
</style>
</head>
<body>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">
<span style="background-color: #CCFF99">第 11 章</span><span style="background-color: #CCFF99">
</span>><span style="background-color: #CCFF99"> 第 2 节 </span>><span style="background-color: #CCFF99">
11.2 菜单</span></p>
<hr color="#008000" size="1">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1.
</font> <font FACE="??ì?,SimSun" LANG="ZH-CN"><font size="2">菜单的创建</font></p>
</font><font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font FACE="??ì?,SimSun" LANG="ZH-CN" size="2">在资源文件中创建菜单可分为定义和加载两个步骤:
</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">(1)<font face="oúì?,SimHei" lang="ZH-CN">
</font><font FACE="??ì?,SimSun" LANG="ZH-CN">菜单在资源描述文件中的定义形式为:
</font></font></p>
<blockquote>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font color="#008000" size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">
菜单名</font><font face="??ì?,SimSun" lang="ZH-CN"> </font>MENU [<font FACE="??ì?,SimSun" LANG="ZH-CN">选项</font>]</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font color="#008000" size="2">{</font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font FACE="??ì?,SimSun" LANG="ZH-CN" size="2" color="#008000">菜单项列表
</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font color="#008000" size="2">}</font></p>
</blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="oúì?,SimHei" LANG="ZH-CN">(2)
</font><font FACE="??ì?,SimSun" LANG="ZH-CN">
在Windows应用程序中加载菜单的方法有如下三种:</font></font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font face="oúì?,SimHei" lang="ZH-CN"><span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">①</span></font>
<font FACE="??ì?,SimSun" LANG="ZH-CN">在窗口类中加载菜单
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font color="#008000" size="2">wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1) ;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">②</span>
<font FACE="??ì?,SimSun" LANG="ZH-CN">在创建窗口时加载菜单
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">应用程序需首先调用函数LoadMenu加载菜单,然后调用函数CreateWindow创建窗口时加载窗口菜单。
</font><span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> </span></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font size="2">HMENU hMenu;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">hwnd = CreateWindow
(</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">szAppName, //<font LANG="ZH-CN">窗口类名
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">"<font FACE="??ì?,SimSun" LANG="ZH-CN" SIZE="1">菜单示例</font>",
//<font LANG="ZH-CN">窗口标题名
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WS_OVERLAPPEDWINDOW, //<font LANG="ZH-CN">窗口的风格
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CW_USEDEFAULT,</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CW_USEDEFAULT, //<font LANG="ZH-CN">窗口左上较坐标为默认值
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CW_USEDEFAULT,</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CW_USEDEFAULT, //<font LANG="ZH-CN">窗口的高和宽为默认值
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL, //<font LANG="ZH-CN">此窗口无父窗口</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">hMenu, //<font LANG="ZH-CN">此窗口的菜单
</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">hInstance, //<font LANG="ZH-CN">应用程序的当前句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL) ; //<font LANG="ZH-CN">此值不使用</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> </span></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">③</span>
<font FACE="??ì?,SimSun" LANG="ZH-CN">动态加载菜单
</font></font></p>
<p ALIGN="left" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">应用程序调用函数
</font>LoadMenu <font LANG="ZH-CN" size="2">获取菜单句柄后,还可通过调用函数</font><font lang="ZH-CN">
</font><font color="#008000">SetMenu</font><font color="#FF9933"> </font><font LANG="ZH-CN">动态地加载菜单,以提高应用程序的灵活性。
</font></font></p>
<font SIZE="3">
<p ALIGN="left" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">动态加载菜单可在同一个应用程序中实现多种不同的菜单操作界面。</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2. <font FACE="??ì?,SimSun" LANG="ZH-CN">菜单的动态创建</font></font><font FACE="??ì?,SimSun" LANG="ZH-CN"><font size="2">和显示</font></p>
</font><font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">动态创建菜单可以使系统资源更加节省,在应用程序中动态创建菜单首先调用函数</font>CreateMenu(
)<font FACE="??ì?,SimSun" LANG="ZH-CN">创建一个空的菜单,然后添加相应的菜单项,在程序运行中也可以添加或删除菜单项或设置菜单的状态。</font></font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" size="2">
(1) 创建菜单
</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font color="#008000" size="2">HMENU CreateMenu(VOID)</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" size="2">
(2) 在菜单的尾部增加菜单项</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font color="#008000" size="2">BOOL AppendMenu(hMenu hMenu, UINT uFlags, UINT uIDNewltem,
LPCTSTR lpNewltem);</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" size="2">
(3) 在菜单中插入菜单项
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -