📄 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 + -