Link to home
Start Free TrialLog in
Avatar of wzou
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!
ASKER CERTIFIED SOLUTION
Avatar of galkin
galkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wzou
wzou

ASKER

Hi, galkin;

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.
In this case define macro ON_CONTROL_EX_RANGE as follows

#define ON_CONTROL_EX_RANGE(wNotifyCode, id, idLast, memberFxn) \
      { WM_COMMAND, (WORD)wNotifyCode, (WORD)id, (WORD)idLast, AfxSig_bw, \
            (AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(UINT))&memberFxn },

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
Avatar of wzou

ASKER

Hi galkin,

It seems to be a good idea. I will test it.

Tanks for your help!


Wei Zou