CWnd::CreateControl

BOOL CWnd::CreateControl( LPCTSTR lpszClass**, LPCTSTR** lpszWindowName**, DWORD** dwStyle**, const RECT&** rect**, CWnd*** pParentWnd**, UINT** nID**, CFile*** pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );

BOOL CWnd::CreateControl( REFCLSID clsid**, LPCTSTR** lpszWindowName**, DWORD** dwStyle**, const RECT&** rect**, CWnd*** pParentWnd**, UINT** nID**, CFile*** pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );

Return Value

Nonzero if successful; otherwise 0.

Parameters

lpszClass

This string may contain the OLE "short name" (ProgID) for the class, e.g., "CIRC3.Circ3Ctrl.1". The name needs to match the same name registered by the control. Alternatively, the string may contain the string form of a CLSID, contained in braces, e.g., "{9DBAFCCF-592F-101B-85CE-00608CEC297B}". In either case, CreateControl converts the string to the corresponding class ID.

lpszWindowName

A pointer to the text to be displayed in the control. Sets the value of the control's Caption or Text property (if any). If NULL, the control's Caption or Text property is not changed.

dwStyle

Windows styles. The available styles are listed under Remarks.

rect

Specifies the control’s size and position. It can be either a CRect object or a RECT structure.

pParentWnd

Specifies the control’s parent window. It must not be NULL.

nID

Specifies the control’s ID.

pPersist

A pointer to a CFile containing the persistent state for the control. The default value is NULL, indicating that the control initializes itself without restoring its state from any persistent storage. If not NULL, it should be a pointer to a CFile-derived object which contains the control’s persistent data, in the form of either a stream or a storage. This data could have been saved in a previous activation of the client. The CFile can contain other data, but must have its read-write pointer set to the first byte of persistent data at the time of the call to CreateControl.

bStorage

Indicates whether the data in pPersist should be interpreted as IStorage or IStream data. If the data in pPersist is a storage, bStorage should be TRUE. If the data in pPersist is a stream, bStorage should be FALSE. The default value is FALSE.

bstrLicKey

Optional license key data. This data is needed only for creating controls that require a run-time license key. If the control supports licensing, you must provide a license key for the creation of the control to succeed. The default value is NULL.

clsid

The unique class ID of the control.

Remarks

Use this member function to create an ActiveX control that will be represented in the MFC program by a CWnd object. CreateControl is a direct analog of the CWnd::Create function, which creates the window for a CWnd. CreateControl creates an ActiveX control instead of an ordinary window.

Only a subset of the Windows dwStyle flags are supported for CreateControl:

  • WS_VISIBLE   Creates a window that is initially visible. Required if you want the control to be visible immediately, like ordinary windows.

  • WS_DISABLED   Creates a window that is initially disabled. A disabled window cannot receive input from the user. Can be set if the control has an Enabled property.

  • WS_BORDER   Creates a window with a thin-line border. Can be set if control has a BorderStyle property.

  • WS_GROUP   Specifies the first control of a group of controls. The user can change the keyboard focus from one control in the group to the next by using the direction keys. All controls defined with the WS_GROUP style after the first control belong to the same group. The next control with the WS_GROUP style ends the group and starts the next group.

  • WS_TABSTOP   Specifies a control that can receive the keyboard focus when the user presses the TAB key. Pressing the TAB key changes the keyboard focus to the next control of the WS_TABSTOP style.

Example

// This code is generated by the Control Wizard.
// It wraps the call to CreateControl in the call to Create.
class CGenocx : public CWnd
{
protected:
   DECLARE_DYNCREATE(CGenocx)
public:
   CLSID const& GetClsid()
   {
      static CLSID const clsid
         = { 0x8a6bbfeb, 0xf9bb, 0x11d1, { 0xb9, 0xc9, 0x0,
         0x60, 0x8, 0x93, 0xb0, 0xfe } };
      return clsid;
   }
   virtual BOOL Create(LPCTSTR lpszClassName,
      LPCTSTR lpszWindowName, DWORD dwStyle,
      const RECT& rect,
      CWnd* pParentWnd, UINT nID,
      CCreateContext* pContext = NULL)
   {
      return CreateControl(GetClsid(), lpszWindowName,
      dwStyle, rect, pParentWnd, nID);
   }
...
};

CWnd OverviewClass MembersHierarchy Chart

See Also   In Visual C++ Programmer’s Guide: