From: ccwork on
Hi,
I try to insert ActiveX to my program as following:

class MyWnd:public CFrameWnd
{
public:
MyWnd()
{
CString strControlProgid;
strControlProgid="mscal.calendar.7";
m_Control.DestroyWindow();
RECT rc;
::GetClientRect(m_hWnd,&rc);
BOOL bStat=FALSE;
bStat=m_Control.CreateControl(strControlProgid, "", WS_VISIBLE,
rc,
this, 5000, NULL, FALSE, NULL);
if (bStat == FALSE)
{
::MessageBox (m_hWnd,"Error!!","Could not place
control",MB_OK);
}
}
private:
CWnd m_Control;
}
class MyApp:public CWinApp
{
MyWnd *wnd;
public:
BOOL InitInstance()
{
AfxEnableControlContainer();
wnd=new MyWnd();
}
}

The error prompt "Error!! Could not place control" always appear. Anyone
know what the problem?
From: Ajay Kalra on
Unless you are doing it somewhere else, you have not created the window
represented by MyWnd *wnd. You have created an object on the heap but not
yet called wnd->Create or CreateEx etc.

--
Ajay Kalra [MVP - VC++]
ajaykalra(a)yahoo.com


"ccwork" <ccwork(a)discussions.microsoft.com> wrote in message
news:7F11C3BC-5063-4246-8C82-DFB5788C07B7(a)microsoft.com...
> Hi,
> I try to insert ActiveX to my program as following:
>
> class MyWnd:public CFrameWnd
> {
> public:
> MyWnd()
> {
> CString strControlProgid;
> strControlProgid="mscal.calendar.7";
> m_Control.DestroyWindow();
> RECT rc;
> ::GetClientRect(m_hWnd,&rc);
> BOOL bStat=FALSE;
> bStat=m_Control.CreateControl(strControlProgid, "",
WS_VISIBLE,
> rc,
> this, 5000, NULL, FALSE, NULL);
> if (bStat == FALSE)
> {
> ::MessageBox (m_hWnd,"Error!!","Could not place
> control",MB_OK);
> }
> }
> private:
> CWnd m_Control;
> }
> class MyApp:public CWinApp
> {
> MyWnd *wnd;
> public:
> BOOL InitInstance()
> {
> AfxEnableControlContainer();
> wnd=new MyWnd();
> }
> }
>
> The error prompt "Error!! Could not place control" always appear. Anyone
> know what the problem?


From: ccwork on
"Ajay Kalra" wrote:

> Unless you are doing it somewhere else, you have not created the window
> represented by MyWnd *wnd. You have created an object on the heap but not
> yet called wnd->Create or CreateEx etc.

I did. In the InitInstance. Please read again.
class MyApp:public CWinApp
{
MyWnd *wnd;
public:
BOOL InitInstance()
{
AfxEnableControlContainer();
wnd=new MyWnd();
}
}

> --
> Ajay Kalra [MVP - VC++]
> ajaykalra(a)yahoo.com
>
>
> "ccwork" <ccwork(a)discussions.microsoft.com> wrote in message
> news:7F11C3BC-5063-4246-8C82-DFB5788C07B7(a)microsoft.com...
> > Hi,
> > I try to insert ActiveX to my program as following:
> >
> > class MyWnd:public CFrameWnd
> > {
> > public:
> > MyWnd()
> > {
> > CString strControlProgid;
> > strControlProgid="mscal.calendar.7";
> > m_Control.DestroyWindow();
> > RECT rc;
> > ::GetClientRect(m_hWnd,&rc);
> > BOOL bStat=FALSE;
> > bStat=m_Control.CreateControl(strControlProgid, "",
> WS_VISIBLE,
> > rc,
> > this, 5000, NULL, FALSE, NULL);
> > if (bStat == FALSE)
> > {
> > ::MessageBox (m_hWnd,"Error!!","Could not place
> > control",MB_OK);
> > }
> > }
> > private:
> > CWnd m_Control;
> > }
> > class MyApp:public CWinApp
> > {
> > MyWnd *wnd;
> > public:
> > BOOL InitInstance()
> > {
> > AfxEnableControlContainer();
> > wnd=new MyWnd();
> > }
> > }
> >
> > The error prompt "Error!! Could not place control" always appear. Anyone
> > know what the problem?
>
>
>
From: ccwork on
Sorry. Actually the code is:
class MyWnd:public CFrameWnd
{
public:
MyWnd()
{
Create(NULL,"MFC Tutorial Part 1 CoderSource Window");
CString strControlProgid;
strControlProgid="mscal.calendar.7";
m_Control.DestroyWindow();
RECT rc;
::GetClientRect(m_hWnd,&rc);
BOOL bStat=FALSE;
bStat=m_Control.CreateControl(strControlProgid, "",
WS_VISIBLE, rc,
this, 5000, NULL, FALSE, NULL);
if (bStat == FALSE)
{
::MessageBox (m_hWnd,"Error!!","Could not place
control",MB_OK);
}
}
private:
CWnd m_Control;
}

"ccwork" wrote:
> "Ajay Kalra" wrote:
>
> > Unless you are doing it somewhere else, you have not created the window
> > represented by MyWnd *wnd. You have created an object on the heap but not
> > yet called wnd->Create or CreateEx etc.
>
> I did. In the InitInstance. Please read again.
> class MyApp:public CWinApp
> {
> MyWnd *wnd;
> public:
> BOOL InitInstance()
> {
> AfxEnableControlContainer();
> wnd=new MyWnd();
> }
> }
>
> > --
> > Ajay Kalra [MVP - VC++]
> > ajaykalra(a)yahoo.com
> >
> >
> > "ccwork" <ccwork(a)discussions.microsoft.com> wrote in message
> > news:7F11C3BC-5063-4246-8C82-DFB5788C07B7(a)microsoft.com...
> > > Hi,
> > > I try to insert ActiveX to my program as following:
> > >
> > > class MyWnd:public CFrameWnd
> > > {
> > > public:
> > > MyWnd()
> > > {
> > > CString strControlProgid;
> > > strControlProgid="mscal.calendar.7";
> > > m_Control.DestroyWindow();
> > > RECT rc;
> > > ::GetClientRect(m_hWnd,&rc);
> > > BOOL bStat=FALSE;
> > > bStat=m_Control.CreateControl(strControlProgid, "",
> > WS_VISIBLE,
> > > rc,
> > > this, 5000, NULL, FALSE, NULL);
> > > if (bStat == FALSE)
> > > {
> > > ::MessageBox (m_hWnd,"Error!!","Could not place
> > > control",MB_OK);
> > > }
> > > }
> > > private:
> > > CWnd m_Control;
> > > }
> > > class MyApp:public CWinApp
> > > {
> > > MyWnd *wnd;
> > > public:
> > > BOOL InitInstance()
> > > {
> > > AfxEnableControlContainer();
> > > wnd=new MyWnd();
> > > }
> > > }
> > >
> > > The error prompt "Error!! Could not place control" always appear. Anyone
> > > know what the problem?
> >
> >
> >
From: Ajay Kalra on
You are creating the window object by calling new MyWnd, but the window has
not been created yet. You need to call MyWnd->Create somewhere. IOW,
MyWnd->m_hWnd is NULL at the time when you are creating the control.

--
Ajay Kalra [MVP - VC++]
ajaykalra(a)yahoo.com


"ccwork" <ccwork(a)discussions.microsoft.com> wrote in message
news:2E66B713-7683-422B-9B81-D7C538327EEB(a)microsoft.com...
> "Ajay Kalra" wrote:
>
> > Unless you are doing it somewhere else, you have not created the window
> > represented by MyWnd *wnd. You have created an object on the heap but
not
> > yet called wnd->Create or CreateEx etc.
>
> I did. In the InitInstance. Please read again.
> class MyApp:public CWinApp
> {
> MyWnd *wnd;
> public:
> BOOL InitInstance()
> {
> AfxEnableControlContainer();
> wnd=new MyWnd();
> }
> }
>
> > --
> > Ajay Kalra [MVP - VC++]
> > ajaykalra(a)yahoo.com
> >
> >
> > "ccwork" <ccwork(a)discussions.microsoft.com> wrote in message
> > news:7F11C3BC-5063-4246-8C82-DFB5788C07B7(a)microsoft.com...
> > > Hi,
> > > I try to insert ActiveX to my program as following:
> > >
> > > class MyWnd:public CFrameWnd
> > > {
> > > public:
> > > MyWnd()
> > > {
> > > CString strControlProgid;
> > > strControlProgid="mscal.calendar.7";
> > > m_Control.DestroyWindow();
> > > RECT rc;
> > > ::GetClientRect(m_hWnd,&rc);
> > > BOOL bStat=FALSE;
> > > bStat=m_Control.CreateControl(strControlProgid, "",
> > WS_VISIBLE,
> > > rc,
> > > this, 5000, NULL, FALSE, NULL);
> > > if (bStat == FALSE)
> > > {
> > > ::MessageBox (m_hWnd,"Error!!","Could not place
> > > control",MB_OK);
> > > }
> > > }
> > > private:
> > > CWnd m_Control;
> > > }
> > > class MyApp:public CWinApp
> > > {
> > > MyWnd *wnd;
> > > public:
> > > BOOL InitInstance()
> > > {
> > > AfxEnableControlContainer();
> > > wnd=new MyWnd();
> > > }
> > > }
> > >
> > > The error prompt "Error!! Could not place control" always appear.
Anyone
> > > know what the problem?
> >
> >
> >