2013-03-02 49 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

相關問題