CWnd::CreateControl
Use this member function to create an ActiveX control that will be represented in the MFC program by a CWnd object.
BOOL CreateControl(
LPCTSTR pszClass,
LPCTSTR pszWindowName,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID,
CFile* pPersist = NULL,
BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL
);
BOOL CreateControl(
REFCLSID clsid,
LPCTSTR pszWindowName,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID,
CFile* pPersist = NULL,
BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL
);
BOOL CreateControl(
REFCLSID clsid,
LPCTSTR pszWindowName,
DWORD dwStyle,
const POINT* ppt,
const SIZE* psize,
CWnd* pParentWnd,
UINT nID,
CFile* pPersist = NULL,
BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL
);
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.
class CGenocx : public CWnd { protected: DECLARE_DYNCREATE(CGenocx) public: CLSID const& GetClsid() { static CLSID const clsid = { 0x20DD1B9E, 0x87C4, 0x11D1, { 0x8B, 0xE3, 0x0, 0x0, 0xF8, 0x75, 0x4D, 0xA1 } }; return clsid; } // This code is generated by the Control Wizard. // It wraps the call to CreateControl in the call to Create. virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL) { UNREFERENCED_PARAMETER(pContext); UNREFERENCED_PARAMETER(lpszClassName); return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); } // remainder of class declaration omitted...