wzou
asked on
create a button control at run time in VC 5
Hi, Expert
I've successfully create some button controls at run-time. However, I don't know how to add the message (ON_BUTTON_CLICK) mapping for these controls at the run-time. Normally, the message mapping is implemented by adding some code at message area like
BEGIN_MESSAGE_MAP(.....)
.....
END_MESSAGE_MAP()
However, since all these buttons are created at run time. It is no way to add in any definition in that area during the run time.
Please, give me some idea!
I've successfully create some button controls at run-time. However, I don't know how to add the message (ON_BUTTON_CLICK) mapping for these controls at the run-time. Normally, the message mapping is implemented by adding some code at message area like
BEGIN_MESSAGE_MAP(.....)
.....
END_MESSAGE_MAP()
However, since all these buttons are created at run time. It is no way to add in any definition in that area during the run time.
Please, give me some idea!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In this case define macro ON_CONTROL_EX_RANGE as follows
#define ON_CONTROL_EX_RANGE(wNotif yCode, id, idLast, memberFxn) \
{ WM_COMMAND, (WORD)wNotifyCode, (WORD)id, (WORD)idLast, AfxSig_bw, \
(AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(UINT))&memb erFxn },
to map range of button IDs to the single handler.
where memberFxn is defined as afx_msg BOOL memberFxn (UINT nID);
where nID is ID of the button sent notification message.
wNotifyCode is BN_CLICKED in your case
#define ON_CONTROL_EX_RANGE(wNotif
{ WM_COMMAND, (WORD)wNotifyCode, (WORD)id, (WORD)idLast, AfxSig_bw, \
(AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(UINT))&memb
to map range of button IDs to the single handler.
where memberFxn is defined as afx_msg BOOL memberFxn (UINT nID);
where nID is ID of the button sent notification message.
wNotifyCode is BN_CLICKED in your case
ASKER
Hi galkin,
It seems to be a good idea. I will test it.
Tanks for your help!
Wei Zou
It seems to be a good idea. I will test it.
Tanks for your help!
Wei Zou
ASKER
Thanks for the reply!
The problem run the program I don't know exactly how many Button Controls I will create. So, I have to assign the ID to the new Button Control at run time. That's why I can't put the message mapping in the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP at build time.