@lexikos Thank you.
But the fact remains that we still need to use "try" a lot.
The "try" is a bigger hazard than the "window exists or not".
I was wondering if you use the window command a lot?
------
Yes, I only need wingettitle() to return "" or the title.
In 99% of cases, I don't need to care if the window exists, I just need to know if I'm getting a title with content.
Maybe 1% of the time I need to know if the window is there or not, then I will use WinExist()
Is this use not allowed?
Or would this be seen as blasphemy against the rigour of V2?
It's hard to imagine that I now mainly use my own wrapped WIN commands. I'm afraid to use the built-in command, I'm afraid of its pop-ups, to me it's as pointless as an advertisement.
Code: Select all
win_gettitle(hwnd) {
static buf := buffer(512, 0)
if sz := DllCall("GetWindowTextW", "Ptr", hwnd, "Ptr", buf.ptr, "uint", 512)
return StrGet(buf.ptr, sz, "utf-16")
}
Perhaps because of my poor programming skills, when I look at my modified V2 code, I find it very ugly.
Code: Select all
aid := WinExist("A"), id:=""
try
name:=WinGetProcessName(aid)
catch
name:=""
if InStr("\Chrome.exe\Opera.exe\firefox.exe\vivaldi.exe\msedge.exe\", "\" name "\")
id := aid
else
{
mode := A_TitleMatchMode
SetTitleMatchMode "RegEx"
try id := WinGetID("ahk_exe i)\\(chrome.exe|opera.exe|firefox.exe|vivaldi.exe|msedge.exe)$")
SetTitleMatchMode mode
}
if id
{
try path := wingetProcessPath(id)
try pid := WinGetpid(id)
}