Visual C++ / MFC 入门教程--Button

 

窗口(控件)在MFC中使用CButton表示,CButton包含了三种样式的按Push ButtonCheck BoxRadio Box。所以在利用CButton象生成按窗口需要指明按格。

建按BOOL CButton::Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );其中lpszCaption是按示的文字,dwStyle钮风格,除了Windows格可以使用外(如WS_CHILD|WS_VISUBLE|WS_BORDER有按钮专用的一些格。

BS_AUTOCHECKBOX 检查框,按的状会自 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.

BS_AUTORADIOBUTTON 选择,按的状会自 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.

 BS_AUTO3STATE 有三即:中,未中,未定 Same as a three-state check box, except that the box changes its state when the user selects it.

BS_CHECKBOX 检查 Creates a small square that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style).

BS_DEFPUSHBUTTON 普通 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).

BS_LEFTTEXT 对齐文字 When combined with a radio-button or check-box style, the text appears on the left side of the radio button or check box.

BS_OWNERDRAW Creates an owner-drawn button. The framework calls the DrawItem member function when a visual aspect of the button has changed. This style must be set when using the CBitmapButton class. 

BS_PUSHBUTTON 普通按 Creates a pushbutton that posts a WM_COMMAND message to the owner window when the user selects the button. 

BS_RADIOBUTTON 选择 Creates a small circle that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style). Radio buttons are usually used in groups of related but mutually exclusive choices. 

BS_3STATE 有三即:中,未中,未定 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.

rect窗口所占据的矩形区域,pParentWnd父窗口指nID为该窗口的ID

/检查形按可能有两中和未中,如果置了BS_3STATEBS_AUTO3STATE格就可能出第三:未定,这时钮显示灰色。通过调int CButton::GetCheck( ) 得到当前是否被中,返回0:未中,1中,2:未定。void CButton::SetCheck( int nCheck );置当前中状

理按消息:要理按消息需要在父窗口中行消息映射,映射宏ON_BN_CLICKED( id, memberFxn )idID,就是指定的nID理函数原型afx_msg void memberFxn( );

posted @ 2008-10-28 11:42  西风残照  阅读(1554)  评论(0)    收藏  举报