Duilib 模態對話方塊和非模態對話方塊
阿新 • • 發佈:2019-02-19
- void CMainDlg::DoTask()
- {
- CTaskDlg * pDlg = NULL;
- pDlg = new CTaskDlg(XML_FILE_NAME_TASK_DLG, WND_CLASS_NAME_TASK_DLG);
- pDlg->Create(this->m_hWnd, MAIN_RORG_DISP_NAME, UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE); ///< 如果引數1是NULL, 為桌面, 子視窗就不是模態對話方塊
- pDlg->CenterWindow();
-
pDlg->ShowModal(); ///< 彈出的是模態視窗
- }
因為要彈出模態對話方塊, 跟進 pDlg->ShowModal(), 看到了duilib禁止主視窗的程式碼, 才想到引數1應為父視窗視窗控制代碼.
可以看出, 當要彈出非模態視窗時, 可以將pDlg->Create 的引數1 填成 NULL.
- UINT CWindowWnd::ShowModal()
- {
- ASSERT(::IsWindow(m_hWnd));
- UINT nRet = 0;
-
HWND hWndParent = GetWindowOwner(m_hWnd);
- ::ShowWindow(m_hWnd, SW_SHOWNORMAL);
- ::EnableWindow(hWndParent, FALSE); ///< 當 (NULL == hWndParent) 時, EnableWindow 不生效, 導致彈出的是非模態視窗.
- MSG msg = { 0 };
- while( ::IsWindow(m_hWnd) && ::GetMessage(&msg, NULL, 0, 0) ) {
-
if
- nRet = msg.wParam;
- ::EnableWindow(hWndParent, TRUE);
- ::SetFocus(hWndParent);
- }
- if( !CPaintManagerUI::TranslateMessage(&msg) ) {
- ::TranslateMessage(&msg);
- ::DispatchMessage(&msg);
- }
- if( msg.message == WM_QUIT ) break;
- }
- ::EnableWindow(hWndParent, TRUE);
- ::SetFocus(hWndParent);
- if( msg.message == WM_QUIT ) ::PostQuitMessage(msg.wParam);
- return nRet;
- }