Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

AutoHotkey: WinHide & WinShow by class and by process

Hello experts,
I set up the following AutoHotkey to hide and show windows by class.
I took as a reference the AutoHotkey reported at https://www.experts-exchange.com/questions/29159194/AutoHotkey-WinHide.html#a42949009
:?*:hhx::
HideClass:="Chrome_WidgetWin_1" ; title must contain this - case insensitive
WinGet,AllWindows,List ; get list of all windows that exist
NumWin:=AllWindows ; number of all windows
NumHidden:=0 ; number of windows hidden
Loop,%NumWin% ; loop through all windows
{
  Handle:=AllWindows%A_Index% ; get the handle of each window
  WinGetClass,Class,ahk_id %Handle% ; get the class of each window
  If (InStr(Class,HideClass)) ; "contains" match and case insensitive
  {
    WinHide, ahk_class %Class% ; hide the window if it matches
    NumHidden:=NumHidden+1 ; increment number of windows hidden
  }
}
MsgBox,4160,Number Hidden: %NumHidden%,Done hiding windows that contain this in the Class:`n`n%HideClass%
Return

:?*:ssx::
DetectHiddenWindows,On ; so that WinGet finds the hidden windows
ShowClass:="Chrome_WidgetWin_1" ; Class must contain this - case insensitive
WinGet,AllWindows,List ; get list of all windows that exist
NumWin:=AllWindows ; number of all windows
NumShown:=0 ; number of windows shown
Loop,%NumWin% ; loop through all windows
{
  Handle:=AllWindows%A_Index% ; get the handle of each window
  WinGetClass,Class,ahk_id %Handle% ; get the class of each window
  If (InStr(Class,ShowClass)) ; "contains" match and case insensitive
  {
    WinShow, ahk_class %Class% ; show the window if it matches
    NumShown:=NumShown+1 ; increment number of windows shown
  }
}
MsgBox,4160,Number Shown: %NumShown%,Done showing windows that contain this in the class:`n`n%ShowClass%
Return

Open in new window


I am trying to understand without success why:
1-WinHide works when I report class of Chrome and class of Notepad++
2-WinShow doesn't work when I report class of Chrome but it works when I report class of Notepad++

I would also like to remove the instr formula in order to have exact match.

Once I finalized the class approach I would like to have the process approach. If you have advice on this approach, please let me know.

Thank you for your help.
SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Helllo Joe,
Thank you for your feedback.
I am still getting some issues with the showing windows by class. As recommended I tested multiple times to show the hidden windows without success. In fact when they are more than 1 hidden windows I am not able to show them.
I attached my video.
Thank you for your help.
Hide-show-windows-by-class_20190927_1.7z
Joe,
I also made a test by process and also having some issues with the show mode.
Please find attached the video.

Thank you for your help.
Hide-show-windows-by-process_20190927.7z
I made the test with the following AutoHotkey:
:?*:hhx::
HideProcess:="notepad++.exe" ; title must contain this - case insensitive
WinGet,AllWindows,List ; get list of all windows that exist
NumWin:=AllWindows ; number of all windows
NumHidden:=0 ; number of windows hidden
Loop,%NumWin% ; loop through all windows
{
  Handle:=AllWindows%A_Index% ; get the handle of each window
  WinGet,Process,ProcessName,ahk_id %Handle% ; get the process of each window
  If (Process=HideProcess) ; "contains" match and case insensitive
  {
    WinHide,ahk_exe %Process% ; hide the window if it matches
    NumHidden:=NumHidden+1 ; increment number of windows hidden
  }
}
MsgBox,4160,Number Hidden: %NumHidden%,Done hiding windows that contain this in the Process:`n`n%HideProcess%
Return

:?*:ssx::
DetectHiddenWindows,On ; so that WinGet finds the hidden windows
ShowProcess:="notepad++.exe"
WinGet,AllWindows,List ; get list of all windows that exist
NumWin:=AllWindows ; number of all windows
NumShown:=0 ; number of windows shown
Loop,%NumWin% ; loop through all windows
{
  Handle:=AllWindows%A_Index% ; get the handle of each window
  WinGet,Process,ProcessName,ahk_id %Handle% ; get the process of each window
  If (Process=ShowProcess)
  {
    WinShow,ahk_exe %Process% ; show the window if it matches
    NumShown:=NumShown+1 ; increment number of windows hidden
  }
}
MsgBox,4160,Number shown: %NumShown%,Done hiding windows that contain this in the Process:`n`n%ShowProcess%
Return

Open in new window

Hi Luis,
So, you're having some issues. What is your approach to troubleshooting/debugging the script? Your thoughts...ideas...methods...for figuring out what the problems are? Regards, Joe
Hi Joe,
I attached some videos in my previous comments.
I try to execute the show windows hotsring multiple times without success.
I also tested with different process: Notepad++ and chrome.
> I attached some videos in my previous comments.

I haven't looked at them yet, but I presume that they simply show that the script doesn't work...that, as you said, you are having some issues.

> I try to execute the show windows hotsring multiple times without success.

OK, you did more testing of the script...it is not working.

> I also tested with different process: Notepad++ and chrome.

More testing...that's good...you've definitely shown that it isn't working. Now, the important question...why? What are your thoughts/ideas on debugging the script? What's the next step?
Hi Luis,
A question that I meant to ask at your first WinHide thread, so I'll ask it here. Are you posting these WinHide/WinShow questions for educational purposes, i.e., just to learn about it, or do you have a real-world usage for it? The reason I ask is that in almost 10 years of using AutoHotkey, I've never had a need for WinHide/WinShow, so I'm curious what your reason is for asking about it...if it's a real-world purpose, I'd love to know what it is. Regards, Joe
Hi Joe,

I posted WinHide/WinShow question just to learn. After asking and reading documentation about WinGet, WinExist, WinActive, WinMaximize, WinMinimize, I was wondering how to properly manage WinHide/WinShow mechanism.
Joe,

Concerning your previous comment:
What are your thoughts/ideas on debugging the script? What's the next step?
I would like to show  every windows that has been previously hidden. By doing so I can check if there is an issue with the loop set up.
I found the following AutoHotkey file which manage WinHide & WinShow with same variable: WinID
https://autohotkey.com/board/topic/8354-how-to-hide-unhide-windows/

hiddenWindowNumber = 0
#End::
   hiddenWindowNumber++
   WinGet winID, ID, A
   WinHide A
   hiddenWindow%hiddenWindowNumber% := winID
Return

#Home::
   ; Show all hidden windows
   ; You can also create a menu (for example) listing the windows
   ; allowing you to choose a specific window to unhide
   Loop %hiddenWindowNumber%
   {
      winID := hiddenWindow%A_Index%
      WinShow ahk_id %winID%
   }
Return

Open in new window


I tested and it works when I execute the first AutoHotkey and right after the second AutoHotkey.  I think that using the same winID is a good idea because we want to show every windows that has been previously hidden.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Joe,

Thank you very much for this useful script and also very glad that we had the same thought!
I got the following result:

-Number of windows: 288   DetectHiddenWindows=On
-Number of windows: 27   DetectHiddenWindows=Off

Two questions came across:
1-The number of windows opened affect the performance of my OS?
2-Is there a way to force the closing of the various number of windows in particular when DetectHiddenWindows is On? I don't ask for DetectHiddenWindows is Off as I supposed when you force the system shutdown all process are closed and as a result the respective windows too.

If I am able to force the various closing windows I will retest winshow approach on the basis of the previous script to see if I am able to properly show the various windows.

Thank you in advance for your feedback.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok. Thank you for your advice.
You're welcome.