?? teach_road_41.htm
字號:
<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開發指南</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>你每點一下上面的廣告我就能有更多的上網時間為大家尋找資料</small></font>
</p>
<table width=98% cellspacing="0" cellpadding="0" align=center><!--整體框架-->
<tr><td>
<table border=0 width="100%" cellspacing="0" cellpadding="2"><!--標記放置區域-->
<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>您當前位置 <a href=../index.htm><font color=white>首頁</font></a> <a href=index.htm><font color=white>開發教程</font></a> 4.1 Button<SCRIPT LANGUAGE='JavaScript'>write_command();</SCRIPT></font></td>
</tr>
</table><!--標記放置區域 END-->
<table border=0 width=100% cellspacing="0" cellpadding="0">
<tr>
<td><!--begin-->
<br>
<p align=center><big>4.1 Button</big></p>
<table border=0 align=center width=100%>
<tr><td>
<small>
<p>按鈕窗口(控件)在MFC中使用CButton表示,CButton包含了三種樣式的按鈕,Push Button,Check Box,Radio Box。所以在利用CButton對象生成按鈕窗口時需要指明按鈕的風格。</p>
<p>創建按鈕:BOOL CButton::Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );其中lpszCaption是按鈕上顯示的文字,dwStyle為按鈕風格,除了Windows風格可以使用外(如WS_CHILD|WS_VISUBLE|WS_BORDER)還有按鈕專用的一些風格。
<ul type=disc>
<li>
<b>BS_AUTOCHECKBOX</b> 檢查框,按鈕的狀態會自動改變 Same as a check box, except that a check mark appears in the check box when the user selects the box; the check mark disappears the next time the user selects the box.<br><br></li>
<li>
<b>BS_AUTORADIOBUTTON</b> 圓形選擇按鈕,按鈕的狀態會自動改變 Same as a radio button, except that when the user selects it, the button automatically highlights itself and removes the selection from any other radio buttons with the same style in the same group.<br><br></li>
<li>
<b>BS_AUTO3STATE</b> 允許按鈕有三種狀態即:選中,未選中,未定 Same as a three-state check box, except that the box changes its state when the user selects it.<br><br></li>
<li>
<b>BS_CHECKBOX</b> 檢查框 Creates a small square that has text displayed to its right (unless this style is combined with the <b>BS_LEFTTEXT</b> style).<br><br></li>
<li>
<b>BS_DEFPUSHBUTTON</b> 默認普通按鈕 Creates a button that has a heavy black border. The user can select this button by pressing the ENTER key. This style enables the user to quickly select the most likely option (the default option).<br><br></li>
<li>
<b>BS_LEFTTEXT</b> 左對齊文字 When combined with a radio-button or check-box style, the text appears on the left side of the radio button or check box.<br><br></li>
<li>
<b>BS_OWNERDRAW</b> 自繪按鈕 Creates an owner-drawn button. The framework calls the <b>DrawItem</b> member function when a visual aspect of the button has changed. This style must be set when using the <b>CBitmapButton</b> class.<br><br></li>
<li>
<b>BS_PUSHBUTTON</b> 普通按鈕 Creates a pushbutton that posts a <b>WM_COMMAND</b> message to the owner window when the user selects the button.<br><br></li>
<li>
<b>BS_RADIOBUTTON</b> 圓形選擇按鈕 Creates a small circle that has text displayed to its right (unless this style is combined with the <b>BS_LEFTTEXT</b> style). Radio buttons are usually used in groups of related but mutually exclusive choices.<br><br></li>
<li>
<b>BS_3STATE</b> 允許按鈕有三種狀態即:選中,未選中,未定 Same as a check box, except that the box can be dimmed as well as checked. The dimmed state typically is used to show that a check box has been disabled.</li>
</ul>
rect為窗口所占據的矩形區域,pParentWnd為父窗口指針,nID為該窗口的ID值。
</p>
<p>獲取/改變按鈕狀態:對于檢查按鈕和圓形按鈕可能有兩種狀態,選中和未選中,如果設置了BS_3STATE或BS_AUTO3STATE風格就可能出現第三種狀態:未定,這時按鈕顯示灰色。通過調用int CButton::GetCheck( ) 得到當前是否被選中,返回0:未選中,1:選中,2:未定。調用void CButton::SetCheck( int nCheck );設置當前選中狀態。</p>
<p>處理按鈕消息:要處理按鈕消息需要在<font color=red>父窗口</font>中進行消息映射,映射宏為ON_BN_CLICKED( id, memberFxn )id為按鈕的ID值,就是創建時指定的nID值。處理函數原型為afx_msg void memberFxn( );</p>
<p></p>
<p></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>版權所有 聞怡洋 <a href=http://www.vchelp.net/>http://www.vchelp.net/</a></small></p>
</td><!--end-->
</tr>
</table>
</td></tr></table><!--整體框架 END-->
<!-- 耐特付費廣告代碼開始 不得修改. -->
<center><script language="javascript">
<!--
var date = new Date();
var ra = date.getTime() % 1000;
var ua = document.URL;
document.write("<iframe src='http://www.china-free.com/cgi-bin/ad/random.cgi?id=560' width=468 height=60 scrolling=no marginwidth=0 marginheight=0 frameborder=0 vspace=0 hspace=0 >");
document.write("<a href='http://www.china-free.com/cgi-bin/ad/random.cgi?id=560' target='_blank'>");
document.write("<img src='http://www.china-free.com/cgi-bin/ad/random.cgi?job=go&id=560' width=468 height=60 border=0></a>");
document.write("</iframe>");
//-->
</script>
<noscript>
<a target="_blank" href="http://www.china-free.com/cgi-bin/ad/random.cgi?id=560">
<img src="http://www.china-free.com/cgi-bin/ad/random.cgi?job=go&id=560" width="468" height="60" border="0"></a>
</noscript>
<br><a HREF="http://www.china-free.com/ad" target="_blank"><img SRC="http://www.china-free.com/ad/bd.gif" BORDER="0" ></a><br>
<small>你每點一下上面的廣告我就能有更多的上網時間為大家尋找資料</small></center>
<!-- 耐特付費廣告代碼結尾. -->
<SCRIPT LANGUAGE='JavaScript'>write_tail();</SCRIPT>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -