📄 example11-1.htm
字号:
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">static
char szAppName[] = "<font LANG="ZH-CN">示例</font>"
; //<font LANG="ZH-CN">窗口类名</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">HWND
hwnd
;
//<font LANG="ZH-CN">窗口句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">MSG
msg
;
//Windows<font LANG="ZH-CN">消息</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WNDCLASSEX
wndclass
;
//<font LANG="ZH-CN">窗口类,可以是</font>WNDCLASS</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.cbSize
= sizeof (wndclass) ; //<font LANG="ZH-CN">窗口类数据大小</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.style
= CS_HREDRAW | CS_VREDRAW ; //<font LANG="ZH-CN">窗口类样式</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.lpfnWndProc
= WndProc ; //<font LANG="ZH-CN">窗口处理函数为</font>WndProc</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.cbClsExtra
= 0 ; //<font LANG="ZH-CN">窗口类无扩展</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.cbWndExtra
= 0 ; //<font LANG="ZH-CN">窗口实例无扩展</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hInstance
= hInstance ; //<font LANG="ZH-CN">当前实例句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#009933">wndclass.hIcon
= LoadIcon (hInstance, MAKEINTRESOURCE(MYICON2)) ;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#009933">//<font LANG="ZH-CN">窗口左上角的图标为</font>MYICON2</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hCursor
= LoadCursor (NULL, IDC_ARROW)
;
//<font LANG="ZH-CN">窗口采用箭头光标</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hbrBackground
= (HBRUSH) GetStockObject (WHITE_BRUSH) ; //<font LANG="ZH-CN">窗口背景为白色</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.lpszMenuName
= MAKEINTRESOURCE(IDR_MENU1)
; //<font LANG="ZH-CN">窗口无菜单</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.lpszClassName
= szAppName
;
//<font LANG="ZH-CN">窗口类名为“示例”</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#009933">//wndclass.hIconSm
= LoadIcon (NULL, MAKEINTRESOURCE(IDI_ICON1)) ;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#009933">wndclass.hIconSm
= LoadIcon (NULL, "icon1")
; //<font lang="ZH-CN"><b><u>程序</u></b></font><font LANG="ZH-CN">最小化的图标为</font>icon1.ico</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">/*
<font LANG="ZH-CN">以下是对窗口类的注册</font> */</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">if(!
RegisterClassEx (&wndclass)) //<font LANG="ZH-CN">如果注册失败则发出警告</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">MessageBeep(0);</font></p>
<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 (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 LANG="ZH-CN">示例</font>11_1",
//<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">NULL,
//<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">ShowWindow
(hwnd, iCmdShow) ; //<font LANG="ZH-CN">显示窗口</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">UpdateWindow
(hwnd) ; //<font LANG="ZH-CN">绘制用户区</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 LANG="ZH-CN">消息循环</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 LANG="ZH-CN">翻译消息</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">DispatchMessage
(&msg) ; //<font LANG="ZH-CN">将消息传递给处理函数</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>
<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"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font 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 (HWND hwnd //<font LANG="ZH-CN">窗口句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">UINT
iMsg, //<font LANG="ZH-CN">消息</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WPARAM
wParam, //<font LANG="ZH-CN">参数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">LPARAM
lParam) //<font LANG="ZH-CN">参数</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 LANG="ZH-CN">调用函数</font>PostQuitessage<font LANG="ZH-CN">退出程序</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>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -