//基于对话框的MFC核心代码
void CDLLDemoDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
AfxBeginThread(TestThread, this);
}
UINT CDLLDemoDlg::TestThread(LPVOID lParam)
{
CDLLDemoDlg* pDlg = (CDLLDemoDlg*)lParam;
ShowDoModalDLg(pDlg->m_hWnd);
return 0;
}
//动态库里的核心代码
__int32 __stdcall ShowDoModalDLg(HWND hWnd)
{
CWnd* pWnd = CWnd::FromHandle(hWnd);
CDlg1 dlg;
if (NULL != pWnd)
{
pWnd->EnableWindow(FALSE);
}
dlg.DoModal();
if (NULL != pWnd)
{
pWnd->EnableWindow(TRUE);
pWnd->SetFocus();
pWnd->SetForegroundWindow();
pWnd->SetActiveWindow();
}
return 0;
}
//改写OnInitDialog,实现Domodal框置顶
BOOL CDlg1::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowPos(&wndTopMost,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
SetForegroundWindow();//将窗口置于前台,即强行置顶
return TRUE;
}