Sign in to follow this  
Followers 0

GUI Control Focus

3 posts in this topic

Posted

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?

Share this post


Link to post
Share on other sites



Posted

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))

Share this post


Link to post
Share on other sites

Posted

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"?

Share this post


Link to post
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
Sign in to follow this  
Followers 0