CSystemInfo.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "CSystemInfo.h"
  2. #define APPCONFIG L"config.ini"
  3. #define THREADPROCESS "ThreadProcess"
  4. #define PID "pid"
  5. #define THREADID "TheardId"
  6. CSystemInfo::CSystemInfo()
  7. {
  8. }
  9. bool CSystemInfo::IsHanvedCurrentWindow()
  10. {
  11. std::wstring ss1 = PathCore::smPath_Temp + L"\\" + APPCONFIG;
  12. wchar_t* ptr = _wcsdup(ss1.c_str());
  13. std::string ss = CharConvert::GetMultiByteW(ptr);
  14. HANDLE h = ::CreateMutex(NULL, TRUE, ExeCore::smName_ExeProcess.c_str());
  15. if (h != NULL)
  16. {
  17. if (GetLastError() == ERROR_ALREADY_EXISTS)
  18. {
  19. DWORD pidIni = LogIni::ReadIntFromini(THREADPROCESS, PID, 0, ss.c_str());
  20. DWORD TheardIdIni = LogIni::ReadIntFromini(THREADPROCESS, THREADID, 0, ss.c_str());
  21. HWND hWnd = ::GetTopWindow(0);
  22. while (hWnd)
  23. {
  24. DWORD pid = 0;
  25. DWORD dwTheardId = ::GetWindowThreadProcessId(hWnd, &pid);
  26. if (dwTheardId != 0)
  27. {
  28. if (pid == pidIni && TheardIdIni == dwTheardId)
  29. {
  30. bool isWindowVisible = IsWindowVisible(hWnd);
  31. if (isWindowVisible == true)
  32. {
  33. ShowWindow(hWnd, SW_SHOWNOACTIVATE);
  34. break;
  35. }
  36. }
  37. }
  38. hWnd = ::GetNextWindow(hWnd, GW_HWNDNEXT);
  39. }
  40. CloseHandle(h);
  41. h = NULL;
  42. return true;
  43. }
  44. }
  45. return false;
  46. }
  47. bool CSystemInfo::isWriteAppProcessInfoToIni(HWND hwnd)
  48. {
  49. std::wstring ss1 = PathCore::smPath_Temp + L"\\" + APPCONFIG;
  50. wchar_t* ptr = _wcsdup(ss1.c_str());
  51. std::string ss = CharConvert::GetMultiByteW(ptr);
  52. DWORD pid = 0;
  53. DWORD dwTheardId = ::GetWindowThreadProcessId(hwnd, &pid);
  54. BOOL readpid = LogIni::WriteIntToini(THREADPROCESS, PID, pid, ss.c_str());
  55. BOOL readTheardId = LogIni::WriteIntToini(THREADPROCESS, THREADID, dwTheardId, ss.c_str());
  56. return (readpid > 0 && readTheardId > 0);
  57. }