Event Handler Never Called??
-
-
Hi, I have dialog based application. If my event handler is in any class other than the main dialog class it never gets called. I would like to move the event handler to my subclass of a control. Suggestions? What am I doing wrong? Thanks Hua-Ying
some example code so that we can see what happen? I'm not a wizard :) Jaime
-
Hi, I have dialog based application. If my event handler is in any class other than the main dialog class it never gets called. I would like to move the event handler to my subclass of a control. Suggestions? What am I doing wrong? Thanks Hua-Ying
What class did you derive from? What event are you wanting to handle?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
some example code so that we can see what happen? I'm not a wizard :) Jaime
Example code probably won't help but I can walk through the steps to reproduce the problem. I'm using Visual Studio 2003 .Net - Create new MFC Application, select application type Dialog based. - In the class view, using the wizard create a new class with a base class of CButton, I called mine MyButton. - in the main dialog create a new button, right click and "Add Event Handler" choose the Message type: BN_CLICKED and the class as MyButton. - in the handler OnBnClickedButton1 add MessageBox("hello"); - run application - click button, nothing happens however if you added the Event Handler to the main dialog class created by the wizard, then everything works fine. :confused: Ideas? Thanks Hua-Ying
-
What class did you derive from? What event are you wanting to handle?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Example code probably won't help but I can walk through the steps to reproduce the problem. I'm using Visual Studio 2003 .Net - Create new MFC Application, select application type Dialog based. - In the class view, using the wizard create a new class with a base class of CButton, I called mine MyButton. - in the main dialog create a new button, right click and "Add Event Handler" choose the Message type: BN_CLICKED and the class as MyButton. - in the handler OnBnClickedButton1 add MessageBox("hello"); - run application - click button, nothing happens however if you added the Event Handler to the main dialog class created by the wizard, then everything works fine. :confused: Ideas? Thanks Hua-Ying
did you put a break point in your handler ? me think it's the MessageBox that simply doesn't show.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Example code probably won't help but I can walk through the steps to reproduce the problem. I'm using Visual Studio 2003 .Net - Create new MFC Application, select application type Dialog based. - In the class view, using the wizard create a new class with a base class of CButton, I called mine MyButton. - in the main dialog create a new button, right click and "Add Event Handler" choose the Message type: BN_CLICKED and the class as MyButton. - in the handler OnBnClickedButton1 add MessageBox("hello"); - run application - click button, nothing happens however if you added the Event Handler to the main dialog class created by the wizard, then everything works fine. :confused: Ideas? Thanks Hua-Ying
Hmm. I'd say the button press must be notified to the parent of the button, in this case the dialog. Notice that the event is called "BN_CLICKED". the "N" in "BN_" usually means "notification", in which case, the button's parent is notified. HTH Bikram Singh I believe we should all pay our tax with a smile. I tried - but they wanted cash.
-
Example code probably won't help but I can walk through the steps to reproduce the problem. I'm using Visual Studio 2003 .Net - Create new MFC Application, select application type Dialog based. - In the class view, using the wizard create a new class with a base class of CButton, I called mine MyButton. - in the main dialog create a new button, right click and "Add Event Handler" choose the Message type: BN_CLICKED and the class as MyButton. - in the handler OnBnClickedButton1 add MessageBox("hello"); - run application - click button, nothing happens however if you added the Event Handler to the main dialog class created by the wizard, then everything works fine. :confused: Ideas? Thanks Hua-Ying
In the message map for
MyButton
, add the following:ON_CONTROL_REFLECT(BN_CLICKED, OnBnClickedButton1)
and remove the
ON_BN_CLICKED()
statement.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Example code probably won't help but I can walk through the steps to reproduce the problem. I'm using Visual Studio 2003 .Net - Create new MFC Application, select application type Dialog based. - In the class view, using the wizard create a new class with a base class of CButton, I called mine MyButton. - in the main dialog create a new button, right click and "Add Event Handler" choose the Message type: BN_CLICKED and the class as MyButton. - in the handler OnBnClickedButton1 add MessageBox("hello"); - run application - click button, nothing happens however if you added the Event Handler to the main dialog class created by the wizard, then everything works fine. :confused: Ideas? Thanks Hua-Ying
Use message reflection. See technical note 62 in MSDN. Search for TN062
[
](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
Hi, I have dialog based application. If my event handler is in any class other than the main dialog class it never gets called. I would like to move the event handler to my subclass of a control. Suggestions? What am I doing wrong? Thanks Hua-Ying
IIRC, I think you will need to use "reflection" to make this work. There is usualy a weird message handle for classes like button that allows them to trap their own click messages. In VS 7, and I think VS 6 did it this way too, the message you want to trap in the wizards looks something like: =BN_CLICKED And the message map entry will be something like: ON_CONTROL_REFLECT(BN_CLICKED, OnBnClicked) Hope this helps. An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.
-
Use message reflection. See technical note 62 in MSDN. Search for TN062
[
](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
Hi, I have dialog based application. If my event handler is in any class other than the main dialog class it never gets called. I would like to move the event handler to my subclass of a control. Suggestions? What am I doing wrong? Thanks Hua-Ying
Thanks for everyone's help!! :) For anyone else who's having the same problem, one last thing you must do before this solution will work is to add a variable in you main dialog class so that when it loads your control it will use the subclass for the control instead of the original. Details: using the class wizard generate a new variable with your subclass type, click the control check box (VS 2003 .Net) so that DDX_Control will update the value. You can also follow Chris Maunder's great tutorial on subclassing controls: tutorial Hua-Ying