you can try ::IsWindow (HWND) or CWnd::GetSafeHwnd ()
"maka3" <ma...@punjabi.net> escribió en el mensaje
If the window is closed, under normal conditions the accompanying CWnd * object has also
been "destroyed", that is, the storage referenced by the CWnd * has been released to the
heap, and may either now represent free space, or have been reallocated for another
purpose. Therefore, the pointer is ALWAYS "valid", in that it points to valid storage. The
storage, however, may not be meaningful (there are rare cases in which the storage might
actually be freed back to the OS, but that doesn't happen often enough to matter. You
almost always end up with a valid pointer to meaningless storage).
Therefore, it is best to code in ways that do not rely on knowing a window pointer is
The most common context comes up in the case of having to deal with threads, where a
thread wishes to PostMessage to a CWnd *. In this case, the answer is simple: the CWnd *
that is receiving the message is responsible for making sure the thread is shut down
before it allows itself to be closed. If this is your problem, post a followup and I'll go
into the more extensive discussion this requires.
Otherwise, you should consider it a coding error that you can be holding onto a CWnd * to
a window that could be destroyed out from under you, and you will have to change your
program. There is no way to tell if a CWnd * pointer is valid.
OTOH, if you have a CWnd * you know CAN be valid, but the window can go away...a rare
condition, given the nature of MFC, then you can use ::IsWindow on the m_hWnd member to
see if it is still a window. There are other tests, for example, CWnd::GetSafeHwnd() can
tell you during startup if a control has been initialized.
> Otherwise, you should consider it a coding error that you can be holding onto a CWnd * to
> a window that could be destroyed out from under you, and you will have to change your
> program. There is no way to tell if a CWnd * pointer is valid.
Thanks for your detailed answer. I create a new window with
pMainFrame->CreateNewChild() and save a pointer to it. In the render
loop I draw to it with DirectDraw.
I could get in the WindowProc and draw in WM_PAINT. But how can I jump
in the Proc
with only having the pointer?
I'm very new to MFC and started programming with C#, where it is a
common way to call for example "Form.Created".
Joseph M. Newcomer [MVP]