中间件标准版5.1git,去除基础模块

CTI.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // CTI.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "CTI.h"
  5. #include "DisplayWnd.h"
  6. #include "CtiCore.h"
  7. #include "ExceptionHandler.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11. volatile unsigned long ThreadCounter = 0;
  12. LONG WINAPI AppUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo)
  13. {
  14. RecordExceptionInfo(ExceptionInfo, "CTI");
  15. return EXCEPTION_EXECUTE_HANDLER;
  16. }
  17. // CCTIApp
  18. BEGIN_MESSAGE_MAP(CCTIApp, CWinApp)
  19. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  20. END_MESSAGE_MAP()
  21. // CCTIApp 构造
  22. CCTIApp::CCTIApp()
  23. {
  24. // 支持重新启动管理器
  25. m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
  26. // TODO: 在此处添加构造代码,
  27. // 将所有重要的初始化放置在 InitInstance 中
  28. SetUnhandledExceptionFilter(AppUnhandledExceptionFilter);
  29. }
  30. // 唯一的一个 CCTIApp 对象
  31. CCTIApp theApp;
  32. // CCTIApp 初始化
  33. BOOL CCTIApp::InitInstance()
  34. {
  35. #ifndef _DEBUG
  36. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  37. #endif
  38. // 禁止多个实例的同时运行
  39. HANDLE hMutexOneInstance = ::CreateMutex(NULL, TRUE, _T(AfxGetAppName()));
  40. if (::GetLastError() == ERROR_ALREADY_EXISTS)
  41. {
  42. if (hMutexOneInstance) // Release the mutex
  43. {
  44. ::ReleaseMutex(hMutexOneInstance);
  45. }
  46. HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
  47. while (::IsWindow(hWndPrevious))
  48. {
  49. // 检查窗口是否有预设的标记? 有,则是我们寻找的主窗口
  50. if (::GetProp(hWndPrevious, m_pszAppName))
  51. {
  52. // 主窗口已最小化,则恢复其大小
  53. if (::IsIconic(hWndPrevious)) ::ShowWindow(hWndPrevious, SW_RESTORE);
  54. ::SetForegroundWindow(hWndPrevious); // 将主窗激活
  55. ::SetForegroundWindow(::GetLastActivePopup(hWndPrevious)); // 将主窗的对话框激活
  56. return FALSE;
  57. } // end if
  58. hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT); // 继续寻找下一个窗口
  59. } // end while
  60. } // end if
  61. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  62. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  63. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  64. INITCOMMONCONTROLSEX InitCtrls;
  65. InitCtrls.dwSize = sizeof(InitCtrls);
  66. // 将它设置为包括所有要在应用程序中使用的
  67. // 公共控件类。
  68. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  69. InitCommonControlsEx(&InitCtrls);
  70. CWinApp::InitInstance();
  71. if (!AfxSocketInit())
  72. {
  73. AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  74. return FALSE;
  75. }
  76. AfxEnableControlContainer();
  77. // 标准初始化
  78. // 如果未使用这些功能并希望减小
  79. // 最终可执行文件的大小,则应移除下列
  80. // 不需要的特定初始化例程
  81. // 更改用于存储设置的注册表项
  82. // TODO: 应适当修改该字符串,
  83. // 例如修改为公司或组织名
  84. SetRegistryKey(_T("CTI"));
  85. //if(!CCtiCore::GetInstance().stage1Start())
  86. // return FALSE;
  87. CDisplayWnd* pDisWnd = (CDisplayWnd *)RUNTIME_CLASS(CDisplayWnd)->CreateObject();
  88. m_pMainWnd = pDisWnd;
  89. pDisWnd->Show();
  90. //CCtiCore::GetInstance().stage2Start();
  91. if (ThreadCounter == 0)
  92. {
  93. AfxBeginThread(StageStartThread, this);
  94. }
  95. return TRUE;
  96. }
  97. UINT CCTIApp::StageStartThread(LPVOID lp)
  98. {
  99. InterlockedIncrement(&ThreadCounter);
  100. CCTIApp* pCTIApp = (CCTIApp*)lp;
  101. bool Stage1Ok = false;
  102. bool Stage2Ok = false;
  103. while (TRUE)
  104. {
  105. CCtiCore::GetInstance().UnInit(); // 先取消消息注册
  106. CCtiCore::GetInstance().StopForContinue(); // 再释放资源
  107. if (false == (Stage1Ok = CCtiCore::GetInstance().stage1Start()) || false == (Stage2Ok = CCtiCore::GetInstance().stage2Start()))
  108. {
  109. Sleep(15 * 1000);
  110. }
  111. else
  112. {
  113. break; //连接成功退出
  114. }
  115. }
  116. InterlockedDecrement(&ThreadCounter);
  117. return 0;
  118. }