SProxy.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // dui-demo.cpp : main source file
  2. //
  3. #include "stdafx.h"
  4. #include "MainDlg.h"
  5. #include "LoginDlg.h"
  6. #include "SouiInit.h"
  7. #include "CApp.h"
  8. #include "CTool.h"
  9. #include "Logger.h"
  10. bool startWisth(const std::wstring& mainstr, const std::wstring& substr)
  11. {
  12. return mainstr.find(substr) == 0 ? 1 : 0;
  13. }
  14. int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
  15. {
  16. HRESULT hRes = OleInitialize(NULL);
  17. SASSERT(SUCCEEDED(hRes));
  18. int nRet = 0;
  19. new Logger();
  20. new CApp();
  21. new CProcessManager();
  22. Logger::getSingletonPtr()->Init(Logger::file_and_terminal, Logger::info);
  23. CApp::getSingletonPtr()->Init();
  24. CApp::getSingletonPtr()->SetMethod(hInstance);
  25. CApp::getSingletonPtr()->ChkeAndSetDtaPath();
  26. if (!CApp::getSingletonPtr()->CheckOnlyOneInstance())
  27. {
  28. std::wstring pmPrefix = L"--pm=";
  29. std::wstring cmdLine(lpstrCmdLine);
  30. if (startWisth(cmdLine, pmPrefix))
  31. return CProcessManager::getSingletonPtr()->SubProcess(cmdLine.substr(pmPrefix.size()));
  32. }
  33. CreateDirectoryIgnoreExist(CApp::getSingletonPtr()->GetDataPath().c_str());
  34. CApp::getSingletonPtr()->CheckOnlyOneInstance();
  35. PortableModeUtil::SetAppId();
  36. /**/
  37. CProcessManager::getSingletonPtr()->SetInsTanCe(hInstance);
  38. //---------------------------防止程序多开-----------------------------------------
  39. auto hEventStatus = CreateEvent(nullptr, TRUE, FALSE, L"sproxy");
  40. if (hEventStatus)
  41. {
  42. if (GetLastError() == ERROR_ALREADY_EXISTS)
  43. {
  44. auto hwndMain = FindWindow(L"sproxy", NULL);//获取该窗体句柄
  45. if (hwndMain)
  46. {
  47. auto hwnpop = GetLastActivePopup(hwndMain);
  48. ShowWindow(hwnpop, SW_SHOW);
  49. SetForegroundWindow(hwnpop);
  50. //ShowWindow(hwndMain, SW_SHOW);
  51. }
  52. CloseHandle(hEventStatus);//互斥量存在释放句柄并复位互斥量
  53. //
  54. SStringT strDisplayInfo;
  55. strDisplayInfo.Format(L"sproxy 正在运行中.");
  56. MessageBox(GetForegroundWindow(), strDisplayInfo, L"", MB_ICONINFORMATION);
  57. return 0;
  58. }
  59. }//-----------------------------------------------------------------
  60. CSouiLoader Loader(hInstance);
  61. InitSystemRes(Loader.GetApp(), Loader.GetComMgr());
  62. InitUserRes(Loader.GetApp(), Loader.GetComMgr());
  63. new CTool();
  64. new SNotifyCenter();
  65. new CManageNetWork();
  66. TCHAR szCurrentDir[MAX_PATH] = { 0 };
  67. GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));
  68. LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
  69. _tcscpy(lpInsertPos + 1, _T("\0"));
  70. SetCurrentDirectory(szCurrentDir);
  71. nRet = Run<CLoginDlg>(Loader.GetApp());
  72. if (CApp::getSingletonPtr()->GetOut() == 1)
  73. {
  74. nRet = Run<CMainDlg>(Loader.GetApp());
  75. }
  76. delete CTool::getSingletonPtr();
  77. delete SNotifyCenter::getSingletonPtr();
  78. delete CManageNetWork::getSingletonPtr();
  79. delete CProcessManager::getSingletonPtr();
  80. delete CApp::getSingletonPtr();
  81. delete Logger::getSingletonPtr();
  82. OleUninitialize();
  83. return nRet;
  84. }