线程里弹DoModal框置顶以及禁止在处理DoModal框时MFC主界面最小化及对主界面进行操作 .

//基于对话框的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;
}

你可能感兴趣的:(C++,MFC)