typedef struct tagMSG{ HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; }MSG; |
while(GetMessage(&&msg,NULL,NULL,NULL)) { file://从消息队列中取得消息 TranslateMessage(&&msg); file://检索并生成字符消息WM_CHAR DispatchMessage(&&msg); file://将消息发送给相应的窗口函数 } |
{ … … // Disable 父窗口 (在创建对话框前) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } TRY { // 创建模态对话框 AfxHookWindowCreate(this); if (CreateDlgIndirect(lpDialogTemplate,CWnd::FromHandle(hWndParent), hInst)) { if (m_nFlags & WF_CONTINUEMODAL) { // 进入模式循环 DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } } } CATCH_ALL(e) { DELETE_EXCEPTION(e); m_nModalResult = -1; } END_CATCH_ALL file://Enable 父窗口 if (bEnableParent) ::EnableWindow(hWndParent, TRUE); if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd) ::SetActiveWindow(hWndParent); // 删除对话框 DestroyWindow(); PostModal(); … … } |
int CsubModeFrame::DoModal() { HWND hWndParent = m_hWndPrt; CRect rc(0,0,400,400); CWnd *pParent = CWnd::FromHandle(hWndParent); DWORD dwStyle=WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_THICKFRAME | WS_VISIBLE | WS_SYSMENU | WS_CAPTION; if(!Create(NULL,"模态文档/试图框架 ",dwStyle,rc,pParent,NULL)) return FALSE; BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent,FALSE); ::EnableWindow(m_hWnd,TRUE); bEnableParent = TRUE; } CenterWindow(); TRY { // enter modal loop DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } CATCH_ALL(e) { DELETE_EXCEPTION(e); m_nModalResult = -1; } END_CATCH_ALL if (bEnableParent) ::EnableWindow(hWndParent, TRUE); if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd) ::SetActiveWindow(hWndParent); // destroy modal window DestroyWindow(); return m_nModalResult; } |
void CSubFrame::EndModal(){ ASSERT(::IsWindow(m_hWnd)); if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL)) { EndModalLoop(1); } } |
CSubModeFrame SubModeFrame; If(SubModeFrame.DoMode()){ MessageBox("Mode Ok");} |