调用一个新的 对话框 的方法
注意:这里是插入窗体。
一、模态对话框
1) 首先,新建的一个对话框,假如为test
2) 在刚才插入的子窗口添加消息映射函数void C***Dll::PostNcDestroy() ,在次函数里面添加 : delete this;
3) 在需要调用 新建对话框的 CPP 文件添加头文件#include \"test.h\"
4) 然后在需要调用新建对话框的按钮的成员函数里写上:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
test testDlg;
testDlg.DoModal();
二、非模态对话框
1) 首先,插入一个窗体,假如为 CFrmDl ;
2) 在刚才插入的子窗口添加消息映射函数void C***Dll::PostNcDestroy() ,在次函数里面添加 : delete this;
3) 在需要调用 新建对话框的 CPP 文件添加头文件#include \"FrmDll.h\" ;
4) 然后在需要调用新建对话框的按钮的成员函数里写上:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CFrmDll *dlg = new CFrmDll; // 在内存中 new 出来
dlg->Create(IDD_FRMDLLDlg); // 创建对话框 ,
dlg->CenterWindow(); // 窗口居中
dlg->ShowWindow(SW_SHOW); // 显示窗口
非模态 Dll 调用 例子:
typedef void ( * P_show)();
HINSTANCE hinstance =NULL;
void CTestDlgDlg::OnButton1()
{
if (hinstance ==NULL)
{
hinstance = LoadLibrary (\"dllPro.dll\");
}
if(hinstance ==NULL)
{
AfxMessageBox(\"Fail\");
return;
}
P_show show = (P_show)::GetProcAddress (hinstance,\"showdlg\");
show();
// FreeLibrary(hinstance); // hinstance = NULL; }
// 这个记得 放在析构函数里面
// 这个记得 放在析构函数里面