// Another example //CWinApp-derived class BOOL CCMFCAutomationApp::InitInstance() { CWinApp::InitInstance(); // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } CWinThread* pThread = AfxGetThread(); if (pThread != NULL) { // Destroy message filter, thereby unregistering it. delete pThread->m_pMessageFilter; pThread->m_pMessageFilter = NULL; // Create the new message filter object. //CMyMessageFilter is derived from COleMessageFilter pThread->m_pMessageFilter = new CMyMessageFilter; ASSERT(AfxOleGetMessageFilter() != NULL); // Register the new message filter object. AfxOleGetMessageFilter()->Register(); }
BOOL AFXAPI AfxOleInit() { _AFX_THREAD_STATE* pState = AfxGetThreadState(); ASSERT(!pState->m_bNeedTerm); // calling it twice? // Special case DLL context to assume that the calling app initializes OLE. // For DLLs where this is not the case, those DLLs will need to initialize // OLE for themselves via OleInitialize. This is done since MFC cannot provide // automatic uninitialize for DLLs because it is not valid to shutdown OLE // during a DLL_PROCESS_DETACH. if (afxContextIsDLL) { pState->m_bNeedTerm = -1; // -1 is a special flag return TRUE; } // first, initialize OLE SCODE sc = ::OleInitialize(NULL); if (FAILED(sc)) { // warn about non-NULL success codes TRACE1("Warning: OleInitialize returned scode = %s.\n", AfxGetFullScodeString(sc)); goto InitFailed; } // termination required when OleInitialize does not fail pState->m_bNeedTerm = TRUE; // hook idle time and exit time for required OLE cleanup CWinThread* pThread; pThread = AfxGetThread(); pThread->m_lpfnOleTermOrFreeLib = AfxOleTermOrFreeLib; // allocate and initialize default message filter if (pThread->m_pMessageFilter == NULL) { pThread->m_pMessageFilter = new COleMessageFilter; ASSERT(AfxOleGetMessageFilter() != NULL); AfxOleGetMessageFilter()->Register(); } return TRUE; InitFailed: AfxOleTerm(); return FALSE; }
Bool CSampleApp::InitInstance() { // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } // CT: нрйкчвемхе дхюкнцю х яннаыемхъ на хявепоюмхх нфхдюмхъ нрберю яепбепю COleMessageFilter* pFilter = AfxOleGetMessageFilter(); ASSERT_VALID(pFilter); pFilter->SetMessagePendingDelay( -1 ); pFilter->EnableNotRespondingDialog(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. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Parse the command line to see if launched as OLE server if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); } else { // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); } CSampleDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
void CWordPadDoc::Serialize(CArchive& ar) { COleMessageFilter* pFilter = AfxOleGetMessageFilter(); ASSERT(pFilter != NULL); pFilter->EnableBusyDialog(FALSE); if (ar.IsLoading()) SetDocType(m_nNewDocType); CRichEditDoc::Serialize(ar); pFilter->EnableBusyDialog(TRUE); }
// @pymethod |win32uiole|EnableBusyDialog| static PyObject *win32uiole_EnableBusyDialog(PyObject *self, PyObject *args) { // @pyparm bool|enabled|| int enabled; if (!PyArg_ParseTuple(args, "i", &enabled)) return NULL; AfxOleGetMessageFilter()->EnableBusyDialog(enabled); Py_INCREF(Py_None); return Py_None; }
// @pymethod |win32uiole|SetMessagePendingDelay| static PyObject *win32uiole_SetMessagePendingDelay(PyObject *self, PyObject *args) { // @pyparm int|delay|| int delay; if (!PyArg_ParseTuple(args, "i", &delay)) return NULL; AfxOleGetMessageFilter()->SetMessagePendingDelay(delay); Py_INCREF(Py_None); return Py_None; }
BOOL CRichEditCtrl::CanPaste(UINT nFormat) const { ASSERT(::IsWindow(m_hWnd)); COleMessageFilter* pFilter = AfxOleGetMessageFilter(); if (pFilter != NULL) pFilter->BeginBusyState(); BOOL b = (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, nFormat, 0L); if (pFilter != NULL) pFilter->EndBusyState(); return b; }
bool CRemoteGraphForm::SpyDoPropertyFrameModal(IMoniker* pMoniker) { ATLASSERT(pMoniker); _ATLTRY { CComPtr<IRunningObjectTable> pRunningObjectTable; ATLENSURE_SUCCEEDED(GetRunningObjectTable(0, &pRunningObjectTable)); CComPtr<IBindCtx> pBindCtx; ATLENSURE_SUCCEEDED(CreateBindCtx(0, &pBindCtx)); CComPtr<IUnknown> pUnknown; ATLENSURE_SUCCEEDED(pRunningObjectTable->GetObject(sel_graph.moniker, &pUnknown)); // NOTE: Doing IDispatch::Invoke to not reference/import external TLB and be dependent from it while building class __declspec(uuid("6945711B-FE0F-4C54-965F-5B67969C28B7")) ISpy; // Alax.Info DirectShowSpy's ISpy const CComQIPtr<IDispatch, &__uuidof(ISpy)> pSpyDispatch = pUnknown; if(!pSpyDispatch) return false; ATLASSERT(pSpyDispatch); // [id(4)] HRESULT DoPropertyFrameModal([in] LONG nParentWindowHandle); CComVariant vParentWindowHandle((LONG) (LONG_PTR) m_hWnd); DISPPARAMS pParameters[1]; ZeroMemory(pParameters, sizeof pParameters); pParameters[0].cArgs = 1; pParameters[0].rgvarg = &vParentWindowHandle; CComVariant vResult; // NOTE: https://support.microsoft.com/kb/248019/en?wa=wsignin1.0 AfxOleGetMessageFilter()->EnableNotRespondingDialog(FALSE); const HRESULT nResult = pSpyDispatch->Invoke(4, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, pParameters, &vResult, NULL, NULL); AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE); ATLENSURE_SUCCEEDED(nResult); } _ATLCATCHALL() { MessageBeep(MB_ICONERROR); return false; } return true; }
BOOL CDiskInfoApp::InitInstance() { BOOL flagEarthlight = FALSE; BOOL flagStartupExit = FALSE; m_FlagCopyExit = FALSE; int defaultDisk = -1; HANDLE hMutex = NULL; INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); // IE Version Check. /* if(GetFileVersion(_T("Shdocvw.dll")) < 471) { AfxMessageBox(_T("CrystalDiskInfo is required IE 6.0 or later.")); } */ // CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // for WMI error SetErrorMode(SEM_FAILCRITICALERRORS); // Init m_Ini TCHAR *ptrEnd; TCHAR ini[MAX_PATH]; ::GetModuleFileName(NULL, ini, MAX_PATH); if((ptrEnd = _tcsrchr(ini, '.')) != NULL) { *ptrEnd = '\0'; _tcscat_s(ini, MAX_PATH, _T(".ini")); } m_Ini = ini; #ifdef SUISHO_SHIZUKU_SUPPORT m_Ini.Replace(_T("DiskInfoS.ini"), _T("DiskInfo.ini")); m_Ini.Replace(_T("DiskInfoSx64.ini"), _T("DiskInfoX64.ini")); #endif CString cstr; DWORD debugMode = GetPrivateProfileInt(_T("Setting"), _T("DebugMode"), 0, m_Ini); SetDebugMode(debugMode); cstr.Format(_T("%d"), debugMode); WritePrivateProfileString(_T("Setting"), _T("DebugMode"), cstr, m_Ini); int argc = 0; int index = 0; LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); if(argc > 1) { CString cstr; cstr = argv[1]; if(cstr.CompareNoCase(_T("/Earthlight")) == 0) { flagEarthlight = TRUE; if(argc > 2) { defaultDisk = _tstoi(argv[2]); } } if(cstr.CompareNoCase(_T("/Startup")) == 0) { int time = 0; time = GetPrivateProfileInt(_T("Setting"), _T("StartupWaitTime"), 30, m_Ini); if(time >= 0) { Sleep(time * 1000); } TCHAR str[MAX_PATH]; ::GetModuleFileName(NULL, str, MAX_PATH); ShellExecute(NULL, NULL, str, NULL, NULL, SW_SHOWNORMAL); return FALSE; } if(cstr.CompareNoCase(_T("/Exit")) == 0) { flagStartupExit = TRUE; } if(cstr.CompareNoCase(_T("/Copy")) == 0) { m_SaveAsText = m_Ini; m_SaveAsText.Replace(_T("ini"), _T("txt")); } if(cstr.CompareNoCase(_T("/CopyExit")) == 0) { m_SaveAsText = m_Ini; m_SaveAsText.Replace(_T("ini"), _T("txt")); m_FlagCopyExit = TRUE; } } // DEBUG // flagEarthlight = TRUE; if(! flagEarthlight) { DebugPrint(_T("CreateMutex")); hMutex = ::CreateMutex(NULL, FALSE, PROJECT_NAME); if(GetLastError() == ERROR_ALREADY_EXISTS) { DebugPrint(_T("ERROR_ALREADY_EXISTS")); return FALSE; } } CString DefaultTheme; CString DefaultLanguage; TCHAR tmp[MAX_PATH]; GetModuleFileName(NULL, tmp, MAX_PATH); if((ptrEnd = _tcsrchr(tmp, '\\')) != NULL) { *ptrEnd = '\0'; } m_ExeDir.Format(_T("%s\\"), tmp); m_ThemeDir.Format(_T("%s\\%s"), tmp, THEME_DIR); m_LangDir.Format(_T("%s\\%s"), tmp, LANGUAGE_DIR); m_SmartDir.Format(_T("%s\\%s"), tmp, SMART_DIR); m_GadgetDir.Format(_T("%s\\%s"), tmp, GADGET_DIR); if(IsDotNet4()) { m_AlertMailPath.Format(_T("%s\\%s"), tmp, ALERT_MAIL_4_PATH); } else if(IsDotNet2()) { m_AlertMailPath.Format(_T("%s\\%s"), tmp, ALERT_MAIL_PATH); } else { m_AlertMailPath = _T(""); } m_OpusDecPath.Format(_T("%s\\%s"), tmp, OPUS_DEC_PATH); #ifdef SUISHO_SHIZUKU_SUPPORT m_ShizukuVoicePath.Format(_T("%s\\%s"), tmp, SHIZUKU_VOICE_PATH); #endif m_ThemeIndex = MENU_THEME_INDEX; m_LangIndex = MENU_LANG_INDEX; DefaultTheme.Format(_T("%s\\%s"), tmp, DEFAULT_THEME); DefaultLanguage.Format(_T("%s\\%s"), tmp, DEFAULT_LANGUAGE); OSVERSIONINFOEX osvi; BOOL bosVersionInfoEx; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if(!(bosVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi))) { osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx((OSVERSIONINFO *)&osvi); } if((BOOL)GetPrivateProfileInt(_T("Workaround"), _T("IE8MODE"), 0, m_Ini)) { m_GraphDlgPath.Format(_T("%s\\") DIALOG_DIR GRAPH_DIALOG_IE8, tmp); if(! IsFileExistEx(m_GraphDlgPath, GRAPH_DIALOG_IE8)) { return FALSE; } } else { m_GraphDlgPath.Format(_T("%s\\") DIALOG_DIR GRAPH_DIALOG, tmp); if(! IsFileExistEx(m_GraphDlgPath, GRAPH_DIALOG)) { return FALSE; } } m_OptionDlgPath.Format(_T("%s\\") DIALOG_DIR OPTION_DIALOG, tmp); // if(! IsFileExistEx(DefaultTheme, DEFAULT_THEME)) { return FALSE; } if(! IsFileExistEx(DefaultLanguage, DEFAULT_LANGUAGE)) { return FALSE; } // for Windows NT family #ifdef _UNICODE if(! IsCurrentUserLocalAdministrator()) { if(osvi.dwMajorVersion < 6) { AfxMessageBox(_T("CrystalDiskInfo is required Administrator Privileges.")); } RunAsRestart(); return FALSE; } #endif BOOL flagAfxOleInit = FALSE; if(flagEarthlight) { CGraphDlg dlg(NULL, defaultDisk); m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); } else { // No Server Busy Dialog!! DebugPrint(_T("AfxOleInit()")); if(AfxOleInit()) { flagAfxOleInit = TRUE; DebugPrint(_T("AfxOleGetMessageFilter()->SetMessagePendingDelay")); AfxOleGetMessageFilter()->SetMessagePendingDelay(60 * 1000); DebugPrint(_T("AfxOleGetMessageFilter()->EnableNotRespondingDialog(FALSE)")); AfxOleGetMessageFilter()->EnableNotRespondingDialog(FALSE); DebugPrint(_T("AfxOleGetMessageFilter()->EnableBusyDialog(FALSE)")); AfxOleGetMessageFilter()->EnableBusyDialog(FALSE); } else { DebugPrint(_T("CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);")); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); } CDiskInfoDlg dlg(NULL, flagStartupExit); m_pMainWnd = &dlg; BOOL flagReExec = FALSE; DebugPrint(_T("dlg.DoModal()")); if(dlg.DoModal() == RE_EXEC) { flagReExec = TRUE; } ::ReleaseMutex(hMutex); ::CloseHandle(hMutex); if(flagReExec) { TCHAR str[MAX_PATH]; ::GetModuleFileName(NULL, str, MAX_PATH); ShellExecute(NULL, NULL, str, NULL, NULL, SW_SHOWNORMAL); } } if(! flagAfxOleInit) { DebugPrint(_T("CoUninitialize();")); CoUninitialize(); } return FALSE; }
BOOL CSTEditorApp::InitInstance() { HRESULT hr; COleMessageFilter *pFilter; USES_CONVERSION; #ifdef STEDITOR_DEBUG DebugBreak(); #endif // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } hr = ::CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); assert (SUCCEEDED (hr)); pFilter = AfxOleGetMessageFilter (); assert (pFilter); if (pFilter != NULL) { pFilter->EnableNotRespondingDialog (FALSE); pFilter->EnableBusyDialog (FALSE); }; AfxEnableControlContainer(); // 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. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif _Module.Init (ObjectMap, m_hInstance); // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey (_T("Softing\\4CONTROLV2\\4CONTROL Engineering")); // keywords are case insensitive // AUTOFMT 08.08.06 SIS >> InitRegistry(); // AUTOFMT 08.08.06 SIS << LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. m_pDocTemplate = new CMultiDocTemplate( IDR_STTYPE, RUNTIME_CLASS(CSTEditorDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CSTEditorView)); m_pDocTemplate->SetServerInfo( IDR_STTYPE_SRVR_EMB, IDR_STTYPE_SRVR_IP, RUNTIME_CLASS(CInPlaceFrame)); AddDocTemplate(m_pDocTemplate); // 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, m_pDocTemplate, FALSE); // Register all OLE server factories as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); // Note: MDI applications register all server objects without regard // to the /Embedding or /Automation on the command line. // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Enable drag/drop open m_pMainWnd->DragAcceptFiles(); // Enable DDE Execute open EnableShellOpen(); RegisterShellFileTypes(TRUE); // Parse command line for standard shell commands, DDE, file open CSTCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Check to see if launched as OLE server if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { // Application was run with /Embedding or /Automation. Don't show the // main window in this case. return TRUE; } // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER); COleObjectFactory::UpdateRegistryAll(); if (cmdInfo.m_bRegServer) { TCHAR szModule[_MAX_PATH+10]; LPOLESTR pszModule; HRESULT hr; LPTYPELIB pTypeLib; USES_CONVERSION; ::GetModuleFileName (m_hInstance, szModule, _MAX_PATH); pszModule = T2OLE (szModule); hr = LoadTypeLib (pszModule, &pTypeLib); if (SUCCEEDED (hr)) { hr = RegisterTypeLib (pTypeLib, pszModule, NULL); pTypeLib->Release (); }; return (FALSE); }; // Prevents ProcessShellCommand from displaying // a message box when unregistering. if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { cmdInfo.m_bRunEmbedded = true; }; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; }
BOOL CExplorerXPApp::InitInstance() { InOut log (TEXT("CExplorerXPApp::InitInstance")); // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); AfxOleInit(); AfxEnableControlContainer(); InitContextMenuManager(); InitShellManager(); InitThemes(); COleMessageFilter *pfilter = AfxOleGetMessageFilter(); if (pfilter) { pfilter->EnableBusyDialog(FALSE); pfilter->EnableNotRespondingDialog(FALSE); } RegisterShellClipboardFormats (); /*HINSTANCE hInstance = LoadLibrary(_T("Bulgarian.dll")); if( hInstance ) { AfxSetResourceHandle( hInstance ); } */ InitSoftwareLogPath (); gOptions.Load (); gFolderStateMan.Load(); gGroupManager.Load (); dirs.Load(); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; ParseCommandLine(cmdInfo); if ( !m_SingleInstance.Create( IDR_MAINFRAME, cmdInfo) ) 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. // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("ExplorerXP")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_EXPLORTYPE, RUNTIME_CLASS(CExplorerXPDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CExplorerXPView)); AddDocTemplate(pDocTemplate); CMainFrame* pMainFrame = new CMainFrame; { InOut log2 (_T("Mainframe:Load")); // create main MDI Frame window if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; } m_pMainWnd = pMainFrame; // Dispatch commands specified on the command line // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); { InOut log2(_T("MainFrame->FillTree ")); // pMainFrame->FillTree (); } LoadFilters (); dirs.Start (); LoadDefaultTabs(); gShortcutManager.Initialize (); gShortcutManager.LoadAccel(IDR_MAINFRAME); if (!cmdInfo.m_strFileName.IsEmpty ()) { // //AfxMessageBox (cmdInfo.m_strFileName); if (cmdInfo.m_strFileName[cmdInfo.m_strFileName.GetLength() -1] == _T('\"')) cmdInfo.m_strFileName.Delete (cmdInfo.m_strFileName.GetLength() -1); OpenFolder (cmdInfo.m_strFileName); } pMainFrame->RepositionMDIChildsInitial (); return TRUE; }
BOOL AFXAPI AfxOleInit() { _AFX_THREAD_STATE* pState = AfxGetThreadState(); ASSERT(!pState->m_bNeedTerm); // calling it twice? // Special case DLL context to assume that the calling app initializes OLE. // For DLLs where this is not the case, those DLLs will need to initialize // OLE for themselves via OleInitialize. This is done since MFC cannot provide // automatic uninitialize for DLLs because it is not valid to shutdown OLE // during a DLL_PROCESS_DETACH. if (afxContextIsDLL) { pState->m_bNeedTerm = -1; // -1 is a special flag return TRUE; } // first, initialize OLE SCODE sc = ::OleInitialize(NULL); if (FAILED(sc)) { // warn about non-NULL success codes TRACE1("Warning: OleInitialize returned scode = %s.\n", AfxGetFullScodeString(sc)); goto InitFailed; } // termination required when OleInitialize does not fail pState->m_bNeedTerm = TRUE; // hook idle time and exit time for required OLE cleanup CWinThread* pThread; pThread = AfxGetThread(); pThread->m_lpfnOleTermOrFreeLib = AfxOleTermOrFreeLib; // allocate and initialize default message filter if (pThread->m_pMessageFilter == NULL) { pThread->m_pMessageFilter = new COleMessageFilter; ASSERT(AfxOleGetMessageFilter() != NULL); AfxOleGetMessageFilter()->Register(); } #ifdef _MAC CWinApp* pApp; pApp = AfxGetApp(); #ifndef _WINDLL // Mac MFC uses a static version of ole2ui which must be initialized if (pState->m_bNeedTerm && !::OleUIInitialize(pApp->m_hInstance, pApp->m_hPrevInstance, SZCLASSICONBOX, SZCLASSRESULTIMAGE)) goto InitFailed; #endif _afxPfnOleAuto = NewAEEventHandlerProc(_AfxOleAutoHandler); if (_afxPfnOleAuto != NULL) { AEInstallEventHandler('OLE2', 'AUTO', _afxPfnOleAuto, (long) pApp, false); } #endif return TRUE; InitFailed: AfxOleTerm(); return FALSE; }
/*func*------------------------------------------------------------------------ description: in : out: -----------------------------------------------------------------------------*/ BOOL CGrEditorApp::InitInstance() { HRESULT hr; HFONT hFont; LOGFONT logFont; CGdiObject *pGdiObject; USES_CONVERSION; // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_GR_OLE_INIT_FAILED); return FALSE; } hr = ::CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); assert (SUCCEEDED (hr)); // prevent the Server-Busy dialog COleMessageFilter *pFilter = AfxOleGetMessageFilter(); assert (pFilter); if (pFilter != NULL) { pFilter->EnableNotRespondingDialog(FALSE); pFilter->EnableBusyDialog(FALSE); } AfxEnableControlContainer(); // 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. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif _Module.Init (ObjectMap, m_hInstance); // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey (_T ("Softing\\4CONTROLV2\\4CONTROL Engineering")); int iValue; CString strKey, strSec; strSec.LoadString(IDS_GR_REG_SECTION); strKey.LoadString(IDS_GR_REG_RUBBLINE); iValue = GetProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, 0); WriteProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, iValue ); // set Line draw mode to rubberlines strKey.LoadString(IDS_GR_REG_RUBB_RECON); iValue = GetProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, 1); WriteProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, iValue ); // set Line draw mode to rubberlines strKey.LoadString(IDS_GR_REG_ZOOMVALUE); iValue = GetProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, 100); WriteProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, iValue ); // set zoom factor for 4gr // default sizes for element insertion strKey.LoadString(IDS_GR_REG_STEPSIZE); iValue = GetProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, (4<<16)+4); // <0: AutoSize:on; HiWord:X; LoWord:Y WriteProfileInt ((LPCTSTR)strSec, (LPCTSTR)strKey, iValue ); // ST actions we yes the STEditor settings .. WriteProfileInt (_T ("ST"), _T ("Case" ), 0 ); // keywords are case insensitive WriteProfileInt (_T ("ST"), _T ("Chroma" ), 1 ); // coloring enabled WriteProfileString (_T ("ST"), _T ("Background" ), _T ("255,255,255" )); // background color white WriteProfileString (_T ("ST"), _T ("Default Text" ), _T ("0,0,0" )); // text color black WriteProfileString (_T ("ST"), _T ("Quote" ), _T ("128,128,128" )); // string color grey WriteProfileString (_T ("ST"), _T ("Comment" ), _T ("0,128,0" )); // comment color red WriteProfileString (_T ("ST"), _T ("Comment Start 1"), _T ("(*" )); // comments start with (* WriteProfileString (_T ("ST"), _T ("Comment End 1" ), _T ("*)" )); // comments end with *) WriteProfileInt (_T ("ST"), _T ("Keep Tabs" ), 0 ); // tabs are not converted to spaces WriteProfileInt (_T ("ST"), _T ("Show Tabs" ), 0 ); // tabs are not visualized WriteProfileInt (_T ("ST"), _T ("Tab Size" ), 4 ); // tab is as wide as 4 spaces WriteProfileString (_T ("ST"), _T ("Keywords" ), _T ("stkeywords.ini")); // // sizeof (LOGFONT) gives you the maximum size of a LOGFONT structure. // CGdiObject::GetObject possibly returns less because the font name // at the end of the LOGFONT structure may not take the whole space // reserved for it. hFont = (HFONT)GetStockObject (ANSI_FIXED_FONT); pGdiObject = CGdiObject::FromHandle (hFont); if (pGdiObject != NULL && pGdiObject->GetObject (sizeof (LOGFONT), &logFont) != 0) { int iFontSize; CWindowDC dc (m_pMainWnd); WriteProfileString (_T ("ST"), _T ("Font Name"), A2T (logFont.lfFaceName)); iFontSize = MulDiv (logFont.lfHeight, 72, dc.GetDeviceCaps (LOGPIXELSY)); WriteProfileInt (_T ("ST"), _T ("Font Size"), iFontSize); WriteProfileInt (_T ("ST"), _T ("Font Weight"), logFont.lfWeight); WriteProfileInt (_T ("ST"), _T ("Font Italic"), logFont.lfItalic); WriteProfileInt (_T ("ST"), _T ("CharSet"), logFont.lfCharSet); }; LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. m_pDocTemplate = new CMultiDocTemplate( IDR_GR_TYPE, RUNTIME_CLASS(CGrEditorDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CGrEditorView)); m_pDocTemplate->SetServerInfo( IDR_GR_TYPE_SRVR_EMB, IDR_GR_TYPE_SRVR_IP, RUNTIME_CLASS(CInPlaceFrame)); AddDocTemplate(m_pDocTemplate); // 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, m_pDocTemplate, FALSE); // Register all OLE server factories as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); // Note: MDI applications register all server objects without regard // to the /Embedding or /Automation on the command line. // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_GR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // create a dummy image .. to solve the problem with DeleteTempMap in OnIdle m_pDummyImage = new CImageList(); VERIFY (m_pDummyImage->Create (16, 15, TRUE, 0, 1)); CBitmap bm; bm.LoadBitmap (IDR_GR_MAINFRAME); m_pDummyImage->Add (&bm, RGB (192, 192, 192)); // Enable drag/drop open m_pMainWnd->DragAcceptFiles(); // Enable DDE Execute open EnableShellOpen(); RegisterShellFileTypes(TRUE); // Parse command line for standard shell commands, DDE, file open CSTCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Check to see if launched as OLE server if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { // Application was run with /Embedding or /Automation. Don't show the // main window in this case. return TRUE; } // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER); COleObjectFactory::UpdateRegistryAll(); if (cmdInfo.m_bRegServer) { TCHAR szModule[_MAX_PATH+10]; LPOLESTR pszModule; HRESULT hr; LPTYPELIB pTypeLib; USES_CONVERSION; ::GetModuleFileName (m_hInstance, szModule, _MAX_PATH); pszModule = T2OLE (szModule); hr = LoadTypeLib (pszModule, &pTypeLib); if (SUCCEEDED (hr)) { hr = RegisterTypeLib (pTypeLib, pszModule, NULL); pTypeLib->Release (); }; return (FALSE); }; // Prevents ProcessShellCommand from displaying // a message box when unregistering. if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { cmdInfo.m_bRunEmbedded = true; }; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; }