How to create dynamic MFC controls and handle message maps of the controls at runtime?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It really depends on which controls do you want to create, especially if you want to know which flags should you set. In general it goes down to this:
Normally a CWnd-derived control is created using
CreateorCreateEx. For a CButton, for instance:where the
CRectspecifies the button position,thisis a pointer to the parent window, andnIDis the control ID.If the control doesn’t come out as expected, it’s probably because some flags are missing. I suggest you draw a sample control in design mode, check out the code for that control in the RC file, and copy the flags to the
Createcaller.As for the message maps, they are normally routed to the parent window. The
nIDvalue you used inCreateis important here, because it will be the number that identifies the control in the message map. If you have a fixed number of controls, you can hard-code thenIDnumbers for your controls (starting at 10000, for instance); if not, you’ll have to provide a way for the parent window to identify them. Then you just add the message map entries.You can use the
ON_CONTROL_RANGEmessage map to map a range of IDs to the same function.