dynamically create controls and attaching listeners to them?
-
Hello, I don't know if this is super-easy to accomplish, I am pretty new to VC++/MFC.. I need to create a dialog which must contain a different number of CButton controls depending on certain state parameters of the application. So I need to dynamically create a number of those controls and attach a message handler for them ( they all share the same message handler code ). How do I attach this listener function to the controls once I've created them? (I destroy all buttons and create a bunch of new ones when the layout changes) thankful for any help.
-
Hello, I don't know if this is super-easy to accomplish, I am pretty new to VC++/MFC.. I need to create a dialog which must contain a different number of CButton controls depending on certain state parameters of the application. So I need to dynamically create a number of those controls and attach a message handler for them ( they all share the same message handler code ). How do I attach this listener function to the controls once I've created them? (I destroy all buttons and create a bunch of new ones when the layout changes) thankful for any help.
Why dont you enable/disable or show/hide the controls at runtime, it is also better by UI Design-Guidelines. -> Make a full dialog with all resources in the resource editor, assign control objects to all controls and work with mycontrol.EnableWindow( bActiveNow ):cool: Try this @ home. (B&B)
-
Why dont you enable/disable or show/hide the controls at runtime, it is also better by UI Design-Guidelines. -> Make a full dialog with all resources in the resource editor, assign control objects to all controls and work with mycontrol.EnableWindow( bActiveNow ):cool: Try this @ home. (B&B)
I've thought of that as well. But I really don't have a clue as of what the maximum number of controls is. I could of course create a ridiculously large amount of CButton objects to be on the safe side, and just hide/show those. But it sounds a bit unneccessary to me... And I'm still very much interested in attaching a message handler dynamically. Can I for example create a hook and install it for every new item? And in that hook listen for the BN_CLICKED event and if one is received obtain the text for the control and pass it further on? If so, how is a hook procedure attached?