void AFXAPI AfxOleOnReleaseAllObjects() { // don't shut down the application if user is in control of the app if (AfxOleGetUserCtrl()) return; AfxOleSetUserCtrl(TRUE); // avoid re-entry // shut down the application CWinApp* pApp = AfxGetApp(); ASSERT_VALID(pApp); if (pApp->m_pMainWnd != NULL) { // destroy the main window (only if enabled) if (pApp->m_pMainWnd->IsWindowEnabled()) { // the main window will post WM_QUIT as part of its shutdown pApp->m_pMainWnd->DestroyWindow(); } } else if (!afxContextIsDLL) { // no main window, so just post WM_QUIT. AfxPostQuitMessage(0); } }
BOOL COleLinkingDoc::OnOpenDocument(LPCTSTR lpszPathName) { ASSERT_VALID(this); // always register the document before opening it Revoke(); if (!RegisterIfServerAttached(lpszPathName, FALSE)) { // always output a trace (it is just an FYI -- not generally fatal) TRACE(traceOle, 0, _T("Warning: Unable to register moniker '%s' as running\n"), lpszPathName); } if (!COleDocument::OnOpenDocument(lpszPathName)) { Revoke(); return FALSE; } // if the app was started only to print, don't set user control CWinApp* pApp = AfxGetApp(); ASSERT(pApp != NULL); if (pApp->m_pCmdInfo == NULL || (pApp->m_pCmdInfo->m_nShellCommand != CCommandLineInfo::FileDDE && pApp->m_pCmdInfo->m_nShellCommand != CCommandLineInfo::FilePrint)) { AfxOleSetUserCtrl(TRUE); } return TRUE; }
BOOL CWinApp::RunAutomated() { ASSERT(m_lpCmdLine != NULL); // hard coded non-localized name if (_AfxParseOption(m_lpCmdLine, _T("Automation"))) { AfxOleSetUserCtrl(FALSE); return TRUE; } return FALSE; // not run with /Automation }
BOOL CWinApp::RunEmbedded() { ASSERT(m_lpCmdLine != NULL); // hard coded non-localized name if (ParseOption(m_lpCmdLine, _T("Embedding"))) { AfxOleSetUserCtrl(FALSE); return TRUE; } return FALSE; // not run with /Embedding }
// @pymethod int|win32uiole|OleSetUserCtrl|Sets or clears the user control flag. static PyObject * win32uiole_set_user_ctrl(PyObject *self, PyObject *args) { BOOL flag; if (!PyArg_ParseTuple(args,"i:OleSetUserCtrl", &flag)) // @pyparm int|bUserCtrl||Specifies whether the user-control flag is to be set or cleared. return NULL; GUI_BGN_SAVE; AfxOleSetUserCtrl(flag); GUI_END_SAVE; RETURN_NONE; }
BOOL COleLinkingDoc::OnNewDocument() { ASSERT_VALID(this); Revoke(); RegisterIfServerAttached(NULL, TRUE); if (!COleDocument::OnNewDocument()) return FALSE; AfxOleSetUserCtrl(TRUE); return TRUE; }
CCmdTarget* COleTemplateServer::OnCreateObject() { ASSERT_VALID(this); ASSERT_VALID(m_pDocTemplate); // save application user control status BOOL bUserCtrl = AfxOleGetUserCtrl(); // create invisible doc/view/frame set CDocument* pDoc = m_pDocTemplate->OpenDocumentFile(NULL, FALSE); // restore application's user control status AfxOleSetUserCtrl(bUserCtrl); if (pDoc != NULL) { ASSERT_VALID(pDoc); ASSERT_KINDOF(CDocument, pDoc); // all new documents created by OLE start out modified pDoc->SetModifiedFlag(); } return pDoc; }
BOOL CWordPadApp::InitInstance() { ParseCommandLine(cmdInfo); if (::FindWindow(szWordPadClass, NULL) && IsDocOpen(cmdInfo.m_strFileName)) return FALSE; SetRegistryKey(szRegKey); LoadOptions(); Enable3dControls(); CSplashWnd splash; BOOL bSplash = cmdInfo.m_bShowSplash; if (!cmdInfo.m_bRunEmbedded) { switch (m_nCmdShow) { case SW_HIDE: case SW_SHOWMINIMIZED: case SW_MINIMIZE: case SW_SHOWMINNOACTIVE: bSplash = FALSE; break; case SW_RESTORE: case SW_SHOW: case SW_SHOWDEFAULT: case SW_SHOWNA: case SW_SHOWNOACTIVATE: case SW_SHOWNORMAL: case SW_SHOWMAXIMIZED: if (m_bMaximized) m_nCmdShow = SW_SHOWMAXIMIZED; break; } } else { //Excel 4 will start OLE servers minimized m_nCmdShow = SW_SHOWNORMAL; } int nCmdShow = m_nCmdShow; if (bSplash) { // only show splash if not embedded splash.Create(NULL); splash.ShowWindow(SW_SHOW); splash.UpdateWindow(); } LoadAbbrevStrings(); #ifdef CREATE_DEV_NAMES m_hDevNames = CreateDevNames(); #else m_hDevNames = NULL; #endif NotifyPrinterChanged((m_hDevNames == NULL)); free((void*)m_pszHelpFilePath); m_pszHelpFilePath = _T("WORDPAD.HLP"); // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } RegisterFormats(); // Initialize RichEdit control if (LoadLibrary(_T("RICHED32.DLL")) == NULL) { AfxMessageBox(IDS_RICHED_LOAD_FAIL, MB_OK|MB_ICONEXCLAMATION); return FALSE; } // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Initialize all Managers for usage. They are automatically constructed // if not yet present SetRegistryBase (_T("SettingsPro")); InitContextMenuManager(); InitKeyboardManager(); InitTooltipManager(); CMFCToolTipInfo params; params.m_bVislManagerTheme = TRUE; theApp.GetTooltipManager ()->SetTooltipParams ( 0xFFFF, RUNTIME_CLASS (CMFCToolTipCtrl), ¶ms); EnableTearOffMenus (NULL, ID_FREE_TEAROFF1, ID_FREE_TEAROFF2); // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. DocTemplate.SetContainerInfo(IDR_CNTR_INPLACE); DocTemplate.SetServerInfo( IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE, RUNTIME_CLASS(CInPlaceFrame)); // Connect the COleTemplateServer to the document template. // The COleTemplateServer creates new documents on behalf // of requesting OLE containers by using information // specified in the document template. m_server.ConnectTemplate(clsid, &DocTemplate, TRUE); // Note: SDI applications register server objects only if /Embedding // or /Automation is present on the command line. // Check to see if launched as OLE server if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); AfxOleSetUserCtrl(FALSE); // Application was run with /Embedding or /Automation. Don't show the // main window in this case. return TRUE; } // make sure the main window is showing m_bPromptForType = FALSE; OnFileNew(); m_bPromptForType = TRUE; // destroy splash window if (cmdInfo.m_bShowSplash) splash.DestroyWindow(); m_nCmdShow = -1; if (m_pMainWnd == NULL) // i.e. OnFileNew failed return FALSE; if (!cmdInfo.m_strFileName.IsEmpty()) // open an existing document m_nCmdShow = nCmdShow; // Dispatch commands specified on the command line if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew && !ProcessShellCommand(cmdInfo)) { return FALSE; } LoadCustomState (); // Enable File Manager drag/drop open m_pMainWnd->DragAcceptFiles(); // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. // do registry stuff in separate thread #ifndef _UNICODE if (m_bWin31) // no threads on Win32s UpdateRegistry(); else #endif AfxBeginThread(DoRegistry, this, THREAD_PRIORITY_IDLE); if (afxGlobalData.m_nBitsPerPixel < 16) { AfxMessageBox(IDS_WRONG_DISPLAY_SETTINGS); } // Set application general look: CAppLookDlg dlg (TRUE); dlg.DoModal (); return TRUE; }