📄 example9-1.htm
字号:
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return
FALSE;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</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 color="#008000">//窗口类名</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">示例</font>9_1",
<font color="#008000">//窗口标题名</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WS_OVERLAPPEDWINDOW,
<font color="#008000">//窗口的风格</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 color="#008000">//窗口左上角坐标为默认值</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CW_USEDEFAULT<font color="#008000">,</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CW_USEDEFAULT,
<font color="#008000">//窗口的高和宽为默认值</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL,
<font color="#008000">//此窗口无父窗口</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL,
<font color="#008000">//此窗口无主菜单</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">hInstance,
<font color="#008000">//创建此窗口的应用程序的当前句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL)
;
<font color="#008000">//此值不使用</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">ShowWindow
(hwnd, iCmdShow) ; <font color="#008000">//显示窗口</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">UpdateWindow
(hwnd)
;
<font color="#008000">//绘制用户区</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">while
(GetMessage (&msg, NULL, 0, 0)) <font color="#008000">//消息循环</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">TranslateMessage
(&msg) ; <font color="#008000"> //翻译消息</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">DispatchMessage
(&msg) ; <font color="#008000">
//将消息传递给处理函数</font></font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return
msg.wParam ;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<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">LRESULT
CALLBACK WndProc (</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">HWND
hwnd,
<font color="#008000">//窗口句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">UINT
iMsg,
<font color="#008000">//代表所处理消息的消息值</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WPARAM
wParam,
<font color="#008000"> //消息的附加参数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">LPARAM
lParam)
<font color="#008000">//消息的附加参数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">switch
(iMsg)</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">case
WM_DESTROY :</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">PostQuitMessage
(0) ; <font color="#008000">//调用函数PostQuitessage退出程序</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return
0 ;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return
DefWindowProc (hwnd, iMsg, wParam, lParam) ;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
</blockquote>
</blockquote>
<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><font FACE="??ì?,SimSun" LANG="ZH-CN">所示。</font></font></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><img SRC="Image6.gif" WIDTH="170" HEIGHT="110"></font></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">例</font>9-1<font FACE="??ì?,SimSun" LANG="ZH-CN">的运行结果</font></font></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -