?? right9-1.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>第 9 章</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">第 9 章</span><span style="background-color: #CCFF99">
</span>><span style="background-color: #CCFF99"> 第 1 節 </span>><span style="background-color: #CCFF99">
9.1 </span><span style="background-color: #CCFF99">Windows
程序設計基本概念</span></p>
<hr color="#008000" size="1">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1.
Visual C++<font FACE="??ì?,SimSun" LANG="ZH-CN">應用程序設計方法</font></font></p>
<p style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">(1)使用</font>Windows<font LANG="ZH-CN">提供的</font>Windows
API<font LANG="ZH-CN">函數</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Windows
API<font LANG="ZH-CN">是</font>Windows<font LANG="ZH-CN">系統和</font>Windows<font LANG="ZH-CN">應用程序間的標準程序接口,應用程序可以通過此接口訪問系統</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font lang="ZH-CN" size="2">(2)</font><font size="2"><font LANG="ZH-CN">使用</font>Microsoft<font LANG="ZH-CN">提供的</font>MFC<font LANG="ZH-CN">類庫</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">MFC<font LANG="ZH-CN">類庫集成了大量已經預先定義好的類,用戶可以根據編程的需要調用相應的類,或根據需要自定義有關的類。</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2.
Windows<font FACE="??ì?,SimSun" LANG="ZH-CN">程序設計基本概念</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font size="2">(<font LANG="ZH-CN">1)
窗口</font></font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">窗口是應用程序與用戶之間交互的接口環境。用戶可以通過窗口輸入數據,控制應用程序的運行;應用程序可以通過窗口顯示數據和狀態。</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)
對象與句柄</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">對象是指</font>Windows<font LANG="ZH-CN">的規范部件,包括各種窗口、菜單、按鈕、對話框以及程序模塊等。</font></font></p>
<font SIZE="3">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">句柄是指</font>Windows<font LANG="ZH-CN">使用的一個唯一的整數值,是一個</font>4<font LANG="ZH-CN">字節長的數值,用于標識應用程序中不同的對象和同類對象中不同的實例,諸如一個窗口、按鈕、圖標、滾動條、輸出設備、控件或者文件等。應用程序通過句柄能夠訪問相應的對象信息。<a href="table9-1.htm" target="_blank">表</a></font><a href="table9-1.htm" target="_self">9-1</a><font LANG="ZH-CN">列出常用的句柄。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(3)
事件驅動</font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Windows<font FACE="??ì?,SimSun" LANG="ZH-CN">應用程序以消息為基礎,以事件驅動之。</font>Windows<font LANG="ZH-CN">應用程序啟動之后將進入一個消息循環,等待系統或應用程序的消息,消息的產生是因為事件發生的結果,</font>Windows<font LANG="ZH-CN">程序設計主要圍繞編寫事件或消息的響應函數上。有關事件驅動的問題在下節中將有詳細的討論。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font LANG="ZH-CN" size="2">(4)
消息及其在Windows編程中的應用</font></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Windows<font FACE="??ì?,SimSun" LANG="ZH-CN">應用程序的運行是依靠事件來驅動,</font>Windows<font LANG="ZH-CN">應用程序不斷等待(利用一個</font>while<font LANG="ZH-CN">循環),如果有事件發生,操作系統會以消息的形式傳遞給應用程序,應用程序會捕獲相應的消息,然后響應消息(調用相應的函數)。</font></font></p>
<p style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">系統傳遞給應用程序的消息數據是一個</font>MSG<font LANG="ZH-CN">結構體數據類型的數據。結構體</font>MSG<font LANG="ZH-CN">的定義如下:</font></font></p>
<blockquote>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">typedef
struct tagMSG // <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">{ </font></p>
<blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">HWND
hwnd;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">UINT
message;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">WPARAM
wParam;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">LPARAM
lParam;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">DWORD
time;</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">POINT
pt;</font></p>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">}
MSG;</font></p>
</blockquote>
</blockquote>
<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <span style="position: absolute; left: 37; top: 727"><a href="right8-5.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>
<span style="position: absolute; left: 483; top: 729"><a href="right9-2.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -