MiddleWares_YiHe 郑州颐和医院随访系统中间件

Guard.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Guard.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "Guard.h"
  5. #include "Config.h"
  6. #include "DisplayWnd.h"
  7. #include "AutoStart.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11. // CGuardApp
  12. BEGIN_MESSAGE_MAP(CGuardApp, CWinApp)
  13. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  14. END_MESSAGE_MAP()
  15. // CGuardApp 构造
  16. CGuardApp::CGuardApp()
  17. {
  18. // TODO: 在此处添加构造代码,
  19. // 将所有重要的初始化放置在 InitInstance 中
  20. }
  21. // 唯一的一个 CGuardApp 对象
  22. CGuardApp theApp;
  23. // CGuardApp 初始化
  24. BOOL CGuardApp::InitInstance()
  25. {
  26. #ifndef _DEBUG
  27. SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
  28. #endif
  29. // 禁止多个实例的同时运行
  30. HANDLE hMutexOneInstance = ::CreateMutex(NULL, TRUE, _T(AfxGetAppName()));
  31. if(::GetLastError() == ERROR_ALREADY_EXISTS)
  32. {
  33. if(hMutexOneInstance) // Release the mutex
  34. {
  35. ::ReleaseMutex(hMutexOneInstance);
  36. }
  37. HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
  38. while(::IsWindow(hWndPrevious))
  39. {
  40. // 检查窗口是否有预设的标记? 有,则是我们寻找的主窗口
  41. if(::GetProp(hWndPrevious, m_pszAppName))
  42. {
  43. // 主窗口已最小化,则恢复其大小
  44. if(::IsIconic(hWndPrevious)) ::ShowWindow(hWndPrevious, SW_RESTORE);
  45. ::SetForegroundWindow(hWndPrevious); // 将主窗激活
  46. ::SetForegroundWindow(::GetLastActivePopup(hWndPrevious)); // 将主窗的对话框激活
  47. return FALSE;
  48. } // end if
  49. hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT); // 继续寻找下一个窗口
  50. } // end while
  51. } // end if
  52. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  53. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  54. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  55. INITCOMMONCONTROLSEX InitCtrls;
  56. InitCtrls.dwSize = sizeof(InitCtrls);
  57. // 将它设置为包括所有要在应用程序中使用的
  58. // 公共控件类。
  59. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  60. InitCommonControlsEx(&InitCtrls);
  61. CWinApp::InitInstance();
  62. // 标准初始化
  63. // 如果未使用这些功能并希望减小
  64. // 最终可执行文件的大小,则应移除下列
  65. // 不需要的特定初始化例程
  66. // 更改用于存储设置的注册表项
  67. // TODO: 应适当修改该字符串,
  68. // 例如修改为公司或组织名
  69. SetRegistryKey(_T("Guard"));
  70. // 加载配置
  71. if(!CConfig::load())
  72. {
  73. AfxMessageBox(_T("加载配置信息失败"));
  74. return FALSE;
  75. }
  76. if (AutoStart::GetInstance()->StartAll())
  77. {
  78. }
  79. CDisplayWnd* pDisWnd = (CDisplayWnd *)RUNTIME_CLASS(CDisplayWnd)->CreateObject();
  80. m_pMainWnd = pDisWnd;
  81. pDisWnd->Show();
  82. return TRUE;
  83. }