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. Removing focus from button in dlg-based app

Removing focus from button in dlg-based app

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionlearning
7 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.
  • V Offline
    V Offline
    Vikram A Punathambekar
    wrote on last edited by
    #1

    I have a big matrix of buttons in a dlg-based MFC app wizard generated program. When any button is clicked, the focus remains on that button even after the handler is called; until another button is clicked. Then I modified the handler - this is the first line in the handler now:

    GetDlgItem(IDC_STATIC1)->SetFocus();

    I'm setting the focus on another static control now. The handler is for the Dialog class, of course. What happens is that the first time I click on a button, it retains the focus. When I click on the same button again, it loses focus (which is what I want). I tried repeating the call to SetFocus() , but it doesn't help. Can anybody suggest a way of taking the focus away completely, please? (I don't want to disable the button) Thanks,
    Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

    V N B 3 Replies Last reply
    0
    • V Vikram A Punathambekar

      I have a big matrix of buttons in a dlg-based MFC app wizard generated program. When any button is clicked, the focus remains on that button even after the handler is called; until another button is clicked. Then I modified the handler - this is the first line in the handler now:

      GetDlgItem(IDC_STATIC1)->SetFocus();

      I'm setting the focus on another static control now. The handler is for the Dialog class, of course. What happens is that the first time I click on a button, it retains the focus. When I click on the same button again, it loses focus (which is what I want). I tried repeating the call to SetFocus() , but it doesn't help. Can anybody suggest a way of taking the focus away completely, please? (I don't want to disable the button) Thanks,
      Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      One solution is Win32 API's SendMessage(). Kuphryn

      1 Reply Last reply
      0
      • V Vikram A Punathambekar

        I have a big matrix of buttons in a dlg-based MFC app wizard generated program. When any button is clicked, the focus remains on that button even after the handler is called; until another button is clicked. Then I modified the handler - this is the first line in the handler now:

        GetDlgItem(IDC_STATIC1)->SetFocus();

        I'm setting the focus on another static control now. The handler is for the Dialog class, of course. What happens is that the first time I click on a button, it retains the focus. When I click on the same button again, it loses focus (which is what I want). I tried repeating the call to SetFocus() , but it doesn't help. Can anybody suggest a way of taking the focus away completely, please? (I don't want to disable the button) Thanks,
        Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

        N Offline
        N Offline
        Neville Franks
        wrote on last edited by
        #3

        There are various problems changing focus to other controls upon some UI action in a dialog. Typically it comes down to the order things happen. In your case of a button click it may be that you are changing focus on the button down, and then when the button up happens Windows puts the focus back on the current control. To resolve issues like this in ED I use PostMessage() with a user defined message, which sets the focus where I want. Hope that helps. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

        V 1 Reply Last reply
        0
        • V Vikram A Punathambekar

          I have a big matrix of buttons in a dlg-based MFC app wizard generated program. When any button is clicked, the focus remains on that button even after the handler is called; until another button is clicked. Then I modified the handler - this is the first line in the handler now:

          GetDlgItem(IDC_STATIC1)->SetFocus();

          I'm setting the focus on another static control now. The handler is for the Dialog class, of course. What happens is that the first time I click on a button, it retains the focus. When I click on the same button again, it loses focus (which is what I want). I tried repeating the call to SetFocus() , but it doesn't help. Can anybody suggest a way of taking the focus away completely, please? (I don't want to disable the button) Thanks,
          Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

          B Offline
          B Offline
          BhaskarBora
          wrote on last edited by
          #4

          I dont think what you did will create problem. i simulated the same condition here in one test dialog box and could see things working fine. what i did? On button click i am setting focus on some statis text ctrl. thus, after the button is clicked the button looses the focus. bhaskar ___________________________ "Think big, think fast, think ahead. Ideas are no one's monopoly"

          V 1 Reply Last reply
          0
          • N Neville Franks

            There are various problems changing focus to other controls upon some UI action in a dialog. Typically it comes down to the order things happen. In your case of a button click it may be that you are changing focus on the button down, and then when the button up happens Windows puts the focus back on the current control. To resolve issues like this in ED I use PostMessage() with a user defined message, which sets the focus where I want. Hope that helps. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            Thanks, I'll check it out and let you know. Regards,
            Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

            1 Reply Last reply
            0
            • B BhaskarBora

              I dont think what you did will create problem. i simulated the same condition here in one test dialog box and could see things working fine. what i did? On button click i am setting focus on some statis text ctrl. thus, after the button is clicked the button looses the focus. bhaskar ___________________________ "Think big, think fast, think ahead. Ideas are no one's monopoly"

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              BhaskarBora wrote: I dont think what you did will create problem. It does. BhaskarBora wrote: what i did? On button click i am setting focus on some statis text ctrl. thus, after the button is clicked the button looses the focus. Did you create an array of buttons? I don't place the buttons on the dialog box using the dialog editor - there are 200 of them :omg: and they must be aligned perfectly. So I create them using an array of CButtons in OnInitDialog(). Regards,
              Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

              B 1 Reply Last reply
              0
              • V Vikram A Punathambekar

                BhaskarBora wrote: I dont think what you did will create problem. It does. BhaskarBora wrote: what i did? On button click i am setting focus on some statis text ctrl. thus, after the button is clicked the button looses the focus. Did you create an array of buttons? I don't place the buttons on the dialog box using the dialog editor - there are 200 of them :omg: and they must be aligned perfectly. So I create them using an array of CButtons in OnInitDialog(). Regards,
                Vikram. ----------------------------- KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames. pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.

                B Offline
                B Offline
                BhaskarBora
                wrote on last edited by
                #7

                i think there wouldnt be any difference whether you use an array or something else. as far as you get the ctrl's address it enough. ___________________________ "Think big, think fast, think ahead. Ideas are no one's monopoly"

                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