CButton::Create

Creates the Windows button control and attaches it to the CButton object.

virtual BOOL Create( 
   LPCTSTR lpszCaption, 
   DWORD dwStyle, 
   const RECT& rect, 
   CWnd* pParentWnd, 
   UINT nID  
);

Parameters

  • lpszCaption
    Specifies the button control's text.

  • dwStyle
    Specifies the button control's style. Apply any combination of button styles to the button.

  • rect
    Specifies the button control's size and position. It can be either a CRect object or a RECT structure.

  • pParentWnd
    Specifies the button control's parent window, usually a CDialog. It must not be NULL.

  • nID
    Specifies the button control's ID.

Return Value

Nonzero if successful; otherwise 0.

Remarks

You construct a CButton object in two steps. First, call the constructor and then call Create, which creates the Windows button control and attaches it to the CButton object.

If the WS_VISIBLE style is given, Windows sends the button control all the messages required to activate and show the button.

Apply the following window styles to a button control:

  • WS_CHILD   Always

  • WS_VISIBLE   Usually

  • WS_DISABLED   Rarely

  • WS_GROUP   To group controls

  • WS_TABSTOP   To include the button in the tabbing order

Example

CButton myButton1, myButton2, myButton3, myButton4;

// Create a push button.
myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 
   CRect(10,10,100,30), pParentWnd, 1);

// Create a radio button.
myButton2.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, 
   CRect(10,40,100,70), pParentWnd, 2);

// Create an auto 3-state button.
myButton3.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTO3STATE, 
   CRect(10,70,100,100), pParentWnd, 3);

// Create an auto check box.
myButton4.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, 
   CRect(10,100,100,130), pParentWnd, 4);

Requirements

Header: afxwin.h

See Also

Reference

CButton Class

Hierarchy Chart

CButton::CButton