Reputation: 5146
The application I'm writing is using a virtual keyboard. To show, hide, resize or move the virtual keyboard, I first need to get a handle to it through a call to FindWindow
function and then send it some messages by PostMessage
.
Since I have no experience with winapi, my question is do I need to release this handle in some way or can I just forget about it once I'm done?
The virtual keyboard is a process of its own with longer lifetime than my application.
Upvotes: 1
Views: 744
Reputation: 612964
You do not need to finalize this handle. It is owned by the process that created the window, which is in charge also of destroying it.
Unlike kernel handles (file handles, event handles, mutex handles etc.) window handles are not reference counted. You call FindWindow
, and then do what need to do with the window handle, and that it.
Note however, that since the system does not keep track of references to window handles, if the window is destroyed, then you can be left holding a handle to that destroyed window. And if the system re-uses that handle then you now have a handle to a different window.
If at all possible, when you are coordinating user interface between multiple processes in this way, you should also communicate window destruction events to avoid one process being left holding a stale handle.
Upvotes: 4