华辉中间件项目(代码服务器上没有,用杨成电脑的源代码上传的)

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. std::map<CString, CString> turnk;
  33. // CCTIApp 初始化
  34. BOOL CCTIApp::InitInstance()
  35. {
  36. #ifndef _DEBUG
  37. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  38. #endif
  39. // 禁止多个实例的同时运行
  40. HANDLE hMutexOneInstance = ::CreateMutex(NULL, TRUE, _T(AfxGetAppName()));
  41. if (::GetLastError() == ERROR_ALREADY_EXISTS)
  42. {
  43. if (hMutexOneInstance) // Release the mutex
  44. {
  45. ::ReleaseMutex(hMutexOneInstance);
  46. }
  47. HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
  48. while (::IsWindow(hWndPrevious))
  49. {
  50. // 检查窗口是否有预设的标记? 有,则是我们寻找的主窗口
  51. if (::GetProp(hWndPrevious, m_pszAppName))
  52. {
  53. // 主窗口已最小化,则恢复其大小
  54. if (::IsIconic(hWndPrevious)) ::ShowWindow(hWndPrevious, SW_RESTORE);
  55. ::SetForegroundWindow(hWndPrevious); // 将主窗激活
  56. ::SetForegroundWindow(::GetLastActivePopup(hWndPrevious)); // 将主窗的对话框激活
  57. return FALSE;
  58. } // end if
  59. hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT); // 继续寻找下一个窗口
  60. } // end while
  61. } // end if
  62. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  63. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  64. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  65. INITCOMMONCONTROLSEX InitCtrls;
  66. InitCtrls.dwSize = sizeof(InitCtrls);
  67. // 将它设置为包括所有要在应用程序中使用的
  68. // 公共控件类。
  69. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  70. InitCommonControlsEx(&InitCtrls);
  71. CWinApp::InitInstance();
  72. if (!AfxSocketInit())
  73. {
  74. AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  75. return FALSE;
  76. }
  77. AfxEnableControlContainer();
  78. // 标准初始化
  79. // 如果未使用这些功能并希望减小
  80. // 最终可执行文件的大小,则应移除下列
  81. // 不需要的特定初始化例程
  82. // 更改用于存储设置的注册表项
  83. // TODO: 应适当修改该字符串,
  84. // 例如修改为公司或组织名
  85. SetRegistryKey(_T("CTI"));
  86. if(!CCtiCore::GetInstance().stage1Start())
  87. return FALSE;
  88. CDisplayWnd* pDisWnd = (CDisplayWnd *)RUNTIME_CLASS(CDisplayWnd)->CreateObject();
  89. m_pMainWnd = pDisWnd;
  90. pDisWnd->Show();
  91. CCtiCore::GetInstance().stage2Start();
  92. //if (ThreadCounter == 0)
  93. //{
  94. // AfxBeginThread(StageStartThread, this);
  95. //}
  96. return TRUE;
  97. }
  98. UINT CCTIApp::StageStartThread(LPVOID lp)
  99. {
  100. InterlockedIncrement(&ThreadCounter);
  101. CCTIApp* pCTIApp = (CCTIApp*)lp;
  102. bool Stage1Ok = false;
  103. bool Stage2Ok = false;
  104. while (TRUE)
  105. {
  106. CCtiCore::GetInstance().UnInit(); // 先取消消息注册
  107. CCtiCore::GetInstance().StopForContinue(); // 再释放资源
  108. if (false == (Stage1Ok = CCtiCore::GetInstance().stage1Start()) || false == (Stage2Ok = CCtiCore::GetInstance().stage2Start()))
  109. {
  110. Sleep(15 * 1000);
  111. }
  112. else
  113. {
  114. break; //连接成功退出
  115. }
  116. }
  117. InterlockedDecrement(&ThreadCounter);
  118. return 0;
  119. }