Use Modeless Dialog inside MFC DLL
-
Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!
-
Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!
You can simply pass NULL to CDialog constructor as parent window. In this case, MFC searches a proper one. If it doesn't find any, dialog's parent window is set to the main application window. You also don't have to use above constructor for modeless dialog boxes. You can use default constructor then you can specify parent window later by Create() function.
m_pDlg = new CMymfc9Dialog();
m_pDlg->Create(IDD_MYMFC9DIALOG, NULL); // or parent wnd instead of NULL
m_pDlg->ShowWindow(SW_SHOW);
-
Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!
In your DLL, put this function:
void MyDLLClass::ShowDialog(CWnd *pWnd)
{
m_pDlg = new CMymfc9Dialog(pWnd); // m_pDlg is variable in MyDLLClass
}In your app, call the
ShowDialog()
function.Best wishes, Hans
-
Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!
Hi, From your posting, I think that you wanted to a dialog box which is added a resource in your MFC dll. If I am right, It is a matter of simple. Please see the sample below. extern "C" __declspec(dllexport) showMyDialog(CWnd *parent) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); CDialog *myDialog = new CDialog(IDD_DIALOG1, parent); myDialog->ShowWindow(SW_NORMAL); } Make sure that you release the allocated memory in WM_NCDESTROY message handler code. Then about the code. There is a problem when we want to show a dialog from an MFC DLL. The MFC will using main application resource handle to find the specified resource. If you not specify the AFX_MANAGE_STATE(AfxGetStaticModuleState( )); at the begginig of the exported function, the MFC framework will try to find the resource in main application's resource. If the specified resource not found, then the showWindow fails and if found, MFC will try to load that resource may causing an unexpected behaviour. For more infomation see the MSDN documentation of AFX_MANAGE_STATE(AfxGetStaticModuleState( )); Hope this helps Thanks Nitheesh George Nitheesh George http://www.simpletools.co.in
-
You can simply pass NULL to CDialog constructor as parent window. In this case, MFC searches a proper one. If it doesn't find any, dialog's parent window is set to the main application window. You also don't have to use above constructor for modeless dialog boxes. You can use default constructor then you can specify parent window later by Create() function.
m_pDlg = new CMymfc9Dialog();
m_pDlg->Create(IDD_MYMFC9DIALOG, NULL); // or parent wnd instead of NULL
m_pDlg->ShowWindow(SW_SHOW);
Thanks! Now I use pMatTable = new CMatTable(this->m_pMainWnd); pass main window as parent window, it works now.
-
In your DLL, put this function:
void MyDLLClass::ShowDialog(CWnd *pWnd)
{
m_pDlg = new CMymfc9Dialog(pWnd); // m_pDlg is variable in MyDLLClass
}In your app, call the
ShowDialog()
function.Best wishes, Hans
Thanks!
-
Hi, From your posting, I think that you wanted to a dialog box which is added a resource in your MFC dll. If I am right, It is a matter of simple. Please see the sample below. extern "C" __declspec(dllexport) showMyDialog(CWnd *parent) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); CDialog *myDialog = new CDialog(IDD_DIALOG1, parent); myDialog->ShowWindow(SW_NORMAL); } Make sure that you release the allocated memory in WM_NCDESTROY message handler code. Then about the code. There is a problem when we want to show a dialog from an MFC DLL. The MFC will using main application resource handle to find the specified resource. If you not specify the AFX_MANAGE_STATE(AfxGetStaticModuleState( )); at the begginig of the exported function, the MFC framework will try to find the resource in main application's resource. If the specified resource not found, then the showWindow fails and if found, MFC will try to load that resource may causing an unexpected behaviour. For more infomation see the MSDN documentation of AFX_MANAGE_STATE(AfxGetStaticModuleState( )); Hope this helps Thanks Nitheesh George Nitheesh George http://www.simpletools.co.in
Thanks for reminding me, I do get application crash since I didn't use AFX_MANAGE_STATE(AfxGetStaticModuleState()) at first.