Jump to content

GUI Control Focus


Jon8c
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

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.
Link to comment
Share on other sites

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"?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...