AutoHotkey Community

It is currently May 25th, 2012, 8:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Tray Menu misbehavior
PostPosted: November 6th, 2007, 11:27 pm 
Offline

Joined: July 15th, 2006, 1:30 am
Posts: 48
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2007, 1:22 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2007, 2:12 am 
Offline

Joined: July 15th, 2006, 1:30 am
Posts: 48
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2007, 4:47 am 
Offline

Joined: July 15th, 2006, 1:30 am
Posts: 48
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!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, krajan, MilesAhead, Rathgar2, rbrtryn, Tegno, vsub and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group