Sign in to follow this  
Followers 0
vanowm

[SOLVED] UISetState(@SW_SHOW) doesn't regain focus on already opened GUI

3 posts in this topic

#1 ·  Posted (edited)

Hello!

I set so double click on tray icon would open a GUI window. Then, if the GUI window looses focus double click on tray icon doesn't bring the GUI window upfront. Is this behavior normal and expected?

If its normal, then is there other, more "practical" function to focus a GUI window other then WinActivate() ?

Thank you.

P.S.

here is an example:

#NoTrayIcon
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode",1)
Opt("TrayAutoPause",0)
Opt("TrayIconDebug",1)
$TrayGUI = TrayCreateItem("&Open GUI")
TrayItemSetOnEvent($TrayGUI, "GUI")
TrayItemSetState($TrayGUI, 512)
TrayItemSetOnEvent(TrayCreateItem("&Exit"), "_Exit")
TraySetClick(16)
TraySetState()

Global $GUI, $GUICreated = 0

Func GUI()
    If NOT $GUICreated Then
        $GUI = GuiCreate("Test")
        $GUICReated = 1
    EndIf
    GUISetState(@SW_SHOW, $GUI)
    GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose", $GUI)
EndFunc

Func GUIClose()
    GUISetState(@SW_HIDE, $GUI)
EndFunc

Func _Exit()
    Exit
EndFunc

While 1
    Sleep(100)
WEnd
Edited by vanowm

Share this post


Link to post
Share on other sites



Hi! Try this:

#NoTrayIcon
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode",1)
Opt("TrayAutoPause",0)
Opt("TrayIconDebug",1)

$GUI = GuiCreate("Test")
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose", $GUI)

$TrayGUI = TrayCreateItem("&Open GUI")
TrayItemSetOnEvent($TrayGUI, "_GUI_SHOW")
TrayItemSetState($TrayGUI, 512)
TrayItemSetOnEvent(TrayCreateItem("&Exit"), "_Exit")
TraySetClick(16)
TraySetState()

While 1
    Sleep(100)
WEnd

Func _GUI_SHOW()
    If Not BitAND(WinGetState($GUI), 2) Then GUISetState(@SW_SHOW, $GUI)
    If Not BitAND(WinGetState($GUI), 8) Then GUISetState(@SW_RESTORE)
EndFunc

Func GUIClose()
    GUISetState(@SW_HIDE, $GUI)
EndFunc

Func _Exit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Excellent!

Works like a charm.

Thank you very much :)

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