我有一个gui可以帮助我自动化某些事情,但只有特定程序中的某些东西。我希望我的GUI在我使用它的程序不活动时最小化自己,并且当我再次激活该窗口时能够最大化自己。任何帮助表示赞赏。还要记住,我对此很新!感谢。
While 1
Sleep(100)
If WinActive("My Program") Then
WinSetState("My GUI", "", @SW_RESTORE)
WinSetOnTop("My GUI","",1)
Else
WinSetState("My GUI", "", @SW_MINIMIZE)
Endif
Switch $nMsg
Case $button1
function()
Case $button2
function()
EndSwitch
Wend
答案 0 :(得分:2)
看起来您的代码会不断设置您的GUI,并最小化您的程序是否处于活动状态。这可能会有所帮助:
Global $ghActive
Global $ghMyProgram = WinGetHandle("My Program")
; if you're not already using a global handle for your gui
Global $ghMyGUI = WinGetHandle("My GUI")
While 1
Sleep(100)
$ghActive = WinGetHandle("[ACTIVE]")
If $ghActive = $ghMyProgram Then
WinSetState($ghMyGUI, "", @SW_RESTORE)
WinSetOnTop($ghMyGUI, "", 1)
ElseIf $ghActive <> $ghMyGUI And $ghActive <> $ghMyProgram Then
WinSetOnTop($ghMyGUI, "", 0)
WinSetState($ghMyGUI, "", @SW_MINIMIZE)
EndIf
Switch $nMsg
Case $button1
function()
Case $button2
function()
EndSwitch
WEnd