HockeyFan Posted August 1, 2008 Share Posted August 1, 2008 Hi, Is it possible to perform a function when focus is lost from a GUI control? If so, is there a particular command to use? I've looked through the Help section but I don't see anything that references losing focus. Thanks in advance! Link to comment Share on other sites More sharing options...
Andreik Posted August 1, 2008 Share Posted August 1, 2008 (edited) Hi,Is it possible to perform a function when focus is lost from a GUI control? If so, is there a particular command to use? I've looked through the Help section but I don't see anything that references losing focus. Thanks in advance! Look in helpfile about GuiCtrlSetState and state $GUI_NOFOCUS, maybe is what you want.Or you can use AdlibEnable to check if focus was lost. Edited August 1, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
rasim Posted August 2, 2008 Share Posted August 2, 2008 HockeyFanExample:#include <GuiConstantsEx.au3> $hGUI = GUICreate("Test", 300, 200) $button1 = GUICtrlCreateButton("OK", 10, 160, 75, 23) $button2 = GUICtrlCreateButton("Cancel", 210, 160, 75, 23) GUICtrlSetState($button1, $GUI_FOCUS) GUISetState() AdlibEnable("_GetFocused") Do Until GUIGetMsg() = -3 AdlibDisable() Func _GetFocused() If ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)) = GUICtrlGetHandle($button2) Then ConsoleWrite("->Cancel button is focused" & @LF) EndIf EndFunc Link to comment Share on other sites More sharing options...
HockeyFan Posted August 4, 2008 Author Share Posted August 4, 2008 HockeyFan Example: #include <GuiConstantsEx.au3> $hGUI = GUICreate("Test", 300, 200) $button1 = GUICtrlCreateButton("OK", 10, 160, 75, 23) $button2 = GUICtrlCreateButton("Cancel", 210, 160, 75, 23) GUICtrlSetState($button1, $GUI_FOCUS) GUISetState() AdlibEnable("_GetFocused") Do Until GUIGetMsg() = -3 AdlibDisable() Func _GetFocused() If ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)) = GUICtrlGetHandle($button2) Then ConsoleWrite("->Cancel button is focused" & @LF) EndIf EndFunc Rasim, Thanks for your help. I've altered your script to more closely match what I'm trying to accomplish. #include <GuiConstantsEx.au3> $hGUI = GUICreate("Test", 300, 200) $button1 = GUICtrlCreateButton("OK", 10, 160, 75, 23) $button2 = GUICtrlCreateButton("Cancel", 210, 160, 75, 23) GUICtrlSetState($button1, $GUI_FOCUS) GUISetState() AdlibEnable("_LooseFocus") Do Until GUIGetMsg() = -3 AdlibDisable() Func _LooseFocus() If ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)) <> GUICtrlGetHandle($button1) Then ConsoleWrite("->OK button has lost focus " & @SEC & @LF) EndIf Question: What does the "-3" from GUIGetMsg() = -3 represent? Again, thanks for your help! Link to comment Share on other sites More sharing options...
martin Posted August 4, 2008 Share Posted August 4, 2008 Rasim, Thanks for your help. I've altered your script to more closely match what I'm trying to accomplish. #include <GuiConstantsEx.au3> $hGUI = GUICreate("Test", 300, 200) $button1 = GUICtrlCreateButton("OK", 10, 160, 75, 23) $button2 = GUICtrlCreateButton("Cancel", 210, 160, 75, 23) GUICtrlSetState($button1, $GUI_FOCUS) GUISetState() AdlibEnable("_LooseFocus") Do Until GUIGetMsg() = -3 AdlibDisable() Func _LooseFocus() If ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)) <> GUICtrlGetHandle($button1) Then ConsoleWrite("->OK button has lost focus " & @SEC & @LF) EndIf Question: What does the "-3" from GUIGetMsg() = -3 represent? Again, thanks for your help!-3 is the value of $GUI_EVENT_CLOSE which is the event when you click on the close icon.. 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 More sharing options...
HockeyFan Posted August 4, 2008 Author Share Posted August 4, 2008 -3 is the value of $GUI_EVENT_CLOSE which is the event when you click on the close icon..Thanks martin...now I understand. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now