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. Unwanted radio button click

Unwanted radio button click

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tools
6 Posts 2 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
    lor75
    wrote on last edited by
    #1

    Hello, I have programmed a MFC utility with some radio buttons on the main window. When I click on a radio button the BN_CLICKED message is captured by the handler and does some task. I have seen an unexpected behaviour: when I open another window (hard disk explorer, control panel, speaker volume and also a generic folder) and then I close it, the radio button clicks even I haven't clicked the mouse on the radio button. I suppose that this is caused by my program's window that get the focus when I close the other window. How can I block this behaviour?

    D 1 Reply Last reply
    0
    • L lor75

      Hello, I have programmed a MFC utility with some radio buttons on the main window. When I click on a radio button the BN_CLICKED message is captured by the handler and does some task. I have seen an unexpected behaviour: when I open another window (hard disk explorer, control panel, speaker volume and also a generic folder) and then I close it, the radio button clicks even I haven't clicked the mouse on the radio button. I suppose that this is caused by my program's window that get the focus when I close the other window. How can I block this behaviour?

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

      This behavior is, or at least used to be, by design. When [de]activating the window, the radio buttons do not know that. All they know is that they got focus, and the behavior for radio buttons is to auto-select on focus. See the WM_SETFOCUS message here.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      L 1 Reply Last reply
      0
      • D David Crow

        This behavior is, or at least used to be, by design. When [de]activating the window, the radio buttons do not know that. All they know is that they got focus, and the behavior for radio buttons is to auto-select on focus. See the WM_SETFOCUS message here.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

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

        Ok, I have read the WM_SETFOCUS page and now I disable all the radiobuttons when the window lose focus. This works but it seems a strange solution to me. I wonder if there is a better way to solve the problem. I want to discard message from radiobuttons when they are launched by focus changes.

        D 1 Reply Last reply
        0
        • L lor75

          Ok, I have read the WM_SETFOCUS page and now I disable all the radiobuttons when the window lose focus. This works but it seems a strange solution to me. I wonder if there is a better way to solve the problem. I want to discard message from radiobuttons when they are launched by focus changes.

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

          I just put together a dummy MFC app with four radio buttons, and an ON_BN_CLICKED() handler for each. With the app running, I open various other windows and then switch back to it, none of the four handlers are fired. Hmmmm

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          L 1 Reply Last reply
          0
          • D David Crow

            I just put together a dummy MFC app with four radio buttons, and an ON_BN_CLICKED() handler for each. With the app running, I open various other windows and then switch back to it, none of the four handlers are fired. Hmmmm

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            L Offline
            L Offline
            lor75
            wrote on last edited by
            #5

            Dear David, they aren't fired because you switch from one window to another without have a focus on radiobutton. If you click on a radio button with the mouse the radio button gets focus: if you switch frome one window to another you will see that the handlers are fired. If you never click on radiobutton with mouse this doesn't happen.

            D 1 Reply Last reply
            0
            • L lor75

              Dear David, they aren't fired because you switch from one window to another without have a focus on radiobutton. If you click on a radio button with the mouse the radio button gets focus: if you switch frome one window to another you will see that the handlers are fired. If you never click on radiobutton with mouse this doesn't happen.

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

              Nope, radio button had focus.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              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