?? teach_road_4e.htm
字號(hào):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="聞怡洋 wyy_cq@21cn.com">
<title>Visual C++/MFC開發(fā)指南</title>
<SCRIPT LANGUAGE='JavaScript' SRC='../navigate_bar.js'></SCRIPT>
<link REL="stylesheet" HREF="../main.css">
</head>
<SCRIPT LANGUAGE='JavaScript'>write_body();</SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>write_bar();</SCRIPT>
<p align="center"><a
HREF="http://www.0828.com/pay/cgi-bin/random.cgi?job=go&id=820"
target="_blank">
<img SRC="http://www.0828.com/pay/cgi-bin/random.cgi?id=820" BORDER="0"
width="468" height="60"></a><br>
<font size="2"><a href="http://www.0828.com/pay/index.html"><img border="0"
src="http://www.0828.com/pay/code.gif" width="468" height="15"></a><br>
<small>你每點(diǎn)一下上面的廣告我就能有更多的上網(wǎng)時(shí)間為大家尋找資料</small></font>
</p>
<table width=98% cellspacing="0" cellpadding="0" align=center><!--整體框架-->
<tr><td>
<table border=0 width="100%" cellspacing="0" cellpadding="2"><!--標(biāo)記放置區(qū)域-->
<tr>
<td width="30%" align="center" bgcolor="#003D84" valign=middle><img src=../img/brand_200_60.gif width=200 height=60 alt="LOGO1"></td>
<td width="70%" align="center" bgcolor="#003D84" valign=middle><img src=../img/logo_400_60.gif width=400 height=60 alt="LOGO2"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#0080C0" align=center><font color=white>您當(dāng)前位置</font> <a href=../index.htm><font color=white>首頁</font></a> <a href=index.htm><font color=white>開發(fā)教程</font></a> <font color=white class=eng>4.E General Window</font><SCRIPT LANGUAGE='JavaScript'>write_command();</SCRIPT></font></td>
</tr>
</table><!--標(biāo)記放置區(qū)域 END-->
<table border=0 width=100% cellspacing="0" cellpadding="0">
<tr>
<td><!--begin-->
<br>
<p align=center><big><font class=eng>4.E General Window</font></big></p>
<table border=0 align=center width=100%>
<tr><td>
<small>
<p>從VC提供的MFC類派生圖中我們可以看出窗口的派生關(guān)系,<a href=4e_g1.gif target=_blank>派生圖</a>,所有的窗口類都是由CWnd派生。所有CWnd的成員函數(shù)在其派生類中都可以使用。本節(jié)介紹一些常用的功能給大家。
</p>
<p><b>改變窗口狀態(tài):</b><br>
BOOL EnableWindow( BOOL bEnable = TRUE );可以設(shè)置窗口的禁止/允許狀態(tài)。BOOL IsWindowEnabled( );可以查詢窗口的禁止/允許狀態(tài)。
<br>BOOL ModifyStyle( DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0 )/BOOL ModifyStyleEx( DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0 );可以修改窗口的風(fēng)格,而不需要調(diào)用SetWindowLong
<br>BOOL IsWindowVisible( ) 可以檢查窗口是否被顯示。
<br>BOOL ShowWindow( int nCmdShow );將改變窗口的顯示狀態(tài),nCmdShow可取如下值:
<ul >
<li>
<b>SW_HIDE</b> 隱藏窗口</li>
<li>
<b>SW_MINIMIZE SW_SHOWMAXIMIZED</b> 最小化窗口</li>
<li>
<b>SW_RESTORE</b> 恢復(fù)窗口</li>
<li>
<b>SW_SHOW</b> 顯示窗口</li>
<li>
<b>SW_SHOWMINIMIZED</b> 最大化窗口</li>
</ul>
</p>
<p><b>改變窗口位置:</b><br>
void MoveWindow( LPCRECT lpRect, BOOL bRepaint = TRUE );可以移動(dòng)窗口。<br>
void GetWindowRect( LPRECT lpRect ) ;可以得到窗口的矩形位置。<br>
BOOL IsIconic( ) ;可以檢測(cè)窗口是否已經(jīng)縮為圖標(biāo)。<br>
BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );可以改變窗口的Z次序,此外還可以移動(dòng)窗口位置。
</p>
<p><b>使窗口失效,印發(fā)重繪:</b><br>
void Invalidate( BOOL bErase = TRUE );使整個(gè)窗口失效,bErase將決定窗口是否產(chǎn)生重繪。<br>
void InvalidateRect( LPCRECT lpRect, BOOL bErase = TRUE )/void InvalidateRgn( CRgn* pRgn, BOOL bErase = TRUE );將使指定的矩形/多邊形區(qū)域失效。
</p>
<p><b>窗口查找:</b>
<br>static CWnd* PASCAL FindWindow( LPCTSTR lpszClassName, LPCTSTR lpszWindowName );可以以窗口的類名和窗口名查找窗口。任一參數(shù)設(shè)置為NULL表對(duì)該參數(shù)代表的數(shù)據(jù)進(jìn)行任意匹配。如FindWindow("MyWnd",NULL)表明查找類名為MyWnd的所有窗口。
<br>BOOL IsChild( const CWnd* pWnd ) 檢測(cè)窗口是否為子窗口。
<br>CWnd* GetParent( ) 得到父窗口指針。
<br>CWnd* GetDlgItem( int nID ) 通過子窗口ID得到窗口指針。
<br>int GetDlgCtrlID( ) 得到窗口ID值。
<br>static CWnd* PASCAL WindowFromPoint( POINT point );將從屏幕上某點(diǎn)坐標(biāo)得到包含該點(diǎn)的窗口指針。
<br>static CWnd* PASCAL FromHandle( HWND hWnd );通過HWND構(gòu)造一個(gè)CWnd*指針,但該指針在空閑時(shí)會(huì)被刪除,所以不能保存供以后使用。
</p>
<p><b>時(shí)鐘:</b><br>
UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );可以創(chuàng)建一個(gè)時(shí)鐘,如果lpfnTimer回調(diào)函數(shù)為NULL,窗口將會(huì)收到WM_TIMER消息,并可以在afx_msg void OnTimer( UINT nIDEvent );中安排處理代碼
<br>BOOL KillTimer( int nIDEvent );刪除一個(gè)指定時(shí)鐘。
</p>
<p><b>可以利用重載來添加消息處理的虛函數(shù):</b>
<br>afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );窗口被創(chuàng)建時(shí)被調(diào)用
<br>afx_msg void OnDestroy( );窗口被銷毀時(shí)被調(diào)用
<br>afx_msg void OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI );需要得到窗口尺寸時(shí)被調(diào)用
<br>afx_msg void OnSize( UINT nType, int cx, int cy );窗口改變大小后被調(diào)用
<br>afx_msg void OnMove( int x, int y );窗口被移動(dòng)后時(shí)被調(diào)用
<br>afx_msg void OnPaint( );窗口需要重繪時(shí)時(shí)被調(diào)用,你可以填如繪圖代碼,對(duì)于視圖類不需要重載OnPaint,所有繪圖代碼應(yīng)該在OnDraw中進(jìn)行
<br>afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );接收到字符輸入時(shí)被調(diào)用
<br>afx_msg void OnKeyDown/OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags );鍵盤上鍵被按下/放開時(shí)被調(diào)用
<br>afx_msg void OnLButtonDown/OnRButtonDown( UINT nFlags, CPoint point );鼠標(biāo)左/右鍵按下時(shí)被調(diào)用
<br>afx_msg void OnLButtonUp/OnRButtonUp( UINT nFlags, CPoint point );鼠標(biāo)左/右鍵放開時(shí)被調(diào)用
<br>afx_msg void OnLButtonDblClk/OnRButtonDblClk( UINT nFlags, CPoint point );鼠標(biāo)左/右鍵雙擊時(shí)被調(diào)用
<br>afx_msg void OnMouseMove( UINT nFlags, CPoint point );鼠標(biāo)在窗口上移動(dòng)時(shí)被調(diào)用
</p>
</small>
</td>
</tr>
<tr><td>
<small>
<p align=center><a href=index.htm#charpter4>返回</a></p>
</small>
</td></tr>
</table>
<p align=center><small>版權(quán)所有 聞怡洋 <a href=http://www.vchelp.net/>http://www.vchelp.net/</a></small></p>
</td><!--end-->
</tr>
</table>
</td></tr></table><!--整體框架 END-->
<SCRIPT LANGUAGE='JavaScript'>write_tail();</SCRIPT>
</body></html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -