Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

GUI Control Focus


  • Please log in to reply
2 replies to this topic

#1 Jon8c

Jon8c

    Seeker

  • Active Members
  • 21 posts

Posted 28 December 2009 - 05:57 AM

How do I determine whether a GUI control, specifically input boxes and buttons, has focus? Since I'm not sure what focus actually means, to be plain, I simply want to be able to determine when an input box is selected in that the blinking typing cursor is present within the box; for buttons, I want to determine whether a button is enabled/pressed/activated (or w/e). I've tried using "GUICtrlGetState" for buttons, but its "enabled" state doesn't specify the condition I am looking for. Currently, my GUI simply recognizes when the primary mouse button is in the "pressed" state while hovering over a control, meaning I could click on some random point away from the control, hold the click, and move onto the control (which I would not like to happen). Is there anyway to detect these states?

On a side note, is there a way to prevent the text in a combo box from being editted by the user, like how "$ES_ReadOnly" can prevent editting of an input box?







#2 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,315 posts

Posted 28 December 2009 - 11:32 AM

How do I determine whether a GUI control, specifically input boxes and buttons, has focus? Since I'm not sure what focus actually means, to be plain, I simply want to be able to determine when an input box is selected in that the blinking typing cursor is present within the box; for buttons, I want to determine whether a button is enabled/pressed/activated (or w/e). I've tried using "GUICtrlGetState" for buttons, but its "enabled" state doesn't specify the condition I am looking for. Currently, my GUI simply recognizes when the primary mouse button is in the "pressed" state while hovering over a control, meaning I could click on some random point away from the control, hold the click, and move onto the control (which I would not like to happen). Is there anyway to detect these states?

On a side note, is there a way to prevent the text in a combo box from being editted by the user, like how "$ES_ReadOnly" can prevent editting of an input box?

If a control has focus it means it will receive keyboard inputs.

If you click and hold the left mouse button down away from a button then drag the cursor onto the button and let the mouse button go it will not behave as though the button is clicked.

You can tell when combo has focus by testing for the $CBN_SETFOCUS and $CBN_KILLFOCUS notifications in a handler for $WM_COMMAND
Plain Text         
GuiRegisterMsg($WM_COMMAND,"MY_WM_COMMAND") Global $fComboFocused = False  Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)     Local $nNotifyCode = _HiWord($wParam)     Local $nID = _LoWord($wParam)  ; Local $hCtrl = $lParam     Switch $nID     Case $combo1     Switch $nNotifyCode     Case $CBN_SETFOCUS     $fComboFocused = True     Case $CBN_KILLFOCUS     $fComboFocused = False     EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _HiWord($x)     Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x)     Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord


If you want to prevent the text displayed from being changed you need to set the combo style to include $CBS_DROPDOWNLIST like this for example-
$comb1 = GUICtrlCreateCombo("item1", 10, 10,120,22,BitOr($GUI_SS_DEFAULT_COMBO,$CBS_DROPDOWNLIST))

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#3 Jon8c

Jon8c

    Seeker

  • Active Members
  • 21 posts

Posted 31 December 2009 - 06:16 PM

Thank you for the reply. Sorry, I was out of town for a few days.

If you click and hold the left mouse button down away from a button then drag the cursor onto the button and let the mouse button go it will not behave as though the button is clicked.

Yeah, I already knew this. I only set it this way as a temporary solution, since I did not know how to determine a control's focus state.

If a control has focus it means it will receive keyboard inputs.

How exactly do I figure this out? Send a random keyboard msg to the GUI and see which control changes? If so, how would I prevent the user from seeing such changes? Make it "instantaneous"?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users