Is retrieved HWND also unique over life-time of my script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Is retrieved HWND also unique over life-time of my script?

27 Aug 2014, 02:23

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
just me
Posts: 9576
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Is retrieved HWND also unique over life-time of my scrip

27 Aug 2014, 03:12

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
So it might depend on the life-time of your script. I do not believe that window handles are recycled without particular reasons.
Last edited by just me on 27 Aug 2014, 04:29, edited 1 time in total.
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Is retrieved HWND also unique over life-time of my scrip

27 Aug 2014, 03:41

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?
just me
Posts: 9576
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Is retrieved HWND also unique over life-time of my scrip

27 Aug 2014, 04:28

autocart wrote:...or does the ahk script only copy the value of the hwnd w/o the OS knowing about it?
Yes!
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Is retrieved HWND also unique over life-time of my scrip

27 Aug 2014, 04:42

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Mateusz53, MrHue, Pianist and 256 guests