?
Solved

how does Windows (re)assign HWND values?

Posted on 2006-05-24
2
Medium Priority
?
685 Views
Last Modified: 2013-12-03
Lets say I use the Windows CE API call - EnumWindows, to get a list of the top level windows.  I will then have a list of HWND values for the open top level windows.

Now lets say I store that list of HWND values.

I realize that a window could close, but will the OS reuse those values for new windows?  If some time later I use one of the stored HWND values, for how long will the value refer to the window it referenced when I obtained the value?
0
Comment
Question by:plevintampabay
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16754831
It is not safe to rely on handle values for the reasons you have mentioned. On the other hand, there are over 4 billion possible handle values, so that it should take a while until they're reused. Anyway, the prince of calling 'EnumWindows()' is small compared to the risk of relying on unsafe assumptions.
0
 
LVL 3

Accepted Solution

by:
Mikeh926 earned 500 total points
ID: 16759710
jkr is correct that you shouldn't rely on handles remaining the same. However, if you are sure that the window will not be closed, then the handle will remain valid.

In practice CE tries not to reuse handles. If a window is closed and then reopened, it will almost certainly have a different handle value because CE allocates them on an incremental basis. The actual mechanism that CE uses is not documented and could change from one release of CE to another.

In theory if enough windows were closed and opened, a handle could be reused but that would probably take quite a while, so you might get away with testing your handle value with IsWindow() to find out if the window has been closed. Even then, if it's not your window and it could be closed at any point, there is no guarentee that it won'd be closed between you calling IsWindow() and doing whatever you are going to do with it.

Regards,
Mike.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question