Say I have the Windows Calculator open, and a folder named Calculator open. Now, assume I want to get the hWnd of the Windows Calculator. FindWindow_() alone is no good, because it matches both windows. So, I do additional check of the window's class and lcase(getfilepart(executable)), which is much better, and works quite well.
My question is: are those 3 properties enough to uniquely ID a window? Caption, class, executable? I can't use size or position, because the user can change those. Can anyone think of anything else that may be useful? Thanks!
Uniquely ID a window?
Re: Uniquely ID a window?
Technically, even those might not be quite sufficient. In the unlikely event that there's another application with the same name, the class and executable name would still match. Of course, the path (system32) could be another determiner, but unless the process is launched by our application, other approaches would not really be bulletproof.Dude wrote:Say I have the Windows Calculator open, and a folder named Calculator open. Now, assume I want to get the hWnd of the Windows Calculator. FindWindow_() alone is no good, because it matches both windows. So, I do additional check of the window's class and lcase(getfilepart(executable)), which is much better, and works quite well.
Just an opinion, though.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Uniquely ID a window?
I know, hence why I'm asking if there's anything else that could be used.TI-994A wrote:even those might not be quite sufficient
Actually, now that I think about it, I could also use styles like if the window is resizable, is tool style, has a max or min button, etc.
No, tried that, and it fails because of "System32" vs "SysWow64"; that is, you don't know which path the system will use. I had this problem with Calc.exe and Notepad.exe, for example. It was reporting that Calculator didn't match, until I realized it was because one calc.exe had instance launched with "System32" and the other was with "SysWow64". So, not reliable, and hence why I use just the GetFilePart() instead. Also, sometimes the user might launch the same app/window from the same exe but from the exe being copied to two different folders, so another reason to ignore the path.TI-994A wrote:the path (system32) could be another determiner
Re: Uniquely ID a window?
Exactly; not bulletproof.Dude wrote:I know, hence why I'm asking if there's anything else that could be used.TI-994A wrote:even those might not be quite sufficient
Actually, now that I think about it, I could also use styles like if the window is resizable, has a max or min button, etc.
No, tried that, and it fails because of "System32" vs "SysWow64"; that is, you don't know which path the system will use. I had this problem with Calc.exe and Notepad.exe, for example. It was reporting that Calculator didn't match, until I realized it was because one calc.exe had instance launched with "System32" and the other was with "SysWow64". So, not reliable, and hence why I use just the GetFilePart() instead. Also, sometimes the user might launch the same app/window from the same exe but from the exe being copied to two different folders, so another reason to ignore the path.TI-994A wrote:the path (system32) could be another determiner
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Uniquely ID a window?
Using the caption, class, lower-case exe name (without path), and window styles (sizable? tool window? max button?) seems to work best. I also tried using things like GetParent_() and GetWindow_(..#GW_CHILD) but they failed by changing, probably because the OS changes them. So don't use those. Just putting this info here for future reference.
Re: Uniquely ID a window?
Code: Select all
hWnd = FindWindow_(#Null,"Calculator") ;<- you might also want to be more specific by specifying the Class
pid = GetWindowThreadProcessId_(hWnd)
;// If LCase(GetPathFromPid(pid)) = LCase(WindowsDirectory & "\system32\calc.exe") ;need to check syswow64 too
If LCase(GetFilePart(GetPathFromPid(pid))) = "calc.exe" ;or maybe filename alone is suffice
;confirmed it's Windows calc.exe and not Explorer window looking at C:\Calculator\ folder
EndIf
Re: Uniquely ID a window?
@Dude
you wont find a window named "Calculator" on a foreign os.
i would browse the list of all running processes and check if the exes name and location match the one im looking for.
>> it fails because of "System32" vs "SysWow64"; that is, you don't know which path the system will use.
%SystemRoot%\system32 (CSIDL_SYSTEM) is for 64bit and %SystemRoot%\SysWOW64 (CSIDL_SYSTEMX86) is for 32bit. once you know the running exes bitness, its easy to do a proper path comparison.
>> sometimes the user might launch the same app/window from the same exe but from the exe being copied to two different folders.
true, he could also rename it. you could check for additional information like the company name, copyright, version and so on. but all of that data can be faked as well.
c ya,
nco2k
you wont find a window named "Calculator" on a foreign os.
i would browse the list of all running processes and check if the exes name and location match the one im looking for.
>> it fails because of "System32" vs "SysWow64"; that is, you don't know which path the system will use.
%SystemRoot%\system32 (CSIDL_SYSTEM) is for 64bit and %SystemRoot%\SysWOW64 (CSIDL_SYSTEMX86) is for 32bit. once you know the running exes bitness, its easy to do a proper path comparison.
>> sometimes the user might launch the same app/window from the same exe but from the exe being copied to two different folders.
true, he could also rename it. you could check for additional information like the company name, copyright, version and so on. but all of that data can be faked as well.
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf