Hi,

I'm writing an small library to wrap some Win32 functions for windowing, and i'm having an small issue with modal 'dialogs'. I've created a wrapper for the basic windows (CWindow) and derived a CFormWindow from it, the later will implement the basic dialog box functionality.

Now, my CFormWindow class DOES NOT USE use CreateDialog or any similar function as the library has an XML parser to create controls at runtime from a given XML UI-description file (something like XAML).

The problem is the modal loop. I have a ShowModal(...) function, that has its own message loop and works fine except for the following issues:

- The function receives a pointer to the parent window. It disables the parent and shows the dialog, but if the pointer is null the parent is not disabled (so it's possible to resize, move, close it, etc. along with any child window). MFC's implementation disables EVERY window if the parent is not set.

- Passing a non-null parent pointer disables the parent and its child windows, but only if they have the WM_CHILD style. Floating windows and modeless dialogs aren't affected and its message processing continues normally, without being disabled (even if they're owned by the parent). MFC doesn't disable non-WM_CHILD windows but Windows Forms does.

I've read the MSDN documentation, googled a ton of sites, checked MFC & wxWidgets sources and I can't find a solution.

Here's the code of the ShowModal(...) function:

Code:
int CFormWindow::ShowModal(CWindow *pParent)
{
	MSG msg;
	// Disable the parent window
	if (pParent)
		pParent->Enable(false);
	// Show the (previously created) CFormWindow-derived window
	Show();
	// The modal loop
	for (m_bClose = false; !m_bClose; WaitMessage())
	{      // PeekMessage and remove from queue
		while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{      // Exit modal loop and re-post WM_QUIT message
			if(msg.message == WM_QUIT)
			{
				m_bClose = true;  // Flag that gets 'On' when calling EndModal()
				PostMessage(NULL, WM_QUIT, 0, 0);
				break;
			}
			if(!IsDialogMessage(m_hWnd, &msg))
			{      // Translate and dispatch
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	} 
	// Hide the CFormWindow-derived window
	Hide();
	// And re-enable parent
	if (pParent)
		pParent->Enable(true);
	return 0;
}
So, here's my question: Am I missing something on the ShowModal(...) function? It works with one active window so I think it just may be incomplete.

A possible solution would be notifying each top-level (say, non WM_CHILD) window of the modal dialog activation/deactivation, so they would disable themselves and then re-enable after the dialog has been closed, but this sounds like a dirty hack.

MFC does this automagically but it's not an option. The code should compile on VC++ Express and as you know, it doesn't include MFC (additionally, I'm the only developer on the crew that knows MFC and I don't want to code everything).

Any suggestions and/or ideas will be greatly appreciated =)