Creating ActiveX control dynamically (on the fly)

I'm creating an ActiveX control - ComboBox. I must use an EditBox control inside it. The EditBox is a visual ActiveX control also.

How to create the EditBox ActiveX control object on the fly and draw it inside the ComboBox control?

I must create the EditBox ActiveX control in the OnDraw(CDC* pDC, ...) method of my ComboBox control.

Any similar example or article in MSDN would be cool. Thanks.
LVL 2
MindoAsked:
Who is Participating?
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.

MindoAuthor Commented:
Edited text of question.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

I am not sure of this. But take a look at it.
Insert the actveX control of edit box into the combo box's aciveX project. Include edit controls .h file into combo box's ctl.h file and have a object of the editX init. Then use that object to create that control on OnDraw of comboX.

Try it out.
0
MindoAuthor Commented:
Yes, i did it. The VC++ 6.0 added classes to my project. I try to create the ActiveX control object in the OnDraw() method like this:

m_NMEdit.Create(NULL, WS_VISIBLE, CRect(10, 10, 20, 20), this, 0);

Unfortunately, my program crashes exactly on the above line.

I declared the member of the control as follows:

CNMEdit m_NMEdit;

I wonder, why it crashes? Should i perform initialisation routines?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Vinayak KumbarSr Program ManagerCommented:
Hi,

I have not tried it. Try that one and let me know the results.
Thanks

VinExpert
0
MindoAuthor Commented:
The results are:

My program crashes at the Create(...) function call.

There's a problem with the Create(...) function call. Maybe i pass wrong parameters or maybe i should initialize control data the other way?

Did anybody have the same problems with the Create(...) function call?
0
Vinayak KumbarSr Program ManagerCommented:
Hi,
Ok, I tell u the procedure as I solved the crash.
In the ctrl.h I have other activeX 's pointer say
CEditX *edit;

In the constructor
edit = NULL;

Then in OnDraw()
CRect rect(10,10,50,50);
      edit = new CEditX;
      AfxEnableControlContainer();
      edit->Create(NULL, NULL, WS_VISIBLE, rect, this, 4545, NULL);
      edit->ShowWindow(SW_SHOW);

here AfxEnableControlContainer(); is the extra call that we have to make.

Try it out.
VinExpert
0

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
MindoAuthor Commented:
Cool, it works. Thanks man. I didn't find any good example in MSDN. Why is Microsoft so obscure about giving good examples and explanations?
0
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.