Hi all,
Using WinExist() I can retrieve the "uniqueID" (window handle, hwnd) of a window.
My question:
Can I be 100% sure that the retrieved hwnd is really unique (only referring to this one window) also over the whole time while my ahk-script is active?
Or could it happen that, if the window I was checking gets closed, it's hwnd gets reused by windows OS, so that I would eventually be referring to a different window by using the hwnd that I had retrieved at first? (On the stackoverflow forum they say that, in general, window handles can and do get reused by windows OS under certain conditions.)
Thx for all answers from people who know what they are talking about.
Regards, Stephan
Is retrieved HWND also unique over life-time of my script?
Re: Is retrieved HWND also unique over life-time of my scrip
So it might depend on the life-time of your script. I do not believe that window handles are recycled without particular reasons.IsWindow wrote:Remarks
A thread should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window.
Source: http://msdn.microsoft.com/en-us/library ... s.85).aspx
Last edited by just me on 27 Aug 2014, 04:29, edited 1 time in total.
Re: Is retrieved HWND also unique over life-time of my scrip
ok, let me state the links, that made me think, but that are not clear enough to me:
http://blogs.msdn.com/b/oldnewthing/arc ... 12755.aspx
http://stackoverflow.com/questions/1815 ... les-reused
So, my question, if I understood the meaning of the information correctly, is:
When I call WinExist() and the window does exist, does my ahk script then keep a handle object to that window open (until the end of the script) and thus prohibit the hwnd from being reused by the OS...
...or does the ahk script only copy the value of the hwnd w/o the OS knowing about it?
http://blogs.msdn.com/b/oldnewthing/arc ... 12755.aspx
http://stackoverflow.com/questions/1815 ... les-reused
So, my question, if I understood the meaning of the information correctly, is:
When I call WinExist() and the window does exist, does my ahk script then keep a handle object to that window open (until the end of the script) and thus prohibit the hwnd from being reused by the OS...
...or does the ahk script only copy the value of the hwnd w/o the OS knowing about it?
Re: Is retrieved HWND also unique over life-time of my scrip
Yes!autocart wrote:...or does the ahk script only copy the value of the hwnd w/o the OS knowing about it?
Re: Is retrieved HWND also unique over life-time of my scrip
ok, I hope you know for sure. then I would have to periodically check if the window still exists in case I want to keep using my retrieved window handle.
thx for the response.
thx for the response.
Re: Is retrieved HWND also unique over life-time of my scrip
@justme Great Enthusiasm!
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Who is online
Users browsing this forum: Bing [Bot] and 271 guests