An assertion failure occurs or some keys do not work as expected when displaying the ATL dialog box object as a modeless dialog box (216503)
The information in this article applies to:
- The Microsoft Active Template Library (ATL) 3.0, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
- The Microsoft Active Template Library (ATL) 2.1, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
This article was previously published under Q216503 SYMPTOMS 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: - Clicking OK or Cancel causes an assertion failure.
- The TAB or accelerator key does not work as
expected.
CAUSE The code generated by the ATL wizard is designed to show
the dialog box as a modal dialog box. RESOLUTION Add/modify the code below to the ATL .exe project to show
the ATL dialog box as modeless dialog box: - The EndDialog() call in both the OnOK() and OnCancel()
functions cause the assertion failure. Call DestroyWindow() instead for
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;
}
- Modify the GetMessage() loop in the _tWinMain() function so
IsDialogMessage() is called for a modeless dialog box. This method takes care
of both the tab and accelerator keys processing problem.
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.
STATUS
This behavior is by design.REFERENCES (c) Microsoft Corporation 1999, All Rights Reserved.
Contributions by Yeong-Kah Tam, Microsoft Corporation.
Modification Type: | Major | Last Reviewed: | 10/3/2005 |
---|
Keywords: | kbtshoot kbATLWC kbDlg kbprb KB216503 kbAudDeveloper |
---|
|