本文介绍了Autohotkey-如何将GUI链接到窗口以与其父窗口相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将GUI链接到某个窗口,因此它的作用就像是它的一部分.

I would like to link a GUI to a certain window, so it could act like it's a part of it.

这是我的GUI,我希望它遵循计算器(进行测试).如果将计算器最小化,则gui也将最小化.

This is my GUI and I would like it to follow the Calculator (for testing). If the calculator is minimized, the gui would be minimized as well.

提前谢谢!

#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

推荐答案

我最终得到了两个脚本.也许可以稍后再组合.

I ended up with two scripts. Maybe this can be combined later.

一个脚本用于ToolMenu,第二个脚本用于激活.由于无法通过激活脚本控制GUI(显示/隐藏),因此我使用 + + +解决了"它和 + + + .不是最优雅的方式,但是可以...

One script is for the ToolMenu, the second for the activation.Since I could not control the GUI, Show/Hide from the Activation script, I "solved" it by using +++ and +++.Not the most elegant way, but it works...

#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

让我知道它是如何工作的...

Let me know how this works...

这篇关于Autohotkey-如何将GUI链接到窗口以与其父窗口相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:10