assert in CFrameWnd::NotifyFloatingWindows
Hi,
I'm trying to track down an occasional crash I'm getting while calling
into "PeekMessage" right after my application has been activated
(usually from Alt-Tabbing between my application and other
appliations).
The call into PeekMessage() eventually filters down into
CFrameWnd::NotifyFloatingWindows(), and the source code included with
my visual studio for this function has this little loop at the bottom:
// then update the state of all floating windows owned by the parent
HWND hWnd = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
while (hWnd != NULL)
{
if (AfxIsDescendant(pParent->m_hWnd, hWnd))
::SendMessage(hWnd, WM_FLOATSTATUS, dwFlags, 0);
hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
}
And my source code for 'AfxIsDescendant(..)' starts like this:
BOOL AFXAPI AfxIsDescendant(HWND hWndParent, HWND hWndChild)
// helper for detecting whether child descendent of parent
// (works with owned popups as well)
{
ASSERT(::IsWindow(hWndParent));
ASSERT(::IsWindow(hWndChild));
I'm wondering if this occasional crash I'm running into isn't a
problem with my Application, but with this piece of code.
According to MSDN on the "IsWindow" function, in the "Remarks"
section:
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.
Unfortunately, the loop mentioned above in
CFrameWnd::NotifyFloatingWindows() is iterating over some windows that
were NOT created by the current thread (it seems to be iterating over
all windows in all applications, but I'm not positive about this). I
have verified this by running a similar loop and calling
GetWindowThreadProcessId() for each hwnd, and several of those windows
were not created by the current thread, or even the current process.
Is the MSDN documentation old or out of date? Is this a legitimate
MFC bug or am I missing something else? Any help would be
appreciated.
thanks,
sam