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. Using SetFocus() in a push button.

Using SetFocus() in a push button.

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
10 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.
  • D Offline
    D Offline
    dipuks
    wrote on last edited by
    #1

    Hey I have a C++ WIN32 app having a dialog with 5 buttons. Now i want to call the SetFocus() function to set the focus on each buttons. The focus does get set in a way, i.e., if i press the space key in key board, it will infact click the button to which the SetFocus() function was set. But visually it doesn't work. i.e., it doesn't draw a blue border on the button giving it a visual feel that the button has focus on it. Why is this happening? Is there a way to have SetFocus() draw the blue border along the button? If i open a windows folder on top of it, it will draw the blue border along the button that was called with SetFocus() function. Thanks in advance.

    K D 2 Replies Last reply
    0
    • D dipuks

      Hey I have a C++ WIN32 app having a dialog with 5 buttons. Now i want to call the SetFocus() function to set the focus on each buttons. The focus does get set in a way, i.e., if i press the space key in key board, it will infact click the button to which the SetFocus() function was set. But visually it doesn't work. i.e., it doesn't draw a blue border on the button giving it a visual feel that the button has focus on it. Why is this happening? Is there a way to have SetFocus() draw the blue border along the button? If i open a windows folder on top of it, it will draw the blue border along the button that was called with SetFocus() function. Thanks in advance.

      K Offline
      K Offline
      Klaus Werner Konrad
      wrote on last edited by
      #2

      May be you have to invalidate the button to enforce a redraw ...

      D A 2 Replies Last reply
      0
      • K Klaus Werner Konrad

        May be you have to invalidate the button to enforce a redraw ...

        D Offline
        D Offline
        dipuks
        wrote on last edited by
        #3

        That's not working

        K 1 Reply Last reply
        0
        • K Klaus Werner Konrad

          May be you have to invalidate the button to enforce a redraw ...

          A Offline
          A Offline
          Albert Holguin
          wrote on last edited by
          #4

          that's a good question... who actually draws that, the button or button's parent window? maybe invalidate the parent window?

          K 1 Reply Last reply
          0
          • A Albert Holguin

            that's a good question... who actually draws that, the button or button's parent window? maybe invalidate the parent window?

            K Offline
            K Offline
            Klaus Werner Konrad
            wrote on last edited by
            #5

            AFAIK the window (and every control is a window by itself) draws itself until the style is owner-drawn. If you invalidate the parent window, this will draw itself and then force a redraw of EVERY of its child windows. (To minimize this effect there is a function InvalidateRegion) But my knowledge is from old WinAPI32 - may be something changed since then ...

            modified on Thursday, March 17, 2011 3:36 PM

            A 1 Reply Last reply
            0
            • D dipuks

              That's not working

              K Offline
              K Offline
              Klaus Werner Konrad
              wrote on last edited by
              #6

              Ok, may be you must follow this by a call to UpdateWindow, 'cause InvalidateWindow simply raise a flag to send a WM_Paint message to the window if the message queue is empty ...

              1 Reply Last reply
              0
              • K Klaus Werner Konrad

                AFAIK the window (and every control is a window by itself) draws itself until the style is owner-drawn. If you invalidate the parent window, this will draw itself and then force a redraw of EVERY of its child windows. (To minimize this effect there is a function InvalidateRegion) But my knowledge is from old WinAPI32 - may be something changed since then ...

                modified on Thursday, March 17, 2011 3:36 PM

                A Offline
                A Offline
                Albert Holguin
                wrote on last edited by
                #7

                i know every control is a window, but that's why i was asking who really draws the button "highlighting"? ...it would depend on how the framework implemented the highlighting, which i'm not really sure about... but if he says that dragging an explorer window over it does the trick, that has the same effect as invalidating the parent...

                1 Reply Last reply
                0
                • D dipuks

                  Hey I have a C++ WIN32 app having a dialog with 5 buttons. Now i want to call the SetFocus() function to set the focus on each buttons. The focus does get set in a way, i.e., if i press the space key in key board, it will infact click the button to which the SetFocus() function was set. But visually it doesn't work. i.e., it doesn't draw a blue border on the button giving it a visual feel that the button has focus on it. Why is this happening? Is there a way to have SetFocus() draw the blue border along the button? If i open a windows folder on top of it, it will draw the blue border along the button that was called with SetFocus() function. Thanks in advance.

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

                  Are CDialog::SetDefID() or CDialog::GotoDlgCtrl() of any help?

                  "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

                  "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

                  D 1 Reply Last reply
                  0
                  • D David Crow

                    Are CDialog::SetDefID() or CDialog::GotoDlgCtrl() of any help?

                    "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

                    "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

                    D Offline
                    D Offline
                    dipuks
                    wrote on last edited by
                    #9

                    Finally i got this working. What i did was, do a SetFocus(ParentWindow) and then do a SetFocus(ChildWindow) on this order and it worked just fine.

                    K 1 Reply Last reply
                    0
                    • D dipuks

                      Finally i got this working. What i did was, do a SetFocus(ParentWindow) and then do a SetFocus(ChildWindow) on this order and it worked just fine.

                      K Offline
                      K Offline
                      Klaus Werner Konrad
                      wrote on last edited by
                      #10

                      Seems that is what I replied to another question - is it that this button is the only editable control on the form ? 'Caus then, a SetFocus() will have no effect on painting, 'cause the focus didn't change really ...

                      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