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.

212 lines
5.7 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Job Scheduler Service
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  7. //
  8. // File: jobtask.cxx
  9. //
  10. // Contents: job scheduler test task application
  11. //
  12. // History: 14-Jan-96 EricB created
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include "..\..\pch\headers.hxx"
  16. #pragma hdrstop
  17. #include <debug.hxx>
  18. #include "res-ids.h"
  19. DECLARE_INFOLEVEL(Sched);
  20. // globals
  21. HINSTANCE g_hInstance;
  22. HWND g_hwndChild;
  23. UINT g_uTimeTillExit = 0;
  24. UINT g_uExitCode = 0;
  25. SYSTEMTIME g_st;
  26. // local prototypes
  27. LRESULT CALLBACK TargWndProc(HWND hwndTarg, UINT uMsg, WPARAM wParam,
  28. LPARAM lParam);
  29. #define TARG_CLASS TEXT("TargWndClass")
  30. #define TITLE TEXT("Job Scheduler Test Target")
  31. const int BUF_LEN = 512;
  32. const UINT TIMER_ID = 7;
  33. //+----------------------------------------------------------------------------
  34. //
  35. // Function: WinMain
  36. //
  37. // Synopsis: entry point
  38. //
  39. //-----------------------------------------------------------------------------
  40. int WINAPI
  41. WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
  42. int nCmdShow)
  43. {
  44. GetLocalTime(&g_st);
  45. if (hPrevInstance != NULL)
  46. {
  47. return -1;
  48. }
  49. g_hInstance = hInstance;
  50. if (lpCmdLine && *lpCmdLine != '\0')
  51. {
  52. lpCmdLine = strtok(lpCmdLine, " \t");
  53. // convert seconds to milliseconds.
  54. g_uTimeTillExit = (UINT)atoi(lpCmdLine) * 1000;
  55. LPSTR lpExitCode = strtok(NULL, " \t");
  56. if (lpExitCode)
  57. {
  58. g_uExitCode = (UINT)atoi(lpExitCode);
  59. }
  60. }
  61. //
  62. // Register the window class
  63. //
  64. WNDCLASS wc;
  65. wc.style = CS_HREDRAW | CS_VREDRAW;
  66. wc.lpfnWndProc = TargWndProc;
  67. wc.cbClsExtra = 0;
  68. wc.cbWndExtra = 0;
  69. wc.hInstance = hInstance;
  70. wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SCHEDULER));
  71. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  72. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  73. wc.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);
  74. wc.lpszClassName = TARG_CLASS;
  75. if (!RegisterClass(&wc))
  76. {
  77. schDebugOut((DEB_ERROR, "RegisterClass failed with error %d\n",
  78. GetLastError()));
  79. return -1;
  80. }
  81. //
  82. // Create the window
  83. //
  84. HWND hwndTarg = CreateWindow(TARG_CLASS, TITLE, WS_OVERLAPPEDWINDOW,
  85. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  86. CW_USEDEFAULT, (HWND)NULL, (HMENU)NULL,
  87. hInstance, (LPVOID)NULL);
  88. if (!hwndTarg)
  89. {
  90. schDebugOut((DEB_ERROR, "CreateWindow failed with error %d\n",
  91. GetLastError()));
  92. return -1;
  93. }
  94. if (g_uTimeTillExit > 0)
  95. {
  96. if (TIMER_ID != SetTimer(hwndTarg, TIMER_ID, g_uTimeTillExit, NULL))
  97. {
  98. schDebugOut((DEB_ERROR, "SetTimer failed with error %d\n",
  99. GetLastError()));
  100. }
  101. }
  102. ShowWindow(hwndTarg, nCmdShow);
  103. UpdateWindow(hwndTarg);
  104. MSG msg;
  105. while (GetMessage(&msg, (HWND) NULL, 0, 0))
  106. {
  107. TranslateMessage(&msg);
  108. DispatchMessage(&msg);
  109. }
  110. return msg.wParam;
  111. }
  112. //+----------------------------------------------------------------------------
  113. //
  114. // Function: TargWndProc
  115. //
  116. // Synopsis: handle messages
  117. //
  118. // Returns: occasionally
  119. //
  120. //-----------------------------------------------------------------------------
  121. LRESULT CALLBACK
  122. TargWndProc(HWND hwndTarg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  123. {
  124. TCHAR tszBuf[BUF_LEN];
  125. switch (uMsg)
  126. {
  127. case WM_CREATE:
  128. g_hwndChild = CreateWindow(TEXT("EDIT"), NULL,
  129. WS_CHILD | WS_VISIBLE | WS_HSCROLL |
  130. WS_VSCROLL | ES_MULTILINE |
  131. ES_AUTOVSCROLL | ES_WANTRETURN |
  132. ES_READONLY,
  133. 0, 0, 0, 0, hwndTarg, (HMENU) 1,
  134. g_hInstance, NULL);
  135. TCHAR tszBuf[BUF_LEN];
  136. wsprintf(tszBuf,
  137. TEXT("\r\nTest task launched at %u:%02u:%02u %u/%u/%u,"),
  138. g_st.wHour, g_st.wMinute, g_st.wSecond, g_st.wMonth,
  139. g_st.wDay, g_st.wYear);
  140. TCHAR tszDir[BUF_LEN];
  141. GetCurrentDirectory(BUF_LEN, tszDir);
  142. wsprintf(tszBuf + lstrlen(tszBuf),
  143. TEXT("\r\n\r\nin working directory %s,"), tszDir);
  144. if (g_uTimeTillExit)
  145. {
  146. wsprintf(tszBuf + lstrlen(tszBuf),
  147. TEXT("\r\n\r\nand will run for %u seconds,"),
  148. g_uTimeTillExit / 1000);
  149. }
  150. wsprintf(tszBuf + lstrlen(tszBuf),
  151. TEXT("\r\n\r\nand will return exit code %x."),
  152. g_uExitCode);
  153. SendMessage(g_hwndChild, WM_SETTEXT, 0, (LPARAM)tszBuf);
  154. break;
  155. case WM_SIZE:
  156. MoveWindow(g_hwndChild, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  157. break;
  158. case WM_TIMER:
  159. DestroyWindow(hwndTarg);
  160. break;
  161. case WM_COMMAND:
  162. switch (LOWORD(wParam))
  163. {
  164. case IDM_EXIT:
  165. DestroyWindow(hwndTarg);
  166. break;
  167. }
  168. break;
  169. case WM_SYSCOMMAND:
  170. if (wParam == SC_CLOSE)
  171. {
  172. SendMessageA(hwndTarg, WM_COMMAND, MAKEWPARAM(IDM_EXIT, 0), 0);
  173. break;
  174. }
  175. else
  176. {
  177. return DefWindowProc(hwndTarg, uMsg, wParam, lParam);
  178. }
  179. case WM_DESTROY:
  180. PostQuitMessage(g_uExitCode);
  181. break;
  182. default:
  183. return DefWindowProc(hwndTarg, uMsg, wParam, lParam);
  184. }
  185. return 0;
  186. }