How to Create a Modal Dialog from Within a USRDLL (121947)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 4.0
This article was previously published under Q121947 SUMMARY
When creating a modal dialog box from within a USRDLL, or a regular DLL
statically linked to the MFC, you need to pass a valid parent window object
to the CDialog constructor. You cannot pass the CWnd pointer from an EXE to
an USRDLL, so you need to pass the HWND of the parent window.
You can use two methods to construct the CDialog object with the HWND as
its parent. You can either construct a CWnd object and use the Attach()
function to attach the HWND to it, or you can use CWnd::FromHandle. After
that you can use the CWnd object as the parent of the CDialog object.
The DLLTRACE sample program demonstrates the latter method and demonstrates
how to delete the temporary objects created by MFC in the OnIdle() handler.
To construct a modal dialog in the USRDLL, export a "C" interface function
that takes an HWND as a parameter:
export "C"
{
void FAR PASCAL _export CreateModal(HWND hParent);
}
The implementation of the CreateModal() is below.
Modification Type: | Major | Last Reviewed: | 12/8/2003 |
---|
Keywords: | kbcode KB121947 |
---|
|