Removing focus from button in dlg-based app
-
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. -
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. -
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.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
-
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.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"
-
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
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. -
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"
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
CButton
s inOnInitDialog()
. 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. -
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
CButton
s inOnInitDialog()
. 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.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"