Sign in to follow this  
Followers 0

Minimize GUI to tray fails with external minimize

6 posts in this topic

Posted

I have a GUI that minimizes to the tray. I used some code found in the forum that works fine with the GUI. However, if the GUI is minimized by other scripts or by Win+D, it minimizes to the Task Bar and does not respond other than right-click/close. The minimize and restore parts of the GUI are:

  Case $GUI_EVENT_MINIMIZE
   GUISetState(@SW_MINIMIZE)
   GUISetState(@SW_HIDE)
   TraySetState(1) ; show
   TraySetToolTip("AutoIt Scripts")
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

Func SpecialEvent() ; restore from tray
GUISetState(@SW_RESTORE)
GUISetState(@SW_SHOW)
TraySetState(2) ; hide
EndFunc   ;==>SpecialEvent

Clearly it needs some lines to cope with these external/Windows instructions but I have no idea how to define them.

Share this post


Link to post
Share on other sites



Posted

JohnSAutoIt,

Try making your GUI a child of the everpresent, but invisible, AutoIt GUI - then it does not have a taskbar button to display: :)

$iParent_Win = WinGetHandle(AutoItWinGetTitle())
$hMain_Win = GUICreate("MyGUI", 200, 120, -1, -1, Default, Default, $iParent_Win)

Any help? ;)

M23

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks for the tip on AutoItWinGetTitle which I've never heard of! Your edit did what you described . Perhaps I was not specific enough - when I noted it minimized to the taskbar, that was it, no tray icon. With no presence on the GUI I have to close the process.

Edit:

The original GUI Create was as follows:

$Input1 = GUICreate("AutoIt Scripts", 300, 630, 100, 60, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
Edited by JohnSAutoIt

Share this post


Link to post
Share on other sites

Posted

I remember that if I had minimized some GUIs from external application, I had to use WinSetState instead of GuiSetState, to get everything working like expected.

Share this post


Link to post
Share on other sites

Posted (edited)

I think I see the intent of using WinSetState. I tried it but still had the problem that the task bar item was unresponsive.

I added a Function so I could monitor the window state. It seemed to follow what one would expect when Win+D activated, WinGetState was 23 so it was being seen as minimized, enabled etc.

I resolved the problem by adding the WinGetState line:

Case $GUI_EVENT_MINIMIZE
   GUISetState(@SW_MINIMIZE)
   GUISetState(@SW_HIDE)
   TraySetState(1) ; show
   TraySetToolTip("AutoIt Scripts")
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
If BitAND(WinGetState("AutoIt Scripts"), 16) Then TraySetState(1) ; show
WEnd

Func SpecialEvent() ; restore from tray
GUISetState(@SW_RESTORE)
GUISetState(@SW_SHOW)
TraySetState(2) ; hide
EndFunc   ;==>SpecialEvent

That ensures the tray icon is visible when the GUI is minimized by whatever means. If externally minimized, the task bar item appeared as well as the tray icon but I can live with that (not a normal situation). I tried Melba23's lines on top of that addition - it did not immediately improve things so I called it a day. It's now usable.

Thanks all.

Edited by JohnSAutoIt

Share this post


Link to post
Share on other sites

Posted

A belated resolution FYI based on Funkey's suggestion:

Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE)
TraySetState(1) ; show
TraySetToolTip("AutoIt Scripts")
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If BitAND(WinGetState("AutoIt Scripts"), 16) Then
GUISetState(@SW_HIDE) ; hide
TraySetState(1) ; show
EndIf

I found that the GUISetState and the TraySetState lines had to be in that order. Now the window minimizes to tray even when it's by an external operation such as Win+D

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