what i am trying to do is instead of force closing and starting the new instance , just winrestore old instance gui
any idea ?
Code: Select all
#SingleInstance off ;cant use single instance force because it will show couldnt close previous instance message
KillOtherInstances() ; this is what i do now to close the previous instance
Gui, Add, Button , w200 h40 gShowHide , Show/Hide
Gui,show,,testtitle
return
F10::
ShowHide:
toggle:=!toggle
if toggle
Gui, Hide
Else
Gui, show
Return
KillOtherInstances() { ; Kill All other Script.ahk -or- Script.exe instances. Requires: AhkL, #SingleInstance OFF
cPID:=DllCall("GetCurrentProcessId"), cName:=A_IsCompiled ? A_ScriptName : ComObjGet("winmgmts:")
.ExecQuery("Select * from Win32_Process Where " cPID "=ProcessId")._NewEnum()[cPInf] ? cPInf.Name :"" ;AppNane|AutoHotkey.exe
FOR proc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
IF (proc.Name = cName) && (proc.ProcessID != cPID) && (A_IsCompiled ? True : InStr(proc.CommandLine, A_ScriptFullPath))
Process, close, % proc.ProcessID
}
GuiClose:
ExitApp