Re: Modal Dialog From Modeless Dialog
On 19 Jun., 06:52, none <n...@none.none> wrote:
Hi all,
I have an MFC app with a main window and a bunch of modeless tool windows=
..
If any of these windows (the main window or any tool window) displays a
MessageBox(), only that one window is "frozen" while the dialog is open.
So, the user can just ignore the error message and click in other windows=
..
Is there a way to freeze all windows except for the message box, regardle=
ss
of which window actually launched the modal dialog?
I've tried all the combinations of MB_APPMODAL, MB_TASKMODAL, etc, and no=
ne
of them changed anything. And, anyway, I need something that works for=
any
dialog, not just a MessageBox() dialog.
Thanks.
If hWnd is the window which you wish to behave like a modal dialog,
you could use something like my GoModal function (code below).
Don't forget to call GoModal(hWnd, false) before closing the "modal"
dialog.
BOOL CALLBACK EnableWndProc(HWND hWnd, LPARAM lParam)
{
EnableWindow(hWnd, !lParam);
return TRUE;
}
bool GoModal(HWND hWnd, bool bModal)
{
HANDLE hThreadSnap;
THREADENTRY32 te32;
te32.dwSize = sizeof(te32);
DWORD dwProcessId = GetCurrentProcessId();
// create a snapshot of the system
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (NULL == hThreadSnap)
return false;
// retrieve information about the first thread
if (!Thread32First(hThreadSnap, &te32))
{
CloseHandle(hThreadSnap);
return false;
}
// process the first thread and then get the rest of the threads.
do
{
if (te32.th32OwnerProcessID == dwProcessId)
EnumThreadWindows(te32.th32ThreadID, &EnableWndProc, bModal);
}
while (Thread32Next(hThreadSnap, &te32));
if (bModal)
{
// reenable hWnd
EnableWindow(hWnd, TRUE);
}
CloseHandle(hThreadSnap);
return true;
}
HTH