 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
XavierGr
Joined: 15 Jul 2006 Posts: 48
|
Posted: Tue Nov 06, 2007 10:27 pm Post subject: Tray Menu misbehavior |
|
|
I made a small script that will hide the active window and create a tray submenu (in the autohotkey icon) with the hidden window in it.
Along with it I made another tray menu item that will show all previously hidden windows.
The problem I have is the following:
When there are no Hidden windows I want both the submenu and the other items deleted from the tray menu. While it works the first time, the second time I hide a window the submenu is not updated and so I can't show the hidden windows (except selecting the item that shows all hidden windows).
I've grappled with it for the last 2 hours and I can't find a bug:
| Code: |
; Hide Active Window
#h::
WinGet, WinID, ID, A
WinGetTitle, WinTitle, A
if(WinID)
{
HiddenWins++
All%HiddenWins% := WinID
if(HiddenWins = 1)
Menu, Tray, Add, UnHide All, UnHideAll
Menu, ShowMenu, Add, % WinTitle " - " WinID, ShowWin
Menu, Tray, Add, UnHide Windows, :ShowMenu
WinHide, ahk_id %WinID%
}
return
; Menu for Showing Hidden windows
ShowWin:
StringRight, temp, A_ThisMenuItem, 8
WinShow, ahk_id %temp%
Menu, ShowMenu, Delete, %A_ThisMenuItem%
HiddenWins--
if(HiddenWins = 0)
{
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
}
return
; UnHide all Hidden Windows
UnHideAll:
Loop, %HiddenWins%
{
temp := All%A_Index%
WinShow, ahk_id %temp%
}
HiddenWins := 0
Menu, ShowMenu, DeleteAll
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
return
|
It seems that the second time the submenu is empty but I can't understand why, I clearly set it with new items before I attach it to the main tray menu.
To replicate the misbehavior (Bug?) hide a window, then unhide it selecting from the Tray "UnHide Windows -> the window you chose" and then hide another window. This time you will see that the submenu UnHide Windows is empty.
Any pointers? Thanks in advance. _________________ One hotkey to rule them all! |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Wed Nov 07, 2007 12:22 am Post subject: |
|
|
I figured out what was wrong, but I'd have to say the behavior borders on bug-like. It seems that if you use DeleteAll, there's no problem, remove the last item with Delete, the menu fails to reset or something. And calling DeleteAll afterwards won't help unless you've first added an item to that menu. Still, it wasn't too hard to work around:
| Code: | ; Hide Active Window
#h::
WinGet, WinID, ID, A
WinGetTitle, WinTitle, A
if(WinID)
{
HiddenWins++
All%HiddenWins% := WinID
if(HiddenWins = 1)
Menu, Tray, Add, UnHide All, UnHideAll
Menu, ShowMenu, Add, % WinTitle " - " WinID, ShowWin
Menu, Tray, Add, UnHide Windows, :ShowMenu
WinHide, ahk_id %WinID%
}
return
; Menu for Showing Hidden windows
ShowWin:
StringRight, temp, A_ThisMenuItem, 8
WinShow, ahk_id %temp%
HiddenWins--
if(HiddenWins = 0)
{
Menu, ShowMenu, DeleteAll
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
}
Else
Menu, ShowMenu, Delete, %A_ThisMenuItem%
return
; UnHide all Hidden Windows
UnHideAll:
Loop, %HiddenWins%
{
temp := All%A_Index%
WinShow, ahk_id %temp%
}
HiddenWins := 0
Menu, ShowMenu, DeleteAll
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
return |
|
|
| Back to top |
|
 |
XavierGr
Joined: 15 Jul 2006 Posts: 48
|
Posted: Wed Nov 07, 2007 1:12 am Post subject: |
|
|
Thank you very much, now it works like a charm, though yes it seems close to be a bug.
This is the current version of the script I am using with a hotkey to unhide the previously hidden window.
I've included minimize and restore events in the script, to make it faster for the user to hide/unhide multiple windows repeatedly (without having to activate each window).
| Code: |
Menu, Tray, UseErrorLevel, On
; UnHide previously Hidden Window
#u::
if(HiddenWins <= 0)
return
temp := All%HiddenWins%
DetectHiddenWindows, On
WinGetTitle, WinTitle, ahk_id %temp%
DetectHiddenWindows, Off
WinShow, ahk_id %temp%
PostMessage, 0x112, 0xF120,,, ahk_id %temp% ; restore
MenuTitle := WinTitle " - " temp
HiddenWins--
if(HiddenWins = 0)
{
Menu, ShowMenu, DeleteAll
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
}
else
Menu, ShowMenu, Delete, %MenuTitle%
return
; Hide Active Window
#h::
WinGet, WinID, ID, A
WinGetClass, WinClass, A
WinGetTitle, WinTitle, A
; Don't make Transparent those special Windows
if(WinID = "" || WinClass = "Progman" || WinClass = "Shell_TrayWnd" || WinClass = "WorkerW")
return
HiddenWins++
All%HiddenWins% := WinID
if(HiddenWins = 1)
Menu, Tray, Add, UnHide All, UnHideAll
Menu, ShowMenu, Add, % WinTitle " - " WinID, ShowWin
Menu, Tray, Add, UnHide Windows, :ShowMenu
PostMessage, 0x112, 0xF020,,, A ; minimize to get focus on the other window
WinHide, ahk_id %WinID%
return
; Menu for Showing Hidden windows
ShowWin:
StringRight, temp, A_ThisMenuItem, 8
WinShow, ahk_id %temp%
PostMessage, 0x112, 0xF120,,, ahk_id %temp% ; restore
HiddenWins--
if(HiddenWins = 0)
{
Menu, ShowMenu, DeleteAll
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
}
else
Menu, ShowMenu, Delete, %A_ThisMenuItem%
return
; UnHide all Hidden Windows
UnHideAll:
Loop, %HiddenWins%
{
temp := All%A_Index%
WinShow, ahk_id %temp%
PostMessage, 0x112, 0xF120,,, ahk_id %temp% ; restore
}
HiddenWins := 0
Menu, ShowMenu, DeleteAll
Menu, Tray, Delete, UnHide All
Menu, Tray, Delete, UnHide Windows
return
|
_________________ One hotkey to rule them all! |
|
| Back to top |
|
 |
XavierGr
Joined: 15 Jul 2006 Posts: 48
|
Posted: Wed Nov 07, 2007 3:47 am Post subject: |
|
|
Oops my last post had some bugs, I edited it and I hope that it won't have more. At this point it seems pretty stable. _________________ One hotkey to rule them all! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|