PRB: Problems Showing an ATL Dialog Box as Modeless in ATL .exeID: Q216503
|
The ATL Object Wizard dialog box provides an option to create an ATL dialog box object. However, the following problems are found when displaying the ATL dialog box object as a modeless dialog box from within an ATL .exe project:
The code generated by the ATL wizard is designed to show the dialog box as a modal dialog box.
Add/modify the code below to the ATL .exe project to show the ATL dialog box as modeless dialog box:
LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
DestroyWindow();
PostQuitMessage(0); // OPTIONAL - call this to terminate the app.
return 0;
}
LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
DestroyWindow();
PostQuitMessage(0); // OPTIONAL - call this to terminate the app.
return 0;
}
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
if ((gModelessDlg) &&
(!::IsDialogMessage(gModelessDlg->m_hWnd,&msg)))
DispatchMessage(&msg);
}
NOTE: TranslateMessage() is not required in the GetMessage() loop.This behavior is by design.
// Include the header file for CMyDialog and declare a global variable of
// CMyDialog type.
#include "mydialog.h"
CMyDialog* gMainDialog = NULL;
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
// ... other stuff
// Show the CMyDialog as a modeless dialog box.
gMainDialog = new CMyDialog;
gMainDialog->Create(GetDesktopWindow());
gMainDialog->ShowWindow(SW_SHOW);
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
DispatchMessage(&msg);
// ... other stuff
// Destroy the C++ object for the modeless dialog box.
if (gMainDialog)
delete gMainDialog;
// ... other stuff
}
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Yeong-Kah Tam, Microsoft Corporation.
Additional query words:
Keywords : kbATL210 kbATLWC kbVC500 kbVC600 kbATL300
Version : WINDOWS:2.1,3.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: March 5, 1999