Click to See Complete Forum and Search --> : receive events from dynamically created controls
htang
April 27th, 1999, 11:23 AM
my cformview-based application has dynamically created controls, depending on the user's settings. so, it could have 4 edit boxes for one user and 2 combo boxes for another. how can i receive events from these controls ? i can't use the classwizard. creating all the controls and hiding the appropriate ones is not an option, either.
thanks
Paul McKenzie
April 27th, 1999, 11:58 AM
Try SubclassDlgItem().
Regards,
Paul McKenzie
htang
April 27th, 1999, 02:13 PM
how about if some of these controls are activex controls ? must i use a dialog template for SubclassDlgItem to work ?
thanks again
Andy St.Clair
April 27th, 1999, 03:13 PM
Hi,
Here is one way of doing it.
If I want to create controls on a dialog box at runtime but want the convinience of MFC message mapping - I do the following:
1. Edit resource.h file and add the ID of the control as it will be at runtime.
2. Create a the control on the dialogbox resource and give it the ID we defined in step 1 above.
This way MFC Class wizard will see it at design time and we can map messages as normal.
3. Once we have mapped all the messages we want
then we remove the control from the dialogbox template.
The #define for the control ID should stay in the resource.h file (at least in VC++ version 6).
When we create the control at runtime - no problem.
You must remember to include resource.h in the appropriate cpp file.
This basic principle can be extended to menu items for runtime dynamic menus, etc..
If you want to create the control on for example the mainFrame window. Create a dialogbox in the resource (we will not display this box at all at runtime). Go throught the procedure outlined above. Instead of giving this dialogbox its own class- tell class wizard we want to associate it
with an existing class - for example the mainframe window class.
We can then get class wizard to map the message for the various controls to the mainframe.
When all is done we simply delete the dialogbox from the resource.
This is the way I do all my dynamic creation stuff.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.