Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
5.9 KiB

  1. #include "ids.h"
  2. #include "cmmn.h"
  3. #include <windows.h>
  4. BOOL g_fPaused = FALSE;
  5. HWND g_hwndDlg = NULL;
  6. HANDLE g_hEvent = NULL;
  7. LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
  8. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  9. LPSTR szCmdLine, int iCmdShow)
  10. {
  11. MSG msg;
  12. WNDCLASSEX wndclass;
  13. static WCHAR szAppName[] = TEXT("APDIAG");
  14. hPrevInstance;
  15. szCmdLine;
  16. wndclass.cbSize = sizeof (wndclass);
  17. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  18. wndclass.lpfnWndProc = MainDlgProc;
  19. wndclass.cbClsExtra = 0;
  20. wndclass.cbWndExtra = DLGWINDOWEXTRA;
  21. wndclass.hInstance = hInstance;
  22. wndclass.hIcon = LoadIcon(hInstance, szAppName);
  23. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  24. wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  25. wndclass.lpszMenuName = NULL;
  26. wndclass.lpszClassName = szAppName;
  27. wndclass.hIconSm = LoadIcon(hInstance, szAppName);
  28. RegisterClassEx(&wndclass);
  29. g_hwndDlg = CreateDialog(hInstance, szAppName, 0, NULL);
  30. ShowWindow(g_hwndDlg, iCmdShow);
  31. while (GetMessage(&msg, NULL, 0, 0))
  32. {
  33. TranslateMessage(&msg);
  34. DispatchMessage(&msg);
  35. }
  36. return (int)msg.wParam;
  37. }
  38. // Copied from shell32
  39. BOOL _TestTokenMembership(HANDLE hToken, ULONG ulRID)
  40. {
  41. static SID_IDENTIFIER_AUTHORITY sSystemSidAuthority = SECURITY_NT_AUTHORITY;
  42. PSID pSIDLocalGroup;
  43. BOOL fResult = FALSE;
  44. if (AllocateAndInitializeSid(&sSystemSidAuthority,
  45. 2,
  46. SECURITY_BUILTIN_DOMAIN_RID,
  47. ulRID,
  48. 0, 0, 0, 0, 0, 0,
  49. &pSIDLocalGroup) != FALSE)
  50. {
  51. if (CheckTokenMembership(hToken, pSIDLocalGroup, &fResult) == FALSE)
  52. {
  53. fResult = FALSE;
  54. }
  55. FreeSid(pSIDLocalGroup);
  56. }
  57. return fResult;
  58. }
  59. LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  60. {
  61. LRESULT lres = 0;
  62. BOOL fDoDefault = TRUE;
  63. static BOOL fInited = FALSE;
  64. switch (iMsg)
  65. {
  66. case WM_CREATE:
  67. g_fPaused = FALSE;
  68. break;
  69. case WM_ACTIVATE:
  70. if (!fInited)
  71. {
  72. // Run this only for Admins
  73. if (_TestTokenMembership(NULL, DOMAIN_ALIAS_RID_ADMINS))
  74. {
  75. CreateThread(NULL, 0, Do, 0, 0, NULL);
  76. fInited = TRUE;
  77. }
  78. else
  79. {
  80. MessageBox(hwnd,
  81. TEXT("You need to be an Administrator to run this application."),
  82. TEXT("Autoplay Diagnostic Tools"), MB_OK | MB_ICONEXCLAMATION);
  83. }
  84. }
  85. break;
  86. case WM_COMMAND:
  87. if (BN_CLICKED == HIWORD(wParam))
  88. {
  89. switch (LOWORD(wParam))
  90. {
  91. case IDC_PAUSERESUME:
  92. if (g_fPaused)
  93. {
  94. // Resuming
  95. SendMessage(GetDlgItem(hwnd, IDC_PAUSERESUME), WM_SETTEXT, 0,
  96. (LPARAM)TEXT("&Pause"));
  97. }
  98. else
  99. {
  100. // Pausing
  101. SendMessage(GetDlgItem(hwnd, IDC_PAUSERESUME), WM_SETTEXT, 0,
  102. (LPARAM)TEXT("&Resume"));
  103. }
  104. g_fPaused = !g_fPaused;
  105. break;
  106. case IDC_CLEAR:
  107. SendMessage(GetDlgItem(hwnd, IDC_EDIT1), WM_SETTEXT, 0,
  108. (LPARAM)TEXT(""));
  109. break;
  110. case IDC_COPYALL:
  111. {
  112. if (OpenClipboard(hwnd))
  113. {
  114. BOOL fGoOn = FALSE;
  115. BOOL fFreeMem = TRUE;
  116. LRESULT cch = SendMessage(GetDlgItem(hwnd, IDC_EDIT1),
  117. WM_GETTEXTLENGTH, 0, 0);
  118. HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE |
  119. GMEM_DDESHARE, (cch + 1) * sizeof(WCHAR));
  120. if (hMem)
  121. {
  122. PVOID pv = GlobalLock(hMem);
  123. if (pv)
  124. {
  125. if (SendMessage(GetDlgItem(hwnd, IDC_EDIT1),
  126. WM_GETTEXT, (WPARAM)(cch + 1), (LPARAM)pv))
  127. {
  128. fGoOn = TRUE;
  129. }
  130. GlobalUnlock(hMem);
  131. }
  132. }
  133. if (fGoOn)
  134. {
  135. HANDLE h = SetClipboardData(CF_UNICODETEXT, hMem);
  136. if (h)
  137. {
  138. fFreeMem = FALSE;
  139. }
  140. }
  141. if (fFreeMem)
  142. {
  143. GlobalFree(hMem);
  144. }
  145. CloseClipboard();
  146. }
  147. break;
  148. }
  149. }
  150. }
  151. break;
  152. case WM_DESTROY:
  153. if (g_hEvent)
  154. {
  155. CloseHandle(g_hEvent);
  156. }
  157. PostQuitMessage(0);
  158. fDoDefault = FALSE;
  159. break;
  160. }
  161. if (fDoDefault)
  162. {
  163. lres = DefWindowProc(hwnd, iMsg, wParam, lParam);
  164. }
  165. return lres;
  166. }