 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
maxand
Joined: 03 Apr 2009 Posts: 99
|
Posted: Thu Jan 14, 2010 12:17 pm Post subject: Confused about WinShow vs WinActivate |
|
|
An application with a main window winA generates a small popup window winB each time a particular function Func is activated. The small window is not often needed and I would like it to be hidden unless I am actually using it. But sometimes I need to unhide it. And I also need to close it. So I wrote a set of 3 macros, using hotkeys F1,F2,F3:
| Code: | #IfWinActive ;No matter which window is on top
F1:: Perform Func and allow winB to be on top, i.e., visible
DetectHiddenWindows, On ;Off by default
IfWinExist, winB ;If winB window already exists (means Func is already running)
;IF winB ALREADY EXISTS AND IS VISIBLE, I SHOULDN'T HAVE TO
;WASTE TIME BY RUNNING THE NEXT LINE!
WinShow, winB ;Unhide window
Else ;winB window needs to be created
Gosub, RunFunc ;Includes creating winB
DetectHiddenWindows, Off
Return
;----------------
#IfWinActive ;No matter which window is on top
F2:: ;Perform Func but hide winB
DetectHiddenWindows, On ;Off by default
IfWinNotExist, winB ;First create winB, then hide it
{
IfWinNotActive, winA
{
WinActivate, winA ;Main Window must be active
WinWaitActive, winA
}
Gosub, RunFunc ;Includes creating winB
WinWaitActive, winB
}
WinHide, winB ;Hide window
DetectHiddenWindows, Off
Return
;----------------
F3:: Kill winB when finished
DetectHiddenWindows, On
IfWinExist, winB
WinClose, winB
DetectHiddenWindows, Off
Return
RunFunc: ;Activate app's Func function which also creates popup winB
;some code
Return |
The real version of this code works quite well, but I'm always trying to make it as rigorous as possible, hence this problem.
I can't find any simple way in AHK to ascertain whether a window which exists is hidden or not. In this example, I don't need to unhide it if I know it exists and it's on top. All I should need to do is use WinActivate, maybe, instead of WinShow. Can someone explain the difference between them and also suggest a way of determining whether a window is hidden so that I don't have to WinShow it if there's no need.
The only solution I've found here in the forum is
http://www.autohotkey.com/forum/topic3135.html
but it looks too complex and I'm not sure how I'd fit it into my code.
Thanks for any assistance. |
|
| Back to top |
|
 |
Peter
Joined: 30 Dec 2005 Posts: 448
|
Posted: Thu Jan 14, 2010 3:39 pm Post subject: |
|
|
| maxand wrote: | | Can someone explain the difference between them... | WinShow: makes a hidden window visible for the user (Likely it gets activated at the same time.). A hidden window isn't accessible in any way by the user.
WinActivate: puts the window at the front, so it gets focus and it's all visible for the user. The user could have done it him/herself by clicking on the taskbar button, Alt-Tab key, or other ways.
| maxand wrote: | | The only solution I've found here in the forum is ... but it looks too complex and I'm not sure how I'd fit it into my code. | You have to make yourself familiar with Functions. E.g. | Code: | if WinExist("winB") and IsWindowVisible("winB")
msgbox winB exists and is visible
IsWindowVisible(p_WindowTitle)
{
WinGet, Style, Style, % p_WindowTitle
Transform, IsVisible, BitAnd, %Style%, 0x10000000 ; 0x10000000 is WS_VISIBLE.
return IsVisible
} |
|
|
| Back to top |
|
 |
maxand
Joined: 03 Apr 2009 Posts: 99
|
Posted: Fri Jan 15, 2010 1:33 am Post subject: |
|
|
| Thanks Peter - very helpful reply! |
|
| Back to top |
|
 |
jl34567
Joined: 03 Jan 2010 Posts: 262
|
Posted: Fri Jan 15, 2010 8:04 pm Post subject: |
|
|
Not sure if this is what you're looking for, but Leef_me posted this in another thread yesterday.
Check out the WinGetState line.
By "hidden" I'm not sure if you mean minimized. If that's what you mean, check out the WinGet, WinState line.
You may want to check out the WinMinimize/WinMaximize functions.
| Code: |
#SingleInstance Force
SetTitleMatchMode, 2
WinName=Untitled - Notepad
;WinName=%A_ScriptName%
return
f1::
; msgbox before test
IfWinExist, %WinName%
{
; msgbox window %WinName% exists
WinGet, WinState, MinMax
; msgbox %WinName%
if (WinState = -1)
WinRestore
else
{
; WinRestore
WinMinimize
}
}
else
msgbox window %WinName% could not be found
return |
|
|
| 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
|