Are window handles (HWND) unique, or do they ever get reused?

风格不统一 提交于 2019-12-05 08:08:10
ybungalobill

By the pigeonhole principal, yes, they can't be unique. In fact, Microsoft still maintains compatibility with 16-bit Windows, and as a result handles are 16-bit values. So there are at most 65536 possible handle values.

Yes. There are only a finite number of values a handle can be represented by, so Windows has to reuse them eventually.

Once a handle is closed, it is gone, you can't do anything with it, it doesn't exist, and you shouldn't even look at it.

And if you subsequently open another handle, then it is possible that Windows will reuse the handle value.

I would advise you to make absolutely no assumptions about handle values.

You shouldn't have to think about concrete handle values for all practical purposes. A handle should be considered an opaque placeholder for something else. You can pass the handle around to refer to something (e.g. a window) without having a reference to the real thing, but you shouldn't ever have to look at the handle itself. The fact that it is a numeric value should be considered an implementation detail, ie. not important (unless maybe you do some kind of low-level systems programming).

That being said, I'd support @jalf's answer: Handle values could get reused. If I had to make any assumption at all about that, I would assume that a handle value could get reused anytime.

Yes, window handles are reused.

Documentation to IsWindow function says:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!