Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Event Handler Never Called??

Event Handler Never Called??

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H hyling

    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

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #3

    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

    H 1 Reply Last reply
    0
    • J Jaime Stuardo

      some example code so that we can see what happen? I'm not a wizard :) Jaime

      H Offline
      H Offline
      hyling
      wrote on last edited by
      #4

      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

      M B D PJ ArendsP 4 Replies Last reply
      0
      • D David Crow

        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

        H Offline
        H Offline
        hyling
        wrote on last edited by
        #5

        See my response to Jamie please, that should be enough to completely reproduce the problem. Thanks Hua-Ying

        1 Reply Last reply
        0
        • H hyling

          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

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #6

          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

          1 Reply Last reply
          0
          • H hyling

            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

            B Offline
            B Offline
            bikram singh
            wrote on last edited by
            #7

            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.

            1 Reply Last reply
            0
            • H hyling

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #8

              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

              1 Reply Last reply
              0
              • H hyling

                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

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #9

                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!

                Within you lies the power for good; Use it!

                H 1 Reply Last reply
                0
                • H hyling

                  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

                  N Offline
                  N Offline
                  Navin
                  wrote on last edited by
                  #10

                  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.

                  1 Reply Last reply
                  0
                  • PJ ArendsP PJ Arends

                    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!

                    H Offline
                    H Offline
                    hyling
                    wrote on last edited by
                    #11

                    Thanks, this is exactly what I'm looking for!

                    1 Reply Last reply
                    0
                    • H hyling

                      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

                      H Offline
                      H Offline
                      hyling
                      wrote on last edited by
                      #12

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups