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. when use a button on dialog, i get trouble

when use a button on dialog, i get trouble

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
8 Posts 4 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.
  • S Offline
    S Offline
    samfromcn
    wrote on last edited by
    #1

    there is a button uses IDC_BTN1 on my dialog, I write it's OnClick() function like follow code: CMyDialog::OnBtn1Click() { m_bState = !m_bState; // remember whether the // button highlights; m_btn1.SetState(m_bState); // set the button's state } there is another button uses IDC_BTN2 on my dialog, the problem is when I click m_btn2, if m_btn1 still highlights, the OnClick function of m_btn1 will be called. This is not what I want. Someone may tell me how to prevent this from happenning again. thanks a lot:cool:

    C R S 3 Replies Last reply
    0
    • S samfromcn

      there is a button uses IDC_BTN1 on my dialog, I write it's OnClick() function like follow code: CMyDialog::OnBtn1Click() { m_bState = !m_bState; // remember whether the // button highlights; m_btn1.SetState(m_bState); // set the button's state } there is another button uses IDC_BTN2 on my dialog, the problem is when I click m_btn2, if m_btn1 still highlights, the OnClick function of m_btn1 will be called. This is not what I want. Someone may tell me how to prevent this from happenning again. thanks a lot:cool:

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      And what happens if you press the second button without pressing the first button before ? That is not logical that OnBtn1Click gets called only when the button1 is in another state. Are you absolutely sure that OnBtn1Click gets called (did you use your debugger to check if it was inside this function) ? Alos an easy way to check is to display two different message boxes in each of the handler.

      S 1 Reply Last reply
      0
      • C Cedric Moonen

        And what happens if you press the second button without pressing the first button before ? That is not logical that OnBtn1Click gets called only when the button1 is in another state. Are you absolutely sure that OnBtn1Click gets called (did you use your debugger to check if it was inside this function) ? Alos an easy way to check is to display two different message boxes in each of the handler.

        S Offline
        S Offline
        samfromcn
        wrote on last edited by
        #3

        I write this code in OnBtn1Click(): TRACE(".......state is %x........\n", m_btn1.GetState()); when I click the other buttons, if m_btn1 highlights, debugger will types".......state is 8........". And I just find, need not click the other buttons, if I switch to other application window, while m_btn1 highlights, debugger will type same message also. It's strange.:confused:

        C 1 Reply Last reply
        0
        • S samfromcn

          I write this code in OnBtn1Click(): TRACE(".......state is %x........\n", m_btn1.GetState()); when I click the other buttons, if m_btn1 highlights, debugger will types".......state is 8........". And I just find, need not click the other buttons, if I switch to other application window, while m_btn1 highlights, debugger will type same message also. It's strange.:confused:

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Post the code of the message map of your dialog class (the part that starts with BEGIN_MESSAGE_MAP(CYourDialog, CDialog) and finishes with END_MESSAGE_MAP() Post also the code for the OnBtn2Click handler function

          S 1 Reply Last reply
          0
          • C Cedric Moonen

            Post the code of the message map of your dialog class (the part that starts with BEGIN_MESSAGE_MAP(CYourDialog, CDialog) and finishes with END_MESSAGE_MAP() Post also the code for the OnBtn2Click handler function

            S Offline
            S Offline
            samfromcn
            wrote on last edited by
            #5

            BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_BN_CLICKED(IDC_BTN1, OnBtn1Click) END_MESSAGE_MAP() There is no code for m_btn2 I find something new, I am sure it because focus, when m_btn1 lost focus, if it hightlights, OnBtn1Click() is called. But I don't konw how to prevent it. My code is very simple, you may create a dialog application and put 2 buttons on dialog, I think you will find the same thing.;)

            D 1 Reply Last reply
            0
            • S samfromcn

              there is a button uses IDC_BTN1 on my dialog, I write it's OnClick() function like follow code: CMyDialog::OnBtn1Click() { m_bState = !m_bState; // remember whether the // button highlights; m_btn1.SetState(m_bState); // set the button's state } there is another button uses IDC_BTN2 on my dialog, the problem is when I click m_btn2, if m_btn1 still highlights, the OnClick function of m_btn1 will be called. This is not what I want. Someone may tell me how to prevent this from happenning again. thanks a lot:cool:

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #6

              Why are you calling m_btn1.SetState()? If you're wanting a button that is alternately on and off, use a checkbox with the push button style. Windows will then take care of the button state automatically.

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              1 Reply Last reply
              0
              • S samfromcn

                BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_BN_CLICKED(IDC_BTN1, OnBtn1Click) END_MESSAGE_MAP() There is no code for m_btn2 I find something new, I am sure it because focus, when m_btn1 lost focus, if it hightlights, OnBtn1Click() is called. But I don't konw how to prevent it. My code is very simple, you may create a dialog application and put 2 buttons on dialog, I think you will find the same thing.;)

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

                What does the project's resource.h file look like? When was the last time you did a rebuild-all?


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "We will be known forever by the tracks we leave." - Native American Proverb

                1 Reply Last reply
                0
                • S samfromcn

                  there is a button uses IDC_BTN1 on my dialog, I write it's OnClick() function like follow code: CMyDialog::OnBtn1Click() { m_bState = !m_bState; // remember whether the // button highlights; m_btn1.SetState(m_bState); // set the button's state } there is another button uses IDC_BTN2 on my dialog, the problem is when I click m_btn2, if m_btn1 still highlights, the OnClick function of m_btn1 will be called. This is not what I want. Someone may tell me how to prevent this from happenning again. thanks a lot:cool:

                  S Offline
                  S Offline
                  samfromcn
                  wrote on last edited by
                  #8

                  sorry my friends, I use a checkbox now, but same thing happens again. Q:when the checkbox lost focus, if it's on state, it will become off state. while I want it to keep its on state until I press it again. help me! :(

                  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