Dynamic handlers?
-
How does one go about to implement handlers for buttons that are created dynamically at runtime? E.g. I want to create a button which should run a program when pressed. The program to run is configured by the user. I was thinking of storing the program name within the button object. Then I could use one handler for all of the buttons, but how do I know which button it was that called the handler (in order to retrieve the program name)? Cheers,
/FredrikDo you Sonork? I do! 100.11430:PhatBoy
-
How does one go about to implement handlers for buttons that are created dynamically at runtime? E.g. I want to create a button which should run a program when pressed. The program to run is configured by the user. I was thinking of storing the program name within the button object. Then I could use one handler for all of the buttons, but how do I know which button it was that called the handler (in order to retrieve the program name)? Cheers,
/FredrikDo you Sonork? I do! 100.11430:PhatBoy
You can use ON_COMMAND_RANGE to handle a range of commands: class CMyDialog : public CDialog { afx_msg void OnHandleCommands(UINT nID); DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_COMMAND_RANGE(ID_COMMAND_FIRST, ID_COMMAND_LAST, OnHandleCommands) END_MESSAGE_MAP() void CMyDialog::OnHandleCommands(UINT nID) { // nID contains the ID of the command to handle }