My apologies for the late update, but I've provided now the screenshot and additional details to clear things out.
- image.png (350.59 KiB) Viewed 1816 times
The truth is I haven't really tried using
WinExist because I thought
WinGetList and
WinExist uses the same underlying process. Anyways, I've decided to try it.
#Requires AutoHotkey v2.0
DetectHiddenWindows True
DetectHiddenText True
; WinExist("Microsoft To Do")
; WinExist("ahk_class ApplicationFrameWindow")
; WinExist("ahk_exe ApplicationFrameHost.exe")
WinExist("ahk_pid " 4204)
WinExist("ahk_id " 4653868)
Although the only way it detected the window is by providing the
pid (process id) or
id (hwnd), which is very hard to get.
These are all the ways I tried just to find it (and only one did work but was barely viable):
1. WinExist (Code above) - [Didn't work]
- using the ahk_class and ahk_exe didn't detected it.
2. Listing all the processes and checking each if they matched the ProcessName - [Didn't work]
- since each process can contain multiple windows, therefore, multiple hwnd can lie in a single process (also I don't know how to recover the hwnd from a process)
Code: Select all
MyGui := Gui(, "Process List")
LV := MyGui.Add("ListView", "x2 y0 w400 h500", ["HWND", "Process Name","Command Line"])
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process") {
LV.Add("", process.Handle, process.Name, process.CommandLine)
if process.Name == "Todo.exe" {
MsgBox "Todo process Id: " process.ProcessId
return process.ProcessId
}
}
MyGui.Show()
3. Iterate literally every window possible just to find it - [Didn't work]
- using a recursive function to iterate to every window/child window returned by
EnumWindows and
EnumChildWindows
Code: Select all
MyGui := Gui()
Lv := MyGui.Add("ListView", "h700 w600",["HWND", "Process Name"])
MyGui.Show()
DllCall("EnumWindows", "ptr", callbackCreate(EnumWindows, "F"), "uint", 0)
EnumChildWindows(hwnd) {
try {
pn := WinGetProcessName(hwnd)
} catch { ; incase of access error
return True
}
DllCall("EnumChildWindows", "ptr", hwnd, "ptr", callbackCreate(EnumChildWindows, "F"), "uint", 0)
Lv.add("", hwnd, pn)
if pn == "Todo.exe" {
MsgBox "Match!!"
}
return True
}
EnumWindows(hwnd) {
try {
pn := WinGetProcessName(hwnd)
} catch { ; incase of access error
return True
}
if pn == "ApplicationFrameHost.exe" {
DllCall("EnumChildWindows", "ptr", hwnd, "ptr", callbackCreate(EnumChildWindows, "F"), "uint", 0)
Lv.add("", hwnd, pn)
}
if pn == "Todo.exe" {
MsgBox "Match!!"
}
return True
}
4. Using "WindowsFromPoint" to get the hwnd of a window from a certain coordinate - [Kinda works]
- it's working, but with a major downside which is the requirement of window to be the topmost. Meaning I can't get the hwnd of a window if it's hidden, not in a certain position, or minimized.
Code: Select all
x := 1150
y := 300
hWnd := DllCall("WindowFromPoint", "UInt64", x|(y << 32), "Ptr")
MsgBox WinGetTitle(hWnd) " : " hWnd " : "
WinExist(hWnd)