WinActive / WinHide issue

Report problems with documented functionality
citytrader
Posts: 4
Joined: 27 Apr 2014, 12:25

WinActive / WinHide issue

28 Apr 2014, 10:06

Hello to all, I have found an issue with WinActive/WinHide that I dont know if its normal, I made an script for Totalcomander ( it hides the windows with ctrl-alt-s if its active, if you press again ctrl-alt-s it will restore the windows from the tray) that works mostly fine except for WinHide that do it job hidding Totalcommander but after done that seems WinActive is getting that the windows is active when was hidden, so after you hidden the windows, the script will not work as expected except I do alt-tab once.
I found a caveat to solve this issue is to add "minimize" function before doing the WinHide and in this way the function is working as it should.

Anyone could help me about this if its a bug or something I'm doing wrong in Autohotkey 1.1.14.04?

Code: Select all

;--TOTALCOMMANDER

^!s::
F_HIDE_SHOW("TTOTAL_CMD","E:\D\totalcmd\TOTALCMD64.EXE")
return


F_HIDE_SHOW(PRG,PATH)
{
If WinExist("ahk_class " . PRG)
{
	{
		If WinActive("ahk_class " . PRG)
			{
			 WinGetTitle, TheWinTitle, ahk_class %PRG%
			 menu, tray, Tip, %TheWinTitle%
			 menu, tray, add, %PRG%
			 WinMinimize; /////////////////   I add this function for solving the issue with WinActive/WinHide
			 WinHide, ahk_class %PRG%
			 return
			 }
			 else
				{
			 WinGet, WinStat, MinMax, ahk_class %PRG%
			 If (WinStat = -1)
				{
				 WinRestore, ahk_class %PRG%
				 WinActivate, ahk_class %PRG%
				}
				 else
				{
				 menu, tray, UseErrorLevel
				 menu, tray, Delete, %PRG%
				 WinShow, ahk_class %PRG%
				 WinActivate, ahk_class %PRG%
				}
			}
	}
}
else
{
 Run %PATH%
 WinActivate, ahk_class %PRG%
}
}
citytrader
Posts: 4
Joined: 27 Apr 2014, 12:25

Re: WinActive / WinHide issue

29 Apr 2014, 19:15

HotKeyIt wrote:Try WinWait after WinShow.
Hello, I dont understand what do you mean, because the problems is here:

If WinActive("ahk_class " . PRG)
{
WinGetTitle, TheWinTitle, ahk_class %PRG%
menu, tray, Tip, %TheWinTitle%
menu, tray, add, %PRG%
WinMinimize; ///////////////// I add this function for solving the issue with WinActive/WinHide
WinHide, ahk_class %PRG%
return
}


I think I found the bug, when you apply the WinHide command, the windows goes hidden but WinActive return a result as the windows is active, If I do alt-tab, the issue is gone.
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinActive / WinHide issue

29 Apr 2014, 21:36

That's not a bug. WinHide just hides the window; it doesn't activate some other window. Hidden windows can be active. However, you must have used DetectHiddenWindows On.

WinMinimize doesn't activate some other window either; it just tells the system to minimize the window, and the system does the rest.
citytrader
Posts: 4
Joined: 27 Apr 2014, 12:25

Re: WinActive / WinHide issue

29 Apr 2014, 21:53

lexikos wrote:That's not a bug. WinHide just hides the window; it doesn't activate some other window. Hidden windows can be active. However, you must have used DetectHiddenWindows On.

WinMinimize doesn't activate some other window either; it just tells the system to minimize the window, and the system does the rest.

I had user "DetectHiddenWindows On" in the header of the main script.
At this point the question is, when I hide the windows, how I detect if it is hidden!?... because I'm using the hotkey ctrl-s to show Totalcommander and to hide it.

Without the minimize command, this is the behaviour of the script.

TC is active, so I do ctrl-s and it goes hidden
if I press ctrl-s again, it does not work as it should because its not recognized as hidden.
if I click on the desktop or do ctrl-tab, then ctrl-s works and shows again TC

With the minimize command added.
TC is active, so I do ctrl-s and it goes hidden
if I press ctrl-s again, TC shows without any issue, I dont need to click the desktop or do ctrl-tab


Sorry to insist but I find some difficulty to understand this behaviour of winhide, am I doing something wrong?
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinActive / WinHide issue

30 Apr 2014, 02:37

At this point the question is, when I hide the windows, how I detect if it is hidden!?
Your question is ambiguous.
To detect a window which is hidden, use DetectHiddenWindows On. Just don't use it in the auto-execute section; use it only when and where you need it.
To detect whether a window is hidden or not, use DetectHiddenWindows Off (the default setting) and WinExist/WinActive. If the function returns 0, the window is either hidden or does not exist. You can combine this with DetectHiddenWindows On - if WinExist returns 0 when the setting is Off but not when the setting is On, the window exists but is hidden.
I'm using the hotkey ctrl-s to show Totalcommander and to hide it.
WinShow is only useful when operating on a hidden window, so does not care about the DetectHiddenWindows setting. If your hotkey just uses WinHide, you don't need DetectHiddenWindows On.
Sorry to insist but I find some difficulty to understand this behaviour of winhide, am I doing something wrong?
Does it not hide the window? What more do you expect? If you are expecting the behaviour to match what happens when you manually minimize a window, then continue to use WinMinimize.
citytrader
Posts: 4
Joined: 27 Apr 2014, 12:25

Re: WinActive / WinHide issue

02 May 2014, 00:36

lexikos wrote:
At this point the question is, when I hide the windows, how I detect if it is hidden!?
Your question is ambiguous.
To detect a window which is hidden, use DetectHiddenWindows On. Just don't use it in the auto-execute section; use it only when and where you need it.
To detect whether a window is hidden or not, use DetectHiddenWindows Off (the default setting) and WinExist/WinActive. If the function returns 0, the window is either hidden or does not exist. You can combine this with DetectHiddenWindows On - if WinExist returns 0 when the setting is Off but not when the setting is On, the window exists but is hidden.
I'm using the hotkey ctrl-s to show Totalcommander and to hide it.
WinShow is only useful when operating on a hidden window, so does not care about the DetectHiddenWindows setting. If your hotkey just uses WinHide, you don't need DetectHiddenWindows On.
Sorry to insist but I find some difficulty to understand this behaviour of winhide, am I doing something wrong?
Does it not hide the window? What more do you expect? If you are expecting the behaviour to match what happens when you manually minimize a window, then continue to use WinMinimize.

Thanks for your time, now I have understood the concept, you can erase this post because its not bug!

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 54 guests