AppGlobalF.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include "AppGlobalF.h"
  4. //---------------------------------------------------------------------------
  5. #pragma package(smart_init)
  6. void ActiveProgram(String AClassName, String ATitle)
  7. {
  8. //String AClassName = "TFrmVmsFormEdit";
  9. //String ATitle = g_AppCfg.sTitle + " - Active";
  10. HWND hExeForm = FindWindow(AClassName.c_str(), ATitle.c_str());
  11. if (hExeForm)
  12. {
  13. bool bResult = SetWindowPos(hExeForm, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
  14. if (bResult) {
  15. bResult = ShowWindow(hExeForm, SW_RESTORE);
  16. SetForegroundWindow(hExeForm);
  17. }
  18. }
  19. }
  20. //---------------------------------------------------------------------------
  21. bool ApplicationSingleRun(String AClassName, String ATitle) {
  22. HANDLE hMutex;
  23. try
  24. {
  25. String sLockFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".lock");
  26. String sProgMutexNm = "ICAIR_" + sLockFile;
  27. if ((hMutex=OpenMutex(MUTEX_ALL_ACCESS, false, sProgMutexNm.c_str()))==NULL)
  28. hMutex = CreateMutex(NULL, true, sProgMutexNm.c_str());
  29. else
  30. {
  31. ActiveProgram(AClassName, ATitle);
  32. return false;
  33. }
  34. }
  35. catch (Exception &exception)
  36. {
  37. Application->ShowException(&exception);
  38. return false;
  39. }
  40. return true;
  41. }