Is there any method to check for a valid hwnd from an another thread?
-
Apart the api "IsWndow" which the microsoft doesnt recommend to be used other than by the thread which had created the window,is there any method to check for a valid hwnd i.e from an another thread?
dont want,dont want thinking,climbing on head and jumping grass! (venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
-
Apart the api "IsWndow" which the microsoft doesnt recommend to be used other than by the thread which had created the window,is there any method to check for a valid hwnd i.e from an another thread?
dont want,dont want thinking,climbing on head and jumping grass! (venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
From MSDN:
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.
Are you sure this is a concern? If you're going to do anything with the
HWND
the same applies (it could be destroyed). Just useIsWindow
.Steve
-
Apart the api "IsWndow" which the microsoft doesnt recommend to be used other than by the thread which had created the window,is there any method to check for a valid hwnd i.e from an another thread?
dont want,dont want thinking,climbing on head and jumping grass! (venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
If the target window is a top level window you can install a hook (see WH_SHELL) to be notified about destroying top level windows. But frankly, no matter what technique you use, you can be never sure. If everything looks ok and you send a message to that window, the window still can be destroyed in the same moment(almost the same). Or while is processing your message. Simply there is no way to prevent a foreign window from beeing destroyed anytime. The only thing you can do is to implement thoroughful error processing, verify the effects of each of the messages sent and check regularly if the handle is still for the same window and not reused for another one. Working with a foreign windows is something similar to working with dialog boxes. You can never be sure what stupidity will a user type in an edit box so you have to check everything. I think a window beeing destroyed exactly in the very moment when you need it, is a very rare occurence. Just make sure to limit to minimum the damages of such an event. If your software stops abruptly and hours of the user's unsaved work are gone, that's unacceptable. If the only thing that happens is an error message "Internal error, please repeat the last command", that's acceptable, even if it's not desirable. Even the best software fails sometimes. The only question is how it fails: disastruously or gracefully ?