Ejemplo n.º 1
0
BOOL CitbookApp::InitInstance()
{
	//--------程序只运行一个实例-------------------------

	HANDLE m_hMutex = ::CreateMutex(NULL, TRUE, _T("itbookone"));
    if (GetLastError() == ERROR_ALREADY_EXISTS) //程序已经运行
    {
        HWND   oldHWnd = NULL;   
        oldHWnd = ::FindWindow(NULL, _T("ItBaby笔记管理")); //查找已经运行的程序
        if (oldHWnd)   
        {   
			  AfxMessageBox(_T("程序已运行"));
            ::ShowWindow(oldHWnd, SW_SHOWNORMAL); //激活显示找到的已运行的程序
            ::SetForegroundWindow(oldHWnd);       //将已运行的程序设置为当前窗口
        }  
        CloseHandle(m_hMutex);
        m_hMutex = NULL;
        return FALSE;
    }
	//-------------------------------------------------------------

	//创建删除线程
	AfxBeginThread(DeleteTemp,(LPVOID)123);
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// 初始化 OLE 库
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}
	AfxEnableControlContainer();
	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("ItBook笔记管理"));
	LoadStdProfileSettings(4);  // 加载标准 INI 文件选项(包括 MRU)
	// 注册应用程序的文档模板。文档模板
	// 将用作文档、框架窗口和视图之间的连接
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(IDR_itbookTYPE,
		RUNTIME_CLASS(CitbookDoc),
		RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
		RUNTIME_CLASS(CitbookView));
	if (!pDocTemplate)
		return FALSE;
	pDocTemplate->SetContainerInfo(IDR_itbookTYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);
	
	pDocTemplate=new CMultiDocTemplate(IDR_txtTYPE,
			RUNTIME_CLASS(CtxtDoc),
			RUNTIME_CLASS(CChildFrame),
			RUNTIME_CLASS(CdlTxtView));
	pDocTemplate->SetContainerInfo(IDR_itbookTYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	// 创建主 MDI 框架窗口
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
	{
		delete pMainFrame;
		return FALSE;
	}
	m_pMainWnd = pMainFrame;
	// 仅当具有后缀时才调用 DragAcceptFiles
	//  在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生
	// 启用拖/放
	m_pMainWnd->DragAcceptFiles();

	// 启用“DDE 执行”
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// 分析标准外壳命令、DDE、打开文件操作的命令行
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	//if (!ProcessShellCommand(cmdInfo))
	//	return FALSE;


	// 调度在命令行中指定的命令。如果
	// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	// 主窗口已初始化,因此显示它并对其进行更新
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();


	return TRUE;
}
Ejemplo n.º 2
0
BOOL KSceneEditorApp::InitInstance()
{
    BOOL                        bResult             = false;
	BOOL                        bRetCode            = false;
	HRESULT                     hr                  = E_FAIL;
    char*                       pszRetCWD           = NULL;
    IRecorderFactory*           piRecorderFactory   = NULL;
    CMultiDocTemplate*          pDocTemplate        = NULL;
    MFCFramework::CMainFrame*   pMainFrame    = NULL;
    KGLOG_PARAM                 LogParam;
    char                        szCWD[MAX_PATH];
    CCommandLineInfo            cmdInfo;

    //使用Dummper
    m_hDummperModule = LoadLibrary(_T("dumper.dll"));

    pszRetCWD = getcwd(szCWD, sizeof(szCWD));
    KGLOG_PROCESS_ERROR(pszRetCWD);

	g_SetRootPath();

    g_SetFindFileMode(TRUE);
    g_SetFilePath("");
    g_LoadPackageFiles("config.ini", "PackFile");

	memset(&LogParam, 0, sizeof(LogParam));
	snprintf(LogParam.szPath,sizeof(LogParam.szPath),"%s\\logs",szCWD);
	LogParam.szPath[sizeof(LogParam.szPath) - 1] = '\0';

	strcpy(LogParam.szIdent, "SceneEditor");
	LogParam.nMaxLineEachFile = 65536;
	LogParam.Options = (KGLOG_OPTIONS)KGLOG_OPTION_FILE;

	bRetCode = KGLogInit(LogParam, NULL);
    KGLOG_PROCESS_ERROR(bRetCode);
    m_bLogInitFlag = true;

    bRetCode = KMemory::Initialize("SceneEditor.memory");
    KGLOG_PROCESS_ERROR(bRetCode);
    m_bMemoryInitFlag = true;

	g_cEditorDirectory.Load();

	{
		TCHAR AppDir[256] = {0};
		GetCurrentDirectory(256, AppDir);
		wsprintf(g_szDefWorkDirectory,"%s\\",AppDir);
		wsprintf(g_szDefExeDirectory,"%s\\",AppDir);
	}

	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.

	// 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("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings(10);  // 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.

	
	pDocTemplate = new CMultiDocTemplate(
		IDR_SCENEETYPE,
		RUNTIME_CLASS(KSceneEditorDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(KSceneEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_MESHETYPE,
		RUNTIME_CLASS(KSceneModelEditorDoc),
		RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneModelEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDS_OBJECTTYPE,
		RUNTIME_CLASS(KSceneObjectEditorDoc),
		RUNTIME_CLASS(KSceneObjectEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneObjectEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_SFXEDITOR,
		RUNTIME_CLASS(KSceneSFXEditorDoc),
		RUNTIME_CLASS(KSceneSFXEditorFrame), // custom MDI child frame
		RUNTIME_CLASS(KSceneSFXEditorView));
	pDocTemplate->SetContainerInfo(IDR_SFXEDITOR);
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_MODELTYPE,
		RUNTIME_CLASS(KSceneModelEditorDoc),
		RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneModelEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDS_DATAFLOWFILE,
		RUNTIME_CLASS(KSceneDataFlowEditorDoc),
		RUNTIME_CLASS(KScneDataFlowEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneDataFlowEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

    pDocTemplate = new CMultiDocTemplate(
        IDR_PVSTYPE,
        RUNTIME_CLASS(KPvsEditorDoc),
        RUNTIME_CLASS(KPvsEditorFrame), // custom MDI child frame
        RUNTIME_CLASS(KPvsEditorView));
    pDocTemplate->SetContainerInfo(IDR_PVSTYPE);
    AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_MODELTYPE2,
		RUNTIME_CLASS(KSceneModelEditorDoc),
		RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneModelEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDR_SPEEDTREETYPE,
		RUNTIME_CLASS(KSceneModelEditorDoc),
		RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneModelEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_MODELTYPE3,
		RUNTIME_CLASS(KSceneModelEditorDoc),
		RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame
		RUNTIME_CLASS(KSceneModelEditorView));
	pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	pMainFrame = new MFCFramework::CMainFrame;
    bRetCode = pMainFrame->LoadFrame(IDR_SCENEETYPE);
    KGLOG_PROCESS_ERROR(bRetCode);

    m_pMainWnd = pMainFrame;


	//(by dengzhihui 2006年12月7日 15:48:16
	extern BYTE* g_SceneEditorKeyState;//键盘状态 
	ZeroMemory(g_SceneEditorKeyState,sizeof(BYTE)*256);
	//)

	// Parse command line for standard shell commands, DDE, file open
	
	ParseCommandLine(cmdInfo);

	// 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(SW_MAXIMIZE); 
	pMainFrame->UpdateWindow();
    
    g_pEngineManager->GetUseSO3Logical(&g_bUseSO3Logical);
	if (g_bUseSO3Logical)
	{
        piRecorderFactory = CreateRecorderFactoryInterface(ermNormal);
        KGLOG_PROCESS_ERROR(piRecorderFactory);

        g_pSO3World = new KSO3World;
        KGLOG_PROCESS_ERROR(g_pSO3World);
        
        bRetCode = g_pSO3World->Init(piRecorderFactory);
        KGLOG_PROCESS_ERROR(bRetCode);
        m_bGameWorldOpenFlag = true;

        if (InitRepresent() && InitUI())
        {
            HWND hWnd = NULL;

            g_SetGameWorldUIHandler(&g_pUI->GetGameWorldUIHandler());
            g_SetGameWorldRepresentHandler(g_pRepresent->GetGameWorldRepresentHandler());
            g_pRepresentHandler = g_pRepresent->GetRepresentHandelr();

            g_pRepresent->GetRepresentHandelr()->AttachGameWorld(g_pSO3World, QuerySO3WorldClientInterface());
            g_pRepresent->GetRepresentHandelr()->Attach3DEngine(g_GetEngineIEInterface(), g_pEngineManager->Get3DModelTable(), g_pEngineManager->Get3DUI());
            g_pRepresent->GetRepresentHandelr()->AttachUI(g_pUI, &g_pUI->GetGameWorldUIHandler());

            g_pEngineManager->GetBaseWnd(&hWnd);
            g_pRepresent->GetRepresentHandelr()->InitHWND(hWnd);
            if (!g_pRepresent->Init())
            {
                ::MessageBox(NULL, "表现逻辑初始化失败!", NULL, 0);
            }
        }
	}

	//创建声音
	g_pSoundShell = Create3DSoundShell();
	if (!g_pSoundShell)
	{
		KGLogPrintf(KGLOG_WARNING, "声音创建失败.");
	}
	else
	{
		g_pSoundShell->Init(m_pMainWnd->GetSafeHwnd());
	}

	//在这里把需要使用sound的地方都统一设置上soundshell
	g_pEngineManager->SetSoundShell(g_pSoundShell);
	if (g_pRepresent)
	{
		g_pRepresent->SetSoundShell(g_pSoundShell);
	}

    bResult = true;
Exit0:
    if (!bResult)
    {
        if (m_bGameWorldOpenFlag)
        {
            g_pSO3World->UnInit();
            m_bGameWorldOpenFlag = false;
        }

        KG_DELETE(g_pSO3World);

        if (m_bMemoryInitFlag)
        {
            KMemory::Finalize();
            m_bMemoryInitFlag = false;
        }

        if (m_bLogInitFlag)
        {
            KGLogUnInit(NULL);
            m_bLogInitFlag = false;
        }
    }
    KG_COM_RELEASE(piRecorderFactory);
	return bResult;
}
Ejemplo n.º 3
0
BOOL COleClientApp::InitInstance()
{
#if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
	// turn on extra memory tracking
	afxMemDF |= checkAlwaysMemDF;
#endif

	// Initialize OLE 2.0 libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_AFXOLEINIT_FAILED);
		return FALSE;
	}

	// Standard initialization
	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register document templates
	CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(IDR_OCLIENTTYPE,
			RUNTIME_CLASS(CMainDoc),
			RUNTIME_CLASS(CSplitFrame),
			RUNTIME_CLASS(CMainView));
	pDocTemplate->SetContainerInfo(IDR_OCLIENTTYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
	{
		delete pMainFrame;
		return FALSE;
	}
	m_pMainWnd = pMainFrame;

	// enable file manager drag/drop and DDE Execute open
	m_pMainWnd->DragAcceptFiles();

	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// connect the COleTemplate server to the document template
	m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
	COleTemplateServer::RegisterAll();
		// Note: MDI applications register all class objects regardless of
		//  the /Embedding on the command line.

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (RunEmbedded())
	{
		// application was run with /Embedding flag.  Instead of showing
		//  the window, the application waits to receive OLE requests.
		return TRUE;
	}
	// always update system registry when run non-embedded
	m_server.UpdateRegistry(OAT_CONTAINER);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}
Ejemplo n.º 4
0
BOOL CTenguEditorApp::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);

	CWinAppEx::InitInstance();

	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return 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
	// 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("Local AppWizard-Generated Applications"));
	LoadStdProfileSettings(6);  // Load standard INI file options (including MRU)

	InitContextMenuManager();

	InitKeyboardManager();

	InitTooltipManager();
	CMFCToolTipInfo ttParams;
	ttParams.m_bVislManagerTheme = TRUE;
	theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
		RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(IDR_TenguEditorTYPE,
		RUNTIME_CLASS(CTenguEditorDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CTenguEditorView));
	if (!pDocTemplate)
		return FALSE;
	pDocTemplate->SetContainerInfo(IDR_TenguEditorTYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
	{
		delete pMainFrame;
		return FALSE;
	}
	m_pMainWnd = pMainFrame;
	// call DragAcceptFiles only if there's a suffix
	//  In an MDI app, this should occur immediately after setting m_pMainWnd
	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);


	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	// The main window has been initialized, so show and update it
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}