CStatic::Create

Creates the Windows static control and attaches it to the CStatic object.

virtual BOOL Create(
   LPCTSTR lpszText,
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID = 0xffff 
);

Parameters

  • lpszText
    Specifies the text to place in the control. If NULL, no text will be visible.

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

  • rect
    Specifies the position and size of the static control. It can be either a RECT structure or a CRect object.

  • pParentWnd
    Specifies the CStatic parent window, usually a CDialog object. It must not be NULL.

  • nID
    Specifies the static control's control ID.

Return Value

Nonzero if successful; otherwise 0.

Remarks

Construct a CStatic object in two steps. First, call the constructor CStatic, and then call Create, which creates the Windows static control and attaches it to the CStatic object.

Apply the following window styles to a static control:

  • WS_CHILD   Always

  • WS_VISIBLE   Usually

  • WS_DISABLED   Rarely

If you're going to display a bitmap, cursor, icon, or metafile in the static control, you'll need to apply one of the following static styles:

  • SS_BITMAP   Use this style for bitmaps.

  • SS_ICON   Use this style for cursors and icons.

  • SS_ENHMETAFILE   Use this style for enhanced metafiles.

For cursors, bitmaps, or icons, you may also want to use the following style:

  • SS_CENTERIMAGE   Use to center the image in the static control.

Example

CStatic myStatic;

// Create a child static control that centers its text horizontally.
myStatic.Create(_T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, 
   CRect(10,10,150,50), pParentWnd);   

Requirements

Header: afxwin.h

See Also

Reference

CStatic Class

Hierarchy Chart

CStatic::CStatic

Other Resources

CStatic Members