📄 example9-1.htm
字号:
<html>
<head>
<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>例9-1</title>
</head>
<body>
<blockquote>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">//<font FACE="??ì?,SimSun" LANG="ZH-CN">头文件</font>windows.h<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">#include
<windows.h>
<font color="#008000">//<font FACE="??ì?,SimSun" LANG="ZH-CN">窗口函数说明</font></font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">LRESULT
CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">/*
<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">int
WINAPI WinMain
(
<font color="#008000">//WinMain<font FACE="??ì?,SimSun" LANG="ZH-CN">函数</font></font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">HINSTANCE
hInstance, </font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">HINSTANCE
hPrevInstance,</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">PSTR
szCmdLine,</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">int
iCmdShow)</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">static
char szAppName[] = "<font FACE="??ì?,SimSun" LANG="ZH-CN">示例</font>"
; <font color="#008000">//<font FACE="??ì?,SimSun" LANG="ZH-CN">窗口类名</font></font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">HWND
hwnd
;
<font color="#008000">//<font FACE="??ì?,SimSun" LANG="ZH-CN">窗口句柄</font></font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">MSG
msg
;
<font color="#008000">//Windows<font FACE="??ì?,SimSun" LANG="ZH-CN">消息</font></font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WNDCLASSEX
wndclass
;
<font color="#008000">//窗口类,可以是WNDCLASS</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.cbSize
= sizeof (wndclass) ; <font color="#008000">//窗口类数据大小</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 color="#008000">//窗口类型</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.lpfnWndProc
= WndProc ; <font color="#008000">//窗口处理函数为WndProc</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.cbClsExtra
= 0
;
<font color="#008000">//窗口类无扩展</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.cbWndExtra
= 0
;
<font color="#008000">//窗口实例无扩展</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hInstance
= hInstance ; <font color="#008000">
//当前实例句柄</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hIcon
= LoadIcon (NULL, IDI_APPLICATION) ;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">//窗口的最小化图标为默认图标</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hCursor
= LoadCursor (NULL, IDC_ARROW)
;
<font color="#008000">//窗口采用箭头光标</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 color="#008000">//窗口背景为白色</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.lpszMenuName
= NULL
;
<font color="#008000">//窗口无菜单</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.lpszClassName
= szAppName ; <font color="#008000">//窗口类名为“示例”</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">wndclass.hIconSm
= LoadIcon (NULL, IDI_APPLICATION) ;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">/*
以下是对窗口类的注册 */</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">if(!
RegisterClassEx (&wndclass))
<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">MessageBeep(0);</font></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -