2013-03-02 55 views
0

我想将GUI链接到某个窗口,因此它可以像它的一部分那样操作。Autohotkey - 如何将GUI链接到窗口以与其父窗口相同

这是我的GUI,我希望它遵循计算器(用于测试)。如果计算器最小化,gui也会被最小化。

在此先感谢!

#SingleInstance Force 
#Persistent 

BC = 0 

Gui, Color, EEAA99 
Gui, Margin , 0, 0 
GUI, +AlwaysOnTop -Border -SysMenu -Caption +ToolWindow +Owner 
Gui, Font, S48 CDefault Bold CBlue, Verdana 
Gui, Add, Text, BackgroundTrans , Units completed: 
Gui, Font, S72 CDefault Bold CGreen, Verdana 
Gui, Add, Text, BackgroundTrans vBuildCounter, %BC% 
WinSet, TransColor, EEAA99 
Gui +LastFound +AlwaysOnTop +ToolWindow 
WinSet, TransColor, EEAA99 
Gui -Caption 
Gui, Show, % "x" A_ScreenWidth - 400 " y" A_ScreenHeight/4 

:?*:asd:: ;count up 
    SoundBeep, 500,500 
    BC := BC += 1 
    GuiControl,, BuildCounter, %BC% 
Return 

:?*:qwe:: ;reset the counter 
    SoundBeep, 500,500 
    BC := 0 
    GuiControl,, BuildCounter, %BC% 
Return 

Esc:: 
ExitApp 

回答

0

我结束了两个脚本。也许这可以在以后结合使用。

一个脚本用于ToolMenu,第二个用于激活。 因为我无法控制的GUI,从激活脚本显示/隐藏,我用按Ctrl + Alt键 + + F1按Ctrl + Alt键 + 赢 “解决” 它 + F2。不是最优雅的方式,但它的作品...

ToolMenu.ahk

#SingleInstance Force 
#installKeybdHook 
#Persistent 

Gui, Destroy 
Gui,+AlwaysOnTop 
Gui,+ToolWindow 
Gui,+Border 
Gui, Add, Button, y5 w60, &LowBeep 
Gui, Add, Button, y5 w60, &HighBeep 
Gui, Add, Button, y8 h18, X 
Gui, Show, y0, MyToolWindow 
Return 

ButtonLowBeep: 
    SoundBeep, 300, 300 
Return 

ButtonHighBeep: 
    SoundBeep, 500, 300 
Return 

ButtonX: 
ButtonCancel: 
    Gui, Destroy 
ExitApp 

^!#F1:: 
    Gui, Hide 
Return 

^!#F2:: 
    Gui, Show, y0, MyToolWindow 
Return 

DetectWindowChange.ahk

#SingleInstance 
#installKeybdHook 
#Persistent 
Global SwitchCounter 

Gui +LastFound 
hWnd := WinExist() 
DllCall("RegisterShellHookWindow", UInt,Hwnd) 
MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK") 
OnMessage(MsgNum, "ShellMessage") 
Return 

ShellMessage(wParam) 
{ 
    If (wParam = 4) 
    { 
     WinGetTitle, CurrName, A 
     If (CurrName = "Calculator" OR CurrName = "MyToolWindow") 
     { 
      If (SwitchCounter = 0) 
      { 
       ;WinRestore, MyToolWindow 
       Send, ^!#{F2} ; Send Ctrl+Alt+Win+F2 to trigger GUI Show in GUI script 
      } 
      SwitchCounter += 1 
     } 
     Else 
     { 
      If (SwitchCounter > 0) 
      { 
       ;WinMinimize, MyToolWindow 
       Send, ^!#{F1} ; Send Ctrl+Alt+Win+F1 to trigger GUI Hide in GUI script 
      } 
      SwitchCounter := 0 
     } 
    } 
} 
Return 

让我知道这是如何工作...

+0

有趣的:)它确实工作,我明天会玩它。再次感谢! :) – Ismo 2013-03-03 19:47:45

+0

请提供有关建议解决方案的一些反馈,如果答案有帮助,请点击白色复选标记以将其变为绿色,以便“接受”该答案。谢谢! – 2013-03-06 11:43:08

+0

请点击答案旁边的白色“复选标记”,将其“接受”给定的答案,将其变为绿色。谢谢!请参阅:[接受答案](http://meta.stackexchange.com/a/5235/210367) – 2013-03-09 19:10:03

0

你可以(据我所知)只用settimer来做这件事。

伪代码,未测试!

SetTitleMatchMode := 2 
SetTimer, CheckWindow, 200 

CheckWindow: 
    IfWinActive, Calculator 
    { 
     Gui, Show, % "x" A_ScreenWidth - 400 " y" A_ScreenHeight/4 
    } 
    Else 
    } 
     GUI, Hide 
    { 
Return 
+0

我使用AutoHotKey_L。我也看到了像Set_parent_by_title这样的东西,但我无法使它工作。 :/ – Ismo 2013-03-02 21:13:19

+0

只是将最小化改为GUI,隐藏或GUI,显示 – 2013-03-02 21:42:36

+0

据我所知,#IF无法运行脚本。 – 2013-03-02 21:46:13