int COlePropertiesDialog::DoModal() { ASSERT_VALID(this); ASSERT(m_gp.lpfnHook != NULL); // can still be a user hook ASSERT(m_vp.lpfnHook != NULL); // can still be a user hook ASSERT(m_lp.lpfnHook != NULL); // can still be a user hook // disable scale if OnApplyScale not implemented if (!OnApplyScale(NULL, -1, FALSE)) m_op.lpVP->dwFlags |= VPF_DISABLESCALE; // invoke the dialog m_op.lpPS->hwndParent = PreModal(); int iResult = MapResult(::OleUIObjectProperties(&m_op)); PostModal(); return iResult; }
INT_PTR SimpleFileDialog::DoModal() { // Don't use a hook procedure for Vista OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof osvi; ::GetVersionEx(&osvi); if (osvi.dwMajorVersion >= 6) m_ofn.Flags &= ~OFN_ENABLEHOOK; DWORD nOffset = lstrlen(m_ofn.lpstrFile)+1; memset(m_ofn.lpstrFile+nOffset, 0, (m_ofn.nMaxFile-nOffset)*sizeof(TCHAR)); HWND hWndFocus = ::GetFocus(); BOOL bEnableParent = FALSE; m_ofn.hwndOwner = PreModal(); AfxUnhookWindowCreate(); if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner)) { bEnableParent = TRUE; ::EnableWindow(m_ofn.hwndOwner, FALSE); } _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (m_ofn.Flags & OFN_EXPLORER) pThreadState->m_pAlternateWndInit = this; else AfxHookWindowCreate(this); INT_PTR nResult; if (m_bOpenFileDialog) nResult = ::GetOpenFileName(&m_ofn); else nResult = ::GetSaveFileName(&m_ofn); pThreadState->m_pAlternateWndInit = NULL; if (bEnableParent) ::EnableWindow(m_ofn.hwndOwner, TRUE); if (::IsWindow(hWndFocus)) ::SetFocus(hWndFocus); PostModal(); return nResult ? nResult : IDCANCEL; }
int CFontDialog::DoModal() { ASSERT_VALID(this); ASSERT(m_cf.Flags & CF_ENABLEHOOK); ASSERT(m_cf.lpfnHook != NULL); // can still be a user hook m_cf.hwndOwner = PreModal(); int nResult = ::ChooseFont(&m_cf); PostModal(); if (nResult == IDOK) { // copy logical font from user's initialization buffer (if needed) memcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf)); return IDOK; } return nResult ? nResult : IDCANCEL; }
EMessageBoxReturn Dialog::DoModal() { importData(); PreModal(); EMessageBoxReturn ret = modal_dialog_show(m_window, m_modal); ASSERT_NOTNULL(m_window); if(ret == eIDOK) { exportData(); } gtk_widget_hide(GTK_WIDGET(m_window)); PostModal(m_modal.ret); return m_modal.ret; }
EMessageBoxReturn Dialog::DoModal () { // Import the values from the registry before showing the dialog _registryConnector.importValues(); PreModal(); EMessageBoxReturn ret = modal_dialog_show(m_window, m_modal); ASSERT_NOTNULL(m_window); if (ret == eIDOK) { _registryConnector.exportValues(); } gtk_widget_hide(GTK_WIDGET(m_window)); PostModal(m_modal.ret); return m_modal.ret; }
int COleUpdateDialog::DoModal() { ASSERT_VALID(this); // first count number of links/embeddings to be updated DWORD dwLink = 0; int cLinks = 0; while ((dwLink = m_el.lpOleUILinkContainer->GetNextLink(dwLink)) != 0) ++cLinks; // when no links are out-of-date, don't bother if (cLinks == 0) return IDCANCEL; // bring up the dialog that processes all the links HWND hWndParent = PreModal(); BOOL bResult = OleUIUpdateLinks(m_el.lpOleUILinkContainer, hWndParent, (LPTSTR)(LPCTSTR)m_strCaption, cLinks); PostModal(); return bResult ? IDOK : -1; }
INT CFolderDialog::DoModal( void ) #endif { ASSERT_VALID( this ); ASSERT( m_bi.lpfn != NULL ); m_bi.hwndOwner = PreModal(); INT_PTR nRet = -1; LPITEMIDLIST pItemIDList = ::SHBrowseForFolder( &m_bi ); if( pItemIDList ) { if( ::SHGetPathFromIDList( pItemIDList, m_szFolPath ) ) nRet = IDOK; else nRet = IDCANCEL; _coTaskMemFree( pItemIDList ); } PostModal(); return ( nRet ); }
int Dialog::DoModal(){ Create(); UpdateData( FALSE ); PreModal(); gtk_grab_add( m_pWidget ); gtk_widget_show( m_pWidget ); m_nLoop = true; while ( m_nLoop ) { gtk_main_iteration(); } if ( m_pWidget != NULL ) { UpdateData( TRUE ); gtk_grab_remove( m_pWidget ); gtk_widget_hide( m_pWidget ); } PostModal( m_nReturn ); return m_nReturn; }
INT CFolderDialog::DoModal(VOID) #endif { ASSERT_VALID(this); ASSERT(m_bi.lpfn != NULL); INT_PTR nRet = -1; m_bi.hwndOwner = PreModal(); LPITEMIDLIST pItemIDList = ::SHBrowseForFolder(&m_bi); if (pItemIDList) { if (::SHGetPathFromIDList(pItemIDList, m_szFolPath)) nRet = IDOK; SAFE_COTASKMEMFREE(pItemIDList); } else nRet = IDCANCEL; PostModal(); return (nRet); }
int CDialog::DoModal() { // can be constructed with a resource template or InitModalIndirect ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL || m_lpDialogTemplate != NULL); // load resource as necessary LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate; HGLOBAL hDialogTemplate = m_hDialogTemplate; HINSTANCE hInst = AfxGetResourceHandle(); if (m_lpszTemplateName != NULL) { hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG); HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); } if (hDialogTemplate != NULL) lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate); // return -1 in case of failure to load the dialog template resource if (lpDialogTemplate == NULL) return -1; // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } TRY { // create modeless dialog AfxHookWindowCreate(this); if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInst)) { if (m_nFlags & WF_CONTINUEMODAL) { // enter modal loop DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } // hide the window before enabling the parent, etc. if (m_hWnd != NULL) SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW| SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); } } 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(); PostModal(); // unlock/free resources as necessary if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL) UnlockResource(hDialogTemplate); if (m_lpszTemplateName != NULL) FreeResource(hDialogTemplate); return m_nModalResult; }
int CRuntimeDlg::DoModal(LPCTSTR szCaption, DWORD dwStyle, DWORD dwExStyle, const CRect& rect, CWnd* pParentWnd, UINT nID) { // fail immediately if no controls have been added if (!m_lstControls.GetCount()) return IDCANCEL; // setup for modal loop and creation m_nModalResult = -1; m_nFlags |= WF_CONTINUEMODAL; // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); bEnableParent = TRUE; } try { // create modeless dialog if (Create(szCaption, dwStyle, dwExStyle, rect, pParentWnd ? pParentWnd : CWnd::FromHandle(hWndParent), nID)) { if (m_nFlags & WF_CONTINUEMODAL) { // enter modal loop DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } // hide the window before enabling the parent, etc. if (m_hWnd != NULL) SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER); } } catch(...) { m_nModalResult = -1; } if (bEnableParent) ::EnableWindow(hWndParent, TRUE); if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd) ::SetActiveWindow(hWndParent); // save pos SaveCurrentPos(); // destroy modal window DestroyWindow(); PostModal(); // cleanup resources GraphicsMisc::VerifyDeleteObject(m_hFont); ::DestroyIcon(m_hILarge); ::DestroyIcon(m_hISmall); return m_nModalResult; }
int CWebInterfaceDlg::DoModal() { ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL || m_lpDialogTemplate != NULL); LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate; HGLOBAL hDialogTemplate = m_hDialogTemplate; HINSTANCE hInst = AfxGetResourceHandle(); if (m_lpszTemplateName != NULL) { hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG); HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); } if (hDialogTemplate != NULL) lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate); if (lpDialogTemplate == NULL) return -1; 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 = 0; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult); } if (m_hWnd != NULL) SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW| SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER); } } 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); DestroyWindow(); PostModal(); if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL) UnlockResource(hDialogTemplate); if (m_lpszTemplateName != NULL) FreeResource(hDialogTemplate); return m_nModalResult; }
//============================================================================= // DoModal override copied mostly from MFC, with modification to use // m_ofnEx instead of m_ofn. INT_PTR CXFolderDialog::DoModal() //============================================================================= { TRACE(_T("in CXFolderDialog::DoModal\n")); ASSERT_VALID(this); ASSERT(m_ofn.Flags & OFN_ENABLEHOOK); ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook AFX_MANAGE_STATE(AFXMANAGESTATE()) m_bFirstTime = TRUE; m_wndListView.Init(this); // zero out the file buffer for consistent parsing later TCHAR * pBuf = new TCHAR [m_ofn.nMaxFile + 100]; memset(pBuf, 0, (m_ofn.nMaxFile + 100) * sizeof(TCHAR)); if (m_ofn.lpstrFile) { // copy file buffer _tcsncpy(pBuf, m_ofn.lpstrFile, m_ofn.nMaxFile); // zero out file buffer in OPENFILENAME struct memset(m_ofn.lpstrFile, 0, m_ofn.nMaxFile*sizeof(TCHAR)); // restore copied file buffer _tcsncpy(m_ofn.lpstrFile, pBuf, m_ofn.nMaxFile); } if (pBuf) delete [] pBuf; pBuf = NULL; // WINBUG: This is a special case for the file open/save dialog, // which sometimes pumps while it is coming up but before it has // disabled the main window. HWND hWndFocus = ::GetFocus(); BOOL bEnableParent = FALSE; m_ofn.hwndOwner = PreModal(); AfxUnhookWindowCreate(); if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner)) { bEnableParent = TRUE; ::EnableWindow(m_ofn.hwndOwner, FALSE); } _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); ASSERT(pThreadState->m_pAlternateWndInit == NULL); if (m_ofn.Flags & OFN_EXPLORER) pThreadState->m_pAlternateWndInit = this; else AfxHookWindowCreate(this); memset(&m_ofnEx, 0, sizeof(m_ofnEx)); memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn)); if (m_ofnEx.hInstance == 0) m_ofnEx.hInstance = AfxGetInstanceHandle(); m_ofnEx.Flags |= OFN_ENABLESIZING; #if (_WIN32_WINNT >= 0x0500) TRACE(_T("_WIN32_WINNT=0x%X\n"), _WIN32_WINNT); #pragma message(__FILE__ "(" makestring(__LINE__) \ ") : OPENFILENAME is large size (3 extra items are included)") if (IsWin2000()) m_ofnEx.lStructSize = sizeof(OPENFILENAME); // OS >= 2000, force to large size else m_ofnEx.lStructSize = OPENFILENAME_SIZE_VERSION_400; // use small size #else // _WIN32_WINNT < 0x0500, or isn't defined #pragma message(__FILE__ "(" makestring(__LINE__) \ ") : OPENFILENAME is small size (3 extra items are NOT included)") if (IsWin2000()) m_ofnEx.lStructSize = sizeof(OPENFILENAMEEX_FOLDER); // OS >= 2000, force to large size else m_ofnEx.lStructSize = OPENFILENAME_SIZE_VERSION_400; // use small size #endif m_ofnEx.lpstrInitialDir = m_strInitialFolder; //m_ofnEx.lpstrFilter = m_strFilter; int nResult = 0; if (m_bOpenFileDialog) nResult = ::GetOpenFileName((OPENFILENAME*)&m_ofnEx); else nResult = ::GetSaveFileName((OPENFILENAME*)&m_ofnEx); memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn)); m_ofn.lStructSize = sizeof(m_ofn); if (nResult) { ASSERT(pThreadState->m_pAlternateWndInit == NULL); } pThreadState->m_pAlternateWndInit = NULL; // WINBUG: Second part of special case for file open/save dialog. if (bEnableParent) ::EnableWindow(m_ofnEx.hwndOwner, TRUE); if (::IsWindow(hWndFocus)) ::SetFocus(hWndFocus); PostModal(); return nResult ? nResult : IDCANCEL; }
INT_PTR C_PrintDialogEx::DoModal() { ASSERT_VALID(this); m_pd.hwndOwner = PreModal(); AfxUnhookWindowCreate(); // expand m_pd data into the PRINTDLGEX structure m_pdex.hwndOwner = m_pd.hwndOwner; m_pdex.hDevMode = m_pd.hDevMode; m_pdex.hDevNames = m_pd.hDevNames; m_pdex.hDC = m_pd.hDC; // m_pdex.Flags = (m_pd.Flags & ~(PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP)); m_pdex.nMinPage = m_pd.nMinPage; m_pdex.nMaxPage = m_pd.nMaxPage; m_pdex.hInstance = m_pd.hInstance; m_pdex.nStartPage = START_PAGE_GENERAL; m_pdex.nCopies = m_pd.nCopies; m_pdex.lpCallback = &m_xPrintDialogCallback; // initialize page ranges PRINTPAGERANGE ourPageRange; if (m_pdex.Flags & PD_NOPAGENUMS) { m_pdex.lpPageRanges = NULL; m_pdex.nPageRanges = 0; m_pdex.nMaxPageRanges = 0; } else { ourPageRange.nFromPage = m_pd.nFromPage; ourPageRange.nToPage = m_pd.nToPage; m_pdex.nPageRanges = 1; m_pdex.nMaxPageRanges = 1; m_pdex.lpPageRanges = &ourPageRange; } HMODULE hCommDlg = GetModuleHandleA("COMDLG32.DLL"); HRESULT (STDAPICALLTYPE* pfn)(LPPRINTDLGEX); #ifdef UNICODE pfn = (HRESULT (STDAPICALLTYPE*)(LPPRINTDLGEX)) GetProcAddress(hCommDlg, "PrintDlgExW"); #else pfn = (HRESULT (STDAPICALLTYPE*)(LPPRINTDLGEX)) GetProcAddress(hCommDlg, "PrintDlgExA"); #endif HRESULT hResult = E_NOTIMPL; if (pfn != NULL) { _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); ASSERT(pThreadState->m_pAlternateWndInit == NULL); pThreadState->m_pAlternateWndInit = this; hResult = pfn(&m_pdex); if (SUCCEEDED(hResult)) ASSERT(pThreadState->m_pAlternateWndInit == NULL); pThreadState->m_pAlternateWndInit = NULL; } // pull data back... PostModal(); if (!(m_pdex.Flags & PD_NOPAGENUMS)) { m_pd.nToPage = (WORD) m_pdex.lpPageRanges->nToPage; m_pd.nFromPage = (WORD) m_pdex.lpPageRanges->nFromPage; m_pd.nMinPage = (WORD) m_pdex.nMinPage; m_pd.nMaxPage = (WORD) m_pdex.nMaxPage; } m_pd.hDevMode = m_pdex.hDevMode; m_pd.hDevNames = m_pdex.hDevNames; m_pd.hDC = m_pdex.hDC; m_pd.nCopies = (WORD)m_pdex.nCopies; // calculate return code int nResult = IDCANCEL; if (SUCCEEDED(hResult)) { if (m_pdex.dwResultAction == PD_RESULT_PRINT) nResult = IDOK; } return nResult; }
INT_PTR CMyFileDialog::DoModal() { // From MFC: CFileDialog::DoModal // Uses the OpenFileNameEx structure on Win2k+ set<CWnd*> disabled; theApp.DisableTopLevelWindows(disabled); ASSERT_VALID(this); ASSERT((m_ofn.Flags & OFN_EXPLORER) != 0); ASSERT((m_ofn.Flags & OFN_ENABLEHOOK) == 0); ASSERT(m_ofn.lpfnHook == NULL); // Not using hooks // zero out the file buffer for consistent parsing later ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile)); DWORD nOffset = lstrlen(m_ofn.lpstrFile) + 1; ASSERT(nOffset <= m_ofn.nMaxFile); ZeroMemory(m_ofn.lpstrFile + nOffset, (m_ofn.nMaxFile - nOffset)*sizeof(TCHAR)); // WINBUG: This is a special case for the file open/save dialog, // which sometimes pumps while it is coming up but before it has // disabled the main window. HWND hWndFocus = ::GetFocus(); BOOL bEnableParent = FALSE; m_ofn.hwndOwner = PreModal(); if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner)) { bEnableParent = TRUE; ::EnableWindow(m_ofn.hwndOwner, FALSE); } AfxUnhookWindowCreate(); _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); ASSERT(pThreadState->m_pAlternateWndInit == NULL); pThreadState->m_pAlternateWndInit = this; // Install our own hook to subclass the file dialog MyFileDialogData* pMyData = _myFileDlgData.GetData(); ASSERT(pMyData->hHook == NULL); pMyData->hHook = ::SetWindowsHookEx(WH_CBT, &HookProc, NULL, ::GetCurrentThreadId()); int nResult; if (m_bOpenFileDialog) nResult = ::GetOpenFileName(&m_ofn); else nResult = ::GetSaveFileName(&m_ofn); if (nResult) ASSERT(pThreadState->m_pAlternateWndInit == NULL); pThreadState->m_pAlternateWndInit = NULL; ::UnhookWindowsHookEx(pMyData->hHook); pMyData->hHook = NULL; // WINBUG: Second part of special case for file open/save dialog. if (bEnableParent) ::EnableWindow(m_ofn.hwndOwner, TRUE); if (::IsWindow(hWndFocus)) ::SetFocus(hWndFocus); PostModal(); theApp.EnableWindows(disabled); return nResult ? nResult : IDCANCEL; }