postsetup.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #define APSTUDIO_READONLY_SYMBOLS
  2. #include "main.h"
  3. #include ".\postsetup.h"
  4. #include "./setup_resource.h"
  5. #include "./langutil.h"
  6. #include "api.h"
  7. static BOOL SleepMsg(DWORD dwTimeout)
  8. {
  9. DWORD dwStart = GetTickCount();
  10. DWORD dwElapsed;
  11. while ((dwElapsed = GetTickCount() - dwStart) < dwTimeout)
  12. {
  13. DWORD dwStatus = MsgWaitForMultipleObjectsEx(0, NULL, dwTimeout - dwElapsed, QS_ALLINPUT, MWMO_WAITALL | MWMO_INPUTAVAILABLE);
  14. if (dwStatus == WAIT_OBJECT_0) while (application->app_messageLoopStep());
  15. }
  16. return TRUE; // timed out
  17. }
  18. BOOL StartWinamp(BOOL bWaitShow, HWND *phwndWA, LPCSTR pszParam)
  19. {
  20. HWND hwndWA;
  21. DWORD pid;
  22. wchar_t buf[MAX_PATH] = L"\"";
  23. STARTUPINFOW si = {sizeof(si), };
  24. PROCESS_INFORMATION pi;
  25. if (phwndWA) *phwndWA = NULL;
  26. GetModuleFileNameW(NULL, buf + 1, sizeof(buf)/sizeof(wchar_t) - 1);
  27. StringCchCatW(buf, MAX_PATH, L"\" /NEW ");
  28. if (*pszParam && lstrlenA(pszParam))
  29. {
  30. int count, len;
  31. len = sizeof(buf)/sizeof(wchar_t) - lstrlenW(buf)- 1;
  32. count = MultiByteToWideChar(CP_ACP, 0, pszParam, -1, NULL, 0);
  33. if (count < len) MultiByteToWideChar(CP_ACP, 0, pszParam, -1, buf + lstrlenW(buf), len);
  34. }
  35. si.dwFlags = STARTF_FORCEONFEEDBACK | STARTF_USESHOWWINDOW;
  36. si.wShowWindow = SW_SHOWNOACTIVATE;
  37. if ( 0 ==CreateProcessW(NULL, buf, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  38. {
  39. return FALSE;
  40. }
  41. hwndWA = NULL;
  42. if (bWaitShow)
  43. {
  44. for (int a = 0; a < 20; a++)
  45. {
  46. if (!hwndWA)
  47. {
  48. while (NULL != (hwndWA = FindWindowExW(NULL, hwndWA, szAppName, NULL)))
  49. {
  50. GetWindowThreadProcessId(hwndWA, &pid);
  51. if (pid == pi.dwProcessId) break;
  52. }
  53. }
  54. SleepMsg(250);
  55. if (hwndWA && IsWindowVisible(hwndWA))
  56. break;
  57. }
  58. }
  59. if (phwndWA) *phwndWA = hwndWA;
  60. return TRUE;
  61. }