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. How to debug this? (MFC dialog control question.)

How to debug this? (MFC dialog control question.)

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingquestionc++helptutorial
13 Posts 3 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.
  • L Offline
    L Offline
    largeinsd
    wrote on last edited by
    #1

    Hi, In my darkest of hours, you guys never fail to provide shining light. So here goes... I'm creating a radio button dialog that goes on top of another dialog, and I'm having a problem with initialization of the whole thing. Specifically, when my radio button dialog is being initialized something is firing off an OnBnClicked event for one of the radio buttons. 1) What could possibly be doing this? It happens in such a way as not to actually leave the button selected. (Yet when you step through you definitely get sent to that event handler.) 2) Is it somehow possible using the magic of VisualStudio to trace what's triggering an event handler? 3) As I mentioned, this radio button dialog window gets pasted on top of another dialog window. Is there something weird about this process? Thanks - eagerly awaiting any replies - Jason

    D 1 Reply Last reply
    0
    • L largeinsd

      Hi, In my darkest of hours, you guys never fail to provide shining light. So here goes... I'm creating a radio button dialog that goes on top of another dialog, and I'm having a problem with initialization of the whole thing. Specifically, when my radio button dialog is being initialized something is firing off an OnBnClicked event for one of the radio buttons. 1) What could possibly be doing this? It happens in such a way as not to actually leave the button selected. (Yet when you step through you definitely get sent to that event handler.) 2) Is it somehow possible using the magic of VisualStudio to trace what's triggering an event handler? 3) As I mentioned, this radio button dialog window gets pasted on top of another dialog window. Is there something weird about this process? Thanks - eagerly awaiting any replies - Jason

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

      So if you set a breakpoint in the event handler and check the call stack, what do you see? In any case, why is this a problem? Is it causing something to not get drawn?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      L 1 Reply Last reply
      0
      • D David Crow

        So if you set a breakpoint in the event handler and check the call stack, what do you see? In any case, why is this a problem? Is it causing something to not get drawn?


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        L Offline
        L Offline
        largeinsd
        wrote on last edited by
        #3

        Dave, Thanks for your interest! It's a problem for the opposite reason, it IS causing something to be drawn. Basically, the rest of the dialog configuration depends on which radio button is selected... so when it automatically selects somethin', it's configuring the dialog according to that. And I'm trying to design it so that it comes up blank, ready for a radio button to be selected. Here's the first entry in the call stack prior to the event handler: >Direct3DMFC.exe!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x0012e460, unsigned >int nID=1062, int nCode=0, void (void)* pfn=0x00523fb6, void * >pExtra=0x00000000, unsigned int nSig=56, AFX_CMDHANDLERINFO * >pHandlerInfo=0x00000000) Line 82 C++ Any further suggestions? I should point out that in attempting to debug this little caper i have done the following: 1) Moved the radio button to another location (bug persists) 2) Deleted the message map according to this event handler (bug goes away) 3) Created another radio button with another name for handling similar events. (This one now takes the problem.) 4) Checked as many params etc as I can think of to see why this radio button would be different from all the others? The only thing that I can think of is that it may have been the last one that I put on there. Yay - debugging! Thanks again - Jason

        D R 2 Replies Last reply
        0
        • L largeinsd

          Dave, Thanks for your interest! It's a problem for the opposite reason, it IS causing something to be drawn. Basically, the rest of the dialog configuration depends on which radio button is selected... so when it automatically selects somethin', it's configuring the dialog according to that. And I'm trying to design it so that it comes up blank, ready for a radio button to be selected. Here's the first entry in the call stack prior to the event handler: >Direct3DMFC.exe!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x0012e460, unsigned >int nID=1062, int nCode=0, void (void)* pfn=0x00523fb6, void * >pExtra=0x00000000, unsigned int nSig=56, AFX_CMDHANDLERINFO * >pHandlerInfo=0x00000000) Line 82 C++ Any further suggestions? I should point out that in attempting to debug this little caper i have done the following: 1) Moved the radio button to another location (bug persists) 2) Deleted the message map according to this event handler (bug goes away) 3) Created another radio button with another name for handling similar events. (This one now takes the problem.) 4) Checked as many params etc as I can think of to see why this radio button would be different from all the others? The only thing that I can think of is that it may have been the last one that I put on there. Yay - debugging! Thanks again - Jason

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

          @largeinsd wrote:

          Basically, the rest of the dialog configuration depends on which radio button is selected... so when it automatically selects somethin', it's configuring the dialog according to that.

          Do you have an int member variable that represents all the radio buttons, or do you have a CButton member variable for each?


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          L 1 Reply Last reply
          0
          • L largeinsd

            Dave, Thanks for your interest! It's a problem for the opposite reason, it IS causing something to be drawn. Basically, the rest of the dialog configuration depends on which radio button is selected... so when it automatically selects somethin', it's configuring the dialog according to that. And I'm trying to design it so that it comes up blank, ready for a radio button to be selected. Here's the first entry in the call stack prior to the event handler: >Direct3DMFC.exe!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x0012e460, unsigned >int nID=1062, int nCode=0, void (void)* pfn=0x00523fb6, void * >pExtra=0x00000000, unsigned int nSig=56, AFX_CMDHANDLERINFO * >pHandlerInfo=0x00000000) Line 82 C++ Any further suggestions? I should point out that in attempting to debug this little caper i have done the following: 1) Moved the radio button to another location (bug persists) 2) Deleted the message map according to this event handler (bug goes away) 3) Created another radio button with another name for handling similar events. (This one now takes the problem.) 4) Checked as many params etc as I can think of to see why this radio button would be different from all the others? The only thing that I can think of is that it may have been the last one that I put on there. Yay - debugging! Thanks again - Jason

            R Offline
            R Offline
            Reagan Conservative
            wrote on last edited by
            #5

            Also, don't you need a Group Box for the radio buttons to act properly? Is that not true David?

            John P.

            L D 2 Replies Last reply
            0
            • D David Crow

              @largeinsd wrote:

              Basically, the rest of the dialog configuration depends on which radio button is selected... so when it automatically selects somethin', it's configuring the dialog according to that.

              Do you have an int member variable that represents all the radio buttons, or do you have a CButton member variable for each?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              L Offline
              L Offline
              largeinsd
              wrote on last edited by
              #6

              DavidCrow wrote:

              Do you have an int member variable that represents all the radio buttons, or do you have a CButton member variable for each?

              The former - I have an int variable which is initialzed to -1 (no selection) in the constructor, and then when I get an "OnBnClickedRdBox1" event I do the following: void CShapeSelect::OnBnClickedRdBox1() { m_ShapeSelected = 2; GetParent()->PostMessage(WM_SHAPE_RADIO_CHANGED); }

              D 1 Reply Last reply
              0
              • L largeinsd

                DavidCrow wrote:

                Do you have an int member variable that represents all the radio buttons, or do you have a CButton member variable for each?

                The former - I have an int variable which is initialzed to -1 (no selection) in the constructor, and then when I get an "OnBnClickedRdBox1" event I do the following: void CShapeSelect::OnBnClickedRdBox1() { m_ShapeSelected = 2; GetParent()->PostMessage(WM_SHAPE_RADIO_CHANGED); }

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

                @largeinsd wrote:

                The former - I have an int variable...

                I would lose that and use a CButton for each. Far less confusing that way.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                L 1 Reply Last reply
                0
                • R Reagan Conservative

                  Also, don't you need a Group Box for the radio buttons to act properly? Is that not true David?

                  John P.

                  L Offline
                  L Offline
                  largeinsd
                  wrote on last edited by
                  #8

                  jparken wrote:

                  Also, don't you need a Group Box for the radio buttons to act properly? Is that not true David?

                  Ok, interesting point. For what it's worth I do have the radio buttons enclosed in a group box. If there is some particular initialization required, please let me know. -Jason

                  1 Reply Last reply
                  0
                  • D David Crow

                    @largeinsd wrote:

                    The former - I have an int variable...

                    I would lose that and use a CButton for each. Far less confusing that way.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    L Offline
                    L Offline
                    largeinsd
                    wrote on last edited by
                    #9

                    DavidCrow wrote:

                    I would lose that and use a CButton for each. Far less confusing that way.

                    Ok, well I'm gonna go ahead and implement that, if nothing else hoping to work around this problem. But let me ask you this - is there a way to make the dialog class catch the button selection event that is slightly more elegant than they way i've done it here with my own call to PostMessage ? Thanks - Jason

                    L D 2 Replies Last reply
                    0
                    • L largeinsd

                      DavidCrow wrote:

                      I would lose that and use a CButton for each. Far less confusing that way.

                      Ok, well I'm gonna go ahead and implement that, if nothing else hoping to work around this problem. But let me ask you this - is there a way to make the dialog class catch the button selection event that is slightly more elegant than they way i've done it here with my own call to PostMessage ? Thanks - Jason

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

                      @largeinsd wrote:

                      But let me ask you this - is there a way to make the dialog class catch the button selection event that is slightly more elegant than they way i've done it here with my own call to PostMessage ?

                      Sure. Just use ClassWizard (Ctrl+W) to create a BN_CLICKED handler. All the buttons can use the same handler, or they can each have their own.


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      1 Reply Last reply
                      0
                      • L largeinsd

                        DavidCrow wrote:

                        I would lose that and use a CButton for each. Far less confusing that way.

                        Ok, well I'm gonna go ahead and implement that, if nothing else hoping to work around this problem. But let me ask you this - is there a way to make the dialog class catch the button selection event that is slightly more elegant than they way i've done it here with my own call to PostMessage ? Thanks - Jason

                        L Offline
                        L Offline
                        largeinsd
                        wrote on last edited by
                        #11

                        Ok, here's the update you're just dying to here: i encounter the same problem using buttons - as soon as i add an event handler to take action when the radio buttons are selected, it gets activated on initialization. however, using method i can at least use the m_MyRadioButton.GetChecked() method to do some screening. it's a fine work around, but where is the ELEGANCE?

                        D 1 Reply Last reply
                        0
                        • R Reagan Conservative

                          Also, don't you need a Group Box for the radio buttons to act properly? Is that not true David?

                          John P.

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

                          jparken wrote:

                          Also, don't you need a Group Box for the radio buttons to act properly? Is that not true David?

                          No, a group control (i.e., a control having the BS_GROUPBOX style) is not necessary. Perhaps you are confusing that with the first radio button of the group having the WS_GROUP style and all others in the group not.


                          "A good athlete is the result of a good and worthy opponent." - David Crow

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          1 Reply Last reply
                          0
                          • L largeinsd

                            Ok, here's the update you're just dying to here: i encounter the same problem using buttons - as soon as i add an event handler to take action when the radio buttons are selected, it gets activated on initialization. however, using method i can at least use the m_MyRadioButton.GetChecked() method to do some screening. it's a fine work around, but where is the ELEGANCE?

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

                            @largeinsd wrote:

                            ...it gets activated on initialization.

                            The solution to this is to differentiate between initialization and the actual clicking of one of the buttons. I use a bool member variable to denote this.


                            "A good athlete is the result of a good and worthy opponent." - David Crow

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            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