Jump to content

Gui Control - loose focus


 Share

Recommended Posts

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! :P

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 by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

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

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

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

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