コード例 #1
0
ファイル: mfccalc.cpp プロジェクト: jetlive/skiaming
BOOL CCalcApp::InitInstance()
{
	// Initialize OLE 2.0 libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	// 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 2.0 libraries to create objects from other applications.
		COleTemplateServer::RegisterAll();

		// Do not continue with rest of initialization.  Wait for
		// client to create a CCalcDlg object instead.
		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.
	COleObjectFactory::UpdateRegistryAll();

	// create a modeless dialog as the main window of the application
	//This disables the warning that the dialog could leak - 
	//it will not leak since the Set Visible registers the dialog as
	//the main frame and any windows message that closes that dialog
	//causes the parent class to call the destructor
	#pragma warning( push )
	#pragma warning(disable:6014)
	CCalcDlg* pDlg = new CCalcDlg;
	#pragma warning( pop )
	pDlg->SetVisible(TRUE);
	if (!pDlg->GetVisible())
	{
		// if GetVisible fails after SetVisibile, we never registered
		// the pDlg with the parent class, and it will not be deleted
		AfxMessageBox(IDP_UNABLE_TO_SHOW_CALC);
		delete pDlg;
		return FALSE;
	}
	pDlg->RegisterActive();

	// We are using a modeless dialog so we can translate accelerator keys
	// against the dialog.  In order to run the main message pump,
	// InitInstance must return TRUE even though this application is
	// a dialog-based application.
	return TRUE;
}
コード例 #2
0
ファイル: mfccalc.cpp プロジェクト: Jinjiego/VCSamples
BOOL CCalcApp::InitInstance()
{
    // 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.
#if _MFC_VER < 0x0700
	Enable3dControls();
#endif
    // Initialize OLE 2.0 libraries
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }

	// Parse command line for automation or reg/unreg switches.
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (RunEmbedded() || RunAutomated())
    {
        // Register all OLE server (factories) as running.  This enables the 
        //  OLE 2.0 libraries to create objects from other applications.
        COleTemplateServer::RegisterAll();

        // Do not continue with rest of initialization.  Wait for
        // client to create a CCalcDlg object instead.
        return TRUE;
    }
	// App was launched with /Unregserver or /Unregister switch.  Remove
	// entries from the registry.
	else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
	{
		COleObjectFactory::UpdateRegistryAll(FALSE);
		AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor);
		return FALSE;
	}
	// App was launched standalone or with other switches (e.g. /Register
	// or /Regserver).  Update registry entries, including typelibrary.
	else
	{
		COleObjectFactory::UpdateRegistryAll();
		AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid);
		if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister)
			return FALSE;
	}

	
    // create a modeless dialog as the main window of the application
	//suppress warning because an object of CDialog is self-destructing
	#pragma warning (suppress: 6014)
    CCalcDlg* pDlg = new CCalcDlg;
    pDlg->SetVisible(TRUE);
    if (!pDlg->GetVisible())
    {
        AfxMessageBox(IDP_UNABLE_TO_SHOW_CALC);
		return FALSE;
    }
    pDlg->RegisterActive();

    // We are using a modeless dialog so we can translate accelerator keys 
    // against the dialog.  In order to run the main message pump, 
    // InitInstance must return TRUE even though this application is
    // a dialog-based application.
    return TRUE;
}