zxw
asked on
ActiveX control and CWnd
I know the steps to insert an ActiveX control to a dialog
base app,but how can i programly create an ActiveX control
in CWnd object?
base app,but how can i programly create an ActiveX control
in CWnd object?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks linyf. I've been using Create all this time and CreateControl is definitely more correct.
zxw, Create the control inside your CView::OnInitialUpdate.
Phillip
zxw, Create the control inside your CView::OnInitialUpdate.
Phillip
Ahhh.. The confusion is gone!
When you add the control to your project, the control will create a header file for you. The CreateControl function is called by the Create function. So we're both right!
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); }
// And how I do my create function!
m_pMyControl->Create( NULL, NULL, WS_VISIBLE, rcClient, pWnd, IDC_MY_CONTROL );
Phillip
When you add the control to your project, the control will create a header file for you. The CreateControl function is called by the Create function. So we're both right!
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); }
// And how I do my create function!
m_pMyControl->Create( NULL, NULL, WS_VISIBLE, rcClient, pWnd, IDC_MY_CONTROL );
Phillip
ASKER
I did as Mr. Phillip said, and complied with no error, but when i run the program there still is no
control on the CWnd object, why?
control on the CWnd object, why?
Gotta show the code!
ASKER
I have an ActiveX control named GVBox that shows gif files, i want to put it into the MFC Sample project provided by VC5.0 named saver(screen saver example), and following
the codes i added,
CGvbox* m_pGIFBox;
int CDrawWnd::OnCreate(LPCREAT ESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateSt ruct) == -1)
return -1;
int nSpeed = AfxGetApp()->GetProfileInt ("Config", "Speed", 1);
if (nSpeed < 0)
nSpeed = 0;
SetSpeed(nSpeed);
CRect r(10,10,100,100);
m_pGIFBox = new CGvbox;
ASSRT(m_pGIFBox->Create(_T (""),WS_CH ILD|WS_VIS IBLE,r,thi s,IDC_GVBO XCTRL1));
m_pGIFBox->Set_FileName(_T ("d:\\temp \\mail.gif "));
m_pGIFBox->SetEnabled(TRUE );
return 0;
}
the codes i added,
CGvbox* m_pGIFBox;
int CDrawWnd::OnCreate(LPCREAT
{
if (CWnd::OnCreate(lpCreateSt
return -1;
int nSpeed = AfxGetApp()->GetProfileInt
if (nSpeed < 0)
nSpeed = 0;
SetSpeed(nSpeed);
CRect r(10,10,100,100);
m_pGIFBox = new CGvbox;
ASSRT(m_pGIFBox->Create(_T
m_pGIFBox->Set_FileName(_T
m_pGIFBox->SetEnabled(TRUE
return 0;
}
Remeber my first comment, put it in OnInitialUpdate...
Why are you bothering with the pointer and the new?
Go ahead and make life easy on ya...
Add to your CDrawWnd header file:
CGVBox m_GIFBox;
and put in your OnInitialUpdate
m_GIFBox.Create( _T( "" ), WS_CHILD | WS_VISIBLE, CRect( 10, 10, 100, 100 ), this, IDC_GVBOXCTRL1 ));
MUCH cleaner and you won't have to worry about the deleting!
Phillip
Why are you bothering with the pointer and the new?
Go ahead and make life easy on ya...
Add to your CDrawWnd header file:
CGVBox m_GIFBox;
and put in your OnInitialUpdate
m_GIFBox.Create( _T( "" ), WS_CHILD | WS_VISIBLE, CRect( 10, 10, 100, 100 ), this, IDC_GVBOXCTRL1 ));
MUCH cleaner and you won't have to worry about the deleting!
Phillip
Remember, the ActiveX control is derived from CWnd and you can just create the control with CWnd::Create just like you would do it with an edit box or a button.
Phillip