WinSetTitle breaks #SingleInstance Force

Report problems with documented functionality
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

WinSetTitle breaks #SingleInstance Force

26 Sep 2017, 01:07

Renaming the script's own window, even to the same name it's normally given by AHK, causes #SingleInstance Force to no longer work

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv
SetBatchLines -1
DetectHiddenWindows On
WinSetTitle ,% "ahk_id " A_ScriptHwnd ,,MyScript.ahk - AutoHotkey v1.1.24.03
Return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinSetTitle breaks #SingleInstance Force

26 Sep 2017, 06:31

If you change it to exactly the same title, #SingleInstance force still appears to work, but yes, in the general case, this is very surprising.

Code: Select all

#SingleInstance force
#Persistent
#NoEnv
SetBatchLines, -1
DetectHiddenWindows, On
WinGetTitle, vWinTitle, % "ahk_id " A_ScriptHwnd
WinSetTitle , % "ahk_id " A_ScriptHwnd,, % vWinTitle "x" ;modify title
Sleep 1000
WinSetTitle , % "ahk_id " A_ScriptHwnd,, % vWinTitle ;restore title
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: WinSetTitle breaks #SingleInstance Force

26 Sep 2017, 08:10

To determine if a script is already running AHK is searching for windows of class AutoHotkey (hidden main window) with exactly the same title the new main window would get on creation. This is actually a rather simple method but has been sufficient for many years. Apparently, nobody using #SingleInstance, Force had a reason to change the main window's title as yet.

We could add something like
You must not change the title of the script's hidden main window if you want to prevent new instances of the script from being launched.
to the docs.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 18 guests