| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- // Guard.cpp : 定义应用程序的类行为。
- //
- #include "stdafx.h"
- #include "Guard.h"
- #include "Config.h"
- #include "DisplayWnd.h"
- #include "AutoStart.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CGuardApp
- BEGIN_MESSAGE_MAP(CGuardApp, CWinApp)
- ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
- END_MESSAGE_MAP()
- // CGuardApp 构造
- CGuardApp::CGuardApp()
- {
- // TODO: 在此处添加构造代码,
- // 将所有重要的初始化放置在 InitInstance 中
- }
- // 唯一的一个 CGuardApp 对象
- CGuardApp theApp;
- // CGuardApp 初始化
- BOOL CGuardApp::InitInstance()
- {
- #ifndef _DEBUG
- SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
- #endif
- // 禁止多个实例的同时运行
- HANDLE hMutexOneInstance = ::CreateMutex(NULL, TRUE, _T(AfxGetAppName()));
- if(::GetLastError() == ERROR_ALREADY_EXISTS)
- {
- if(hMutexOneInstance) // Release the mutex
- {
- ::ReleaseMutex(hMutexOneInstance);
- }
- HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
- while(::IsWindow(hWndPrevious))
- {
- // 检查窗口是否有预设的标记? 有,则是我们寻找的主窗口
- if(::GetProp(hWndPrevious, m_pszAppName))
- {
- // 主窗口已最小化,则恢复其大小
- if(::IsIconic(hWndPrevious)) ::ShowWindow(hWndPrevious, SW_RESTORE);
- ::SetForegroundWindow(hWndPrevious); // 将主窗激活
- ::SetForegroundWindow(::GetLastActivePopup(hWndPrevious)); // 将主窗的对话框激活
- return FALSE;
- } // end if
- hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT); // 继续寻找下一个窗口
- } // end while
- } // end if
- // 如果一个运行在 Windows XP 上的应用程序清单指定要
- // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
- //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
- INITCOMMONCONTROLSEX InitCtrls;
- InitCtrls.dwSize = sizeof(InitCtrls);
- // 将它设置为包括所有要在应用程序中使用的
- // 公共控件类。
- InitCtrls.dwICC = ICC_WIN95_CLASSES;
- InitCommonControlsEx(&InitCtrls);
- CWinApp::InitInstance();
- // 标准初始化
- // 如果未使用这些功能并希望减小
- // 最终可执行文件的大小,则应移除下列
- // 不需要的特定初始化例程
- // 更改用于存储设置的注册表项
- // TODO: 应适当修改该字符串,
- // 例如修改为公司或组织名
- SetRegistryKey(_T("Guard"));
- // 加载配置
- if(!CConfig::load())
- {
- AfxMessageBox(_T("加载配置信息失败"));
- return FALSE;
- }
- if (AutoStart::GetInstance()->StartAll())
- {
- }
- CDisplayWnd* pDisWnd = (CDisplayWnd *)RUNTIME_CLASS(CDisplayWnd)->CreateObject();
- m_pMainWnd = pDisWnd;
- pDisWnd->Show();
- return TRUE;
- }
|