Make a ActiveX from a CWnd class

I made a CWnd class tha it work in a Custom Control. Now i want to made an ActiveX with that class.

Do I have to rewrite most of the code????

There is a way to create that CWnd class inside the COleControl class and capture all message like OnLButtonDown.

Please do a example.


PD: Sorry for my english. :)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roshan DavisCommented:
>> Now i want to made an ActiveX with that class
You mean, u already created an ActiveX and want to load thru CWnd?
Rosh :)
DAEAuthor Commented:
No, I not create the activex because I'm looking for an easy way to create that CWnd class in to a activex.

Like subclassing or something like that.

But maybe load thru CWnd it what i want, what is load thru CWnd?

Roshan DavisCommented:
1). File Menu->New
2). Select MFC ActiveXControl Wizard
3). Select the Path for the Project and Enter a Name
4). Click "OK"
5). Press Next
6). Press Finish

Now you will get a new ActiveX Project, you can place the code that in the CWnd in the main class (a class

with Ctl siffix eg: CYourAxCtl.cpp,CYourAxCtl.h)

Is that what u need?

This link also give some idea about creating an ActiveX - Creating an ActiveX button from a MFC owner-draw


Try these links also, this will give some ActiveX tutorials  by Kapil Chaturvedi. by Navin Kohli.

Good Luck
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

DAEAuthor Commented:
No, is not what i need.

For example. I made a CWnd derived class called DumClass.

Wend i start a new activex proyect, I have to create that class in the constructor like:

DumClass Test = new DumClass();

And then in the OnDraw event put some thing like this:

void CActiveXControlCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
       Test->Draw(pdc, rcBounds)

But my question is, there is other way to do this more easy. For example put some thing in the event PreCreateWindows?????????????????

Thanks roshmon for you dedication.
Roshan DavisCommented:
1). Do *NOTHING* in the function "OnDraw"
2). Comment all  the code that already created by the wizard like pDC->Ellipse() something like that
3). If your class is derived from CWnd, you need to create that window using "Create()" function
Put that create function code in your ActiveX control's OnCreate something like
make DumClass object as the class member of CUserManagerCtrl
in "UserManagerCtl.h", declare
DumClass m_oDumClass;

int CActiveXControlCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
      if (COleControl::OnCreate(lpCreateStruct) == -1)
            return -1;

      m_oDumClass.Create(NULL, "", WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, 1234);

      return 0;

And in your OnSize function (that you have to map WM_SIZE using class wizard(Ctrl+W))

void CActiveXControlCtrl::OnSize(UINT nType, int cx, int cy)
      COleControl::OnSize(nType, cx, cy);

      if( ::IsWindow(m_oDumClass.m_hWnd) )
            m_oDumClass.MoveWindow(0, 0, cx, cy);      

Good Luck

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DAEAuthor Commented:
Yes, thats what i want. But it doesn´t works.

m_oDumClass don't draw, and
if( ::IsWindow(m_oDumClass.m_hWnd)) is FALSE.

In the original proyect than i want to pass to activex. I put a Custom Control in a CDialog, and then put :

void CTestDlg::DoDataExchange(CDataExchange* pDX)
      DDX_Control(pDX, IDC_CUSTOMCONTROL, m_oDumClass);

And it work excellent.

I'm burning my brain here.

roshmon we are in the right path.

Roshan DavisCommented:
What that "Create" function returns..?
- m_oDumClass.Create(NULL, "", WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, 1234);

Rosh :)

Roshan DavisCommented:
In your class "DumClass", is there any "Create" function ?
If yes, use that function instead of the above
DAEAuthor Commented:
The function "Create" returns 1.
DAEAuthor Commented:
There is no overload create function in the class.
Roshan DavisCommented:
>> m_oDumClass don't draw, and
>> if( ::IsWindow(m_oDumClass.m_hWnd)) is FALSE.

Check the same condition just after the "Create" function

Rosh :)
DAEAuthor Commented:
Thank Rosh. It work excellent.

Stay in touch. My ICQ number is: 40317575
Roshan DavisCommented:
Thankx and Good Luck
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.