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

📄 example9-1.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
📖 第 1 页 / 共 2 页
字号:
        <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,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//窗口类名</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">&quot;<font FACE="??ì?,SimSun" LANG="ZH-CN">示例</font>9_1&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//窗口标题名</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WS_OVERLAPPEDWINDOW,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <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,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <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,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//窗口的高和宽为默认值</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//此窗口无父窗口</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//此窗口无主菜单</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">hInstance,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//创建此窗口的应用程序的当前句柄</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">NULL) 
      ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <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) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">//显示窗口</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">UpdateWindow 
      (hwnd) 
      ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <font color="#008000">//绘制用户区</font></font></p>
      <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">while 
      (GetMessage (&amp;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 
        (&amp;msg) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000"> //翻译消息</font></font></p>
        <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">DispatchMessage 
        (&amp;msg) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <font color="#008000">//窗口句柄</font></font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">UINT 
    iMsg,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <font color="#008000">//代表所处理消息的消息值</font></font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">WPARAM 
    wParam,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <font color="#008000"> //消息的附加参数</font></font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">LPARAM 
    lParam)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <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) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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 + -