标签:检索 creat ESS mes leo stdcall extern 对话 create
在DLL中封装了一个非模态对话框窗口,但是在运行时希望能阻塞主线程,但是不阻塞界面DWORD WINAPI doModal(LPVOID p) {//线程函数 INT i = 0; while (1) { i++; Sleep(30); if (i == 200)break; static MSG msg; if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { AfxGetApp()->PumpMessage(); } } return 0; } void DoEvent() {//分法消息 MSG msg; if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) //取消息,检索应用程序的消息队列,PM_REMOVE取过之后从消息队列中移除 { //发消息 ::TranslateMessage(&msg); ::DispatchMessage(&msg); } } extern "C" __declspec(dllexport) VOID __stdcall CreateMsgBox(CWnd * parent) {//创建窗口 CScale3DCMessageBoxDlg *pDlgMsgBox = new CScale3DCMessageBoxDlg ; pDlgMsgBox->Create(IDD_DIALOG1, parent); pDlgMsgBox->ShowWindow(SW_SHOW); //创建线程 HANDLE hThread[1]; DWORD threadId; hThread[0] = CreateThread(NULL, 0, doModal, 0, 0, &threadId); DWORD dwRet; DoEvent(); do { dwRet = ::MsgWaitForMultipleObjects(1, hThread, FALSE, INFINITE, QS_ALLINPUT); if (dwRet != WAIT_OBJECT_0) { DoEvent(); } } while ((dwRet != WAIT_OBJECT_0) && (dwRet != WAIT_FAILED)); }
标签:检索 creat ESS mes leo stdcall extern 对话 create
原文地址:http://blog.51cto.com/9233403/2157994