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.

528 lines
14 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxsvc.c
  5. Abstract:
  6. This module contains the windows code for the
  7. FAX service debug window.
  8. Author:
  9. Wesley Witt (wesw) 28-Feb-1996
  10. Revision History:
  11. --*/
  12. #include "faxsvc.h"
  13. #pragma hdrstop
  14. #include "resource.h"
  15. HWND hwndSvcMain;
  16. HWND hwndEdit;
  17. HWND hwndListMsg;
  18. HWND hwndListLines;
  19. HWND hwndListState;
  20. DWORD EditHeight;
  21. DWORD ListMsgHeight;
  22. DWORD ListLinesHeight;
  23. DWORD ListStateHeight;
  24. DWORD
  25. DebugServiceWindowThread(
  26. HANDLE hEvent
  27. );
  28. LRESULT
  29. WndProc(
  30. HWND hwnd,
  31. UINT message,
  32. WPARAM wParam,
  33. LPARAM lParam
  34. );
  35. int
  36. DebugService(
  37. VOID
  38. )
  39. /*++
  40. Routine Description:
  41. Starts the service in debug mode. In this mode the FAX service
  42. runs as a regular WIN32 process. This is implemented as an aid
  43. to debugging the service.
  44. Arguments:
  45. argc - argument count
  46. argv - argument array
  47. Return Value:
  48. Return code. Return zero for success, all other
  49. values indicate errors.
  50. --*/
  51. {
  52. LONG Rslt;
  53. HANDLE WaitHandles[2];
  54. ServiceDebug = TRUE;
  55. ConsoleDebugOutput = TRUE;
  56. WaitHandles[1] = CreateEvent( NULL, FALSE, FALSE, NULL );
  57. WaitHandles[0] = CreateThread(
  58. NULL,
  59. 0,
  60. (LPTHREAD_START_ROUTINE) DebugServiceWindowThread,
  61. WaitHandles[1],
  62. 0,
  63. &Rslt
  64. );
  65. if (!WaitHandles[0]) {
  66. return GetLastError();
  67. }
  68. if (WaitForMultipleObjects( 2, WaitHandles, FALSE, INFINITE ) == WAIT_OBJECT_0) {
  69. //
  70. // the window initialization did not complete successfuly
  71. //
  72. GetExitCodeThread( WaitHandles[0], &Rslt );
  73. return Rslt;
  74. }
  75. return ServiceStart();
  76. }
  77. DWORD
  78. DebugServiceWindowThread(
  79. HANDLE hEvent
  80. )
  81. {
  82. WNDCLASS wndclass;
  83. MSG msg;
  84. HINSTANCE hInstance;
  85. hInstance = GetModuleHandle( NULL );
  86. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  87. wndclass.lpfnWndProc = (WNDPROC) WndProc;
  88. wndclass.cbClsExtra = 0;
  89. wndclass.cbWndExtra = 0;
  90. wndclass.hInstance = hInstance;
  91. wndclass.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_APPICON) );
  92. wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
  93. wndclass.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
  94. wndclass.lpszMenuName = NULL;
  95. wndclass.lpszClassName = TEXT("FaxService");
  96. RegisterClass( &wndclass );
  97. hwndSvcMain = CreateWindow (
  98. TEXT("FaxService"), // window class name
  99. TEXT("Fax Service"), // window caption
  100. WS_OVERLAPPEDWINDOW, // window style
  101. CW_USEDEFAULT, // initial x position
  102. CW_USEDEFAULT, // initial y position
  103. CW_USEDEFAULT, // initial x size
  104. CW_USEDEFAULT, // initial y size
  105. NULL, // parent window handle
  106. NULL, // window menu handle
  107. hInstance, // program instance handle
  108. NULL // creation parameters
  109. );
  110. if (!hwndSvcMain) {
  111. return 0;
  112. }
  113. ShowWindow( hwndSvcMain, SW_SHOWNORMAL );
  114. UpdateWindow (hwndSvcMain) ;
  115. SetEvent( hEvent );
  116. while (GetMessage (&msg, NULL, 0, 0)) {
  117. TranslateMessage (&msg) ;
  118. DispatchMessage (&msg) ;
  119. }
  120. return 0;
  121. }
  122. VOID
  123. ConsoleDebugPrint(
  124. LPTSTR buf
  125. )
  126. {
  127. static WPARAM cxExtent = 0;
  128. static DWORD MsgCount = 0;
  129. SIZE size;
  130. HDC hdc;
  131. HFONT hFont;
  132. if (!ConsoleDebugOutput) {
  133. return;
  134. }
  135. SendMessage( hwndListMsg, LB_ADDSTRING, 0, (LPARAM) buf );
  136. SendMessage( hwndListMsg, LB_SETCURSEL, MsgCount, 0 );
  137. MsgCount += 1;
  138. hdc = GetDC( hwndListMsg );
  139. hFont = (HFONT)SendMessage( hwndListMsg, WM_GETFONT, 0, 0 );
  140. if (hFont != NULL) {
  141. SelectObject( hdc, hFont );
  142. }
  143. GetTextExtentPoint( hdc, buf, _tcslen(buf), &size );
  144. if (size.cx > (LONG)cxExtent) {
  145. cxExtent = size.cx;
  146. }
  147. ReleaseDC( hwndListMsg, hdc );
  148. SendMessage( hwndListMsg, LB_SETHORIZONTALEXTENT, cxExtent, 0 );
  149. }
  150. void
  151. lbprintf(
  152. HWND hwndList,
  153. LPTSTR Format,
  154. ...
  155. )
  156. /*++
  157. Routine Description:
  158. Prints a debug string
  159. Arguments:
  160. format - printf() format string
  161. ... - Variable data
  162. Return Value:
  163. None.
  164. --*/
  165. {
  166. TCHAR buf[1024];
  167. va_list arg_ptr;
  168. va_start(arg_ptr, Format);
  169. _vsntprintf(buf, sizeof(buf), Format, arg_ptr);
  170. va_end(arg_ptr);
  171. SendMessage( hwndList, LB_ADDSTRING, 0, (LPARAM) buf );
  172. }
  173. LRESULT
  174. WndProc(
  175. HWND hwnd,
  176. UINT message,
  177. WPARAM wParam,
  178. LPARAM lParam
  179. )
  180. /*++
  181. Routine Description:
  182. Window procedure for the TIFF image viewer main window.
  183. Arguments:
  184. hwnd - Window handle
  185. message - message identifier
  186. wParam - Parameter
  187. lParam - Parameter
  188. Return Value:
  189. Return result, zero for success.
  190. --*/
  191. {
  192. RECT Rect;
  193. HDC hDC;
  194. TEXTMETRIC tm;
  195. HFONT hFont;
  196. DWORD Height;
  197. TCHAR CmdBuf[128];
  198. DWORD i;
  199. switch (message) {
  200. case WM_CREATE:
  201. GetClientRect( hwnd, &Rect );
  202. hFont = GetStockObject( SYSTEM_FIXED_FONT );
  203. SendMessage( hwnd, WM_SETFONT, (WPARAM)hFont, (LPARAM)FALSE );
  204. hDC = GetDC( hwnd );
  205. GetTextMetrics( hDC, &tm );
  206. ReleaseDC( hwnd, hDC );
  207. EditHeight = (DWORD)(tm.tmHeight * 1.5);
  208. Height = (Rect.bottom - Rect.top) - EditHeight;
  209. ListMsgHeight = (DWORD) (Height * .40);
  210. ListLinesHeight = (DWORD) (Height * .60);
  211. ListStateHeight = (DWORD) (Height * .60);
  212. hwndEdit = CreateWindowEx(
  213. WS_EX_CLIENTEDGE,
  214. TEXT("EDIT"),
  215. NULL,
  216. WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_LEFT | ES_WANTRETURN | ES_MULTILINE | ES_AUTOVSCROLL,
  217. Rect.left,
  218. Rect.bottom - EditHeight,
  219. Rect.right - Rect.left,
  220. EditHeight,
  221. hwnd,
  222. NULL,
  223. GetModuleHandle(NULL),
  224. NULL
  225. );
  226. SendMessage( hwndEdit, EM_LIMITTEXT, 128, 0 );
  227. SendMessage( hwndEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)FALSE );
  228. hwndListMsg = CreateWindowEx(
  229. WS_EX_CLIENTEDGE,
  230. TEXT("LISTBOX"),
  231. NULL,
  232. WS_VSCROLL |
  233. WS_HSCROLL |
  234. WS_CHILD |
  235. WS_VISIBLE |
  236. WS_BORDER |
  237. LBS_NOTIFY |
  238. LBS_NOINTEGRALHEIGHT |
  239. LBS_WANTKEYBOARDINPUT,
  240. Rect.left,
  241. Rect.bottom - EditHeight - ListMsgHeight,
  242. Rect.right - Rect.left,
  243. ListMsgHeight,
  244. hwnd,
  245. NULL,
  246. GetModuleHandle(NULL),
  247. NULL
  248. );
  249. SendMessage( hwndListMsg, WM_SETFONT, (WPARAM)hFont, (LPARAM)FALSE );
  250. hwndListLines = CreateWindowEx(
  251. WS_EX_CLIENTEDGE,
  252. TEXT("LISTBOX"),
  253. NULL,
  254. WS_VSCROLL |
  255. WS_HSCROLL |
  256. WS_CHILD |
  257. WS_VISIBLE |
  258. WS_BORDER |
  259. LBS_NOTIFY |
  260. LBS_NOINTEGRALHEIGHT |
  261. LBS_WANTKEYBOARDINPUT,
  262. Rect.left,
  263. Rect.bottom - EditHeight - ListMsgHeight - ListLinesHeight,
  264. (Rect.right - Rect.left) / 2,
  265. ListLinesHeight,
  266. hwnd,
  267. NULL,
  268. GetModuleHandle(NULL),
  269. NULL
  270. );
  271. SendMessage( hwndListLines, WM_SETFONT, (WPARAM)hFont, (LPARAM)FALSE );
  272. hwndListState = CreateWindowEx(
  273. WS_EX_CLIENTEDGE,
  274. TEXT("LISTBOX"),
  275. NULL,
  276. WS_VSCROLL |
  277. WS_HSCROLL |
  278. WS_CHILD |
  279. WS_VISIBLE |
  280. WS_BORDER |
  281. LBS_NOTIFY |
  282. LBS_NOINTEGRALHEIGHT |
  283. LBS_WANTKEYBOARDINPUT,
  284. Rect.left + ((Rect.right - Rect.left) / 2),
  285. Rect.bottom - EditHeight - ListMsgHeight,
  286. (Rect.right - Rect.left) / 2,
  287. ListStateHeight,
  288. hwnd,
  289. NULL,
  290. GetModuleHandle(NULL),
  291. NULL
  292. );
  293. SendMessage( hwndListState, WM_SETFONT, (WPARAM)hFont, (LPARAM)FALSE );
  294. SetFocus( hwndEdit );
  295. return 0;
  296. case WM_ACTIVATEAPP:
  297. case WM_SETFOCUS:
  298. SetFocus( hwndEdit );
  299. return 0;
  300. case WM_WINDOWPOSCHANGED:
  301. GetClientRect( hwnd, &Rect );
  302. Height = (Rect.bottom - Rect.top) - EditHeight;
  303. ListMsgHeight = (DWORD) (Height * .40);
  304. ListLinesHeight = (DWORD) (Height * .60);
  305. ListStateHeight = (DWORD) (Height * .60);
  306. MoveWindow(
  307. hwndEdit,
  308. Rect.left,
  309. Rect.bottom - Rect.top - EditHeight,
  310. Rect.right - Rect.left,
  311. EditHeight,
  312. TRUE
  313. );
  314. MoveWindow(
  315. hwndListMsg,
  316. Rect.left,
  317. Rect.bottom - Rect.top - EditHeight - ListMsgHeight,
  318. Rect.right - Rect.left,
  319. ListMsgHeight,
  320. TRUE
  321. );
  322. MoveWindow(
  323. hwndListLines,
  324. Rect.left,
  325. Rect.bottom - Rect.top - EditHeight - ListMsgHeight - ListLinesHeight,
  326. (Rect.right - Rect.left) / 2,
  327. ListLinesHeight,
  328. TRUE
  329. );
  330. MoveWindow(
  331. hwndListState,
  332. Rect.left + ((Rect.right - Rect.left) / 2),
  333. Rect.bottom - Rect.top - EditHeight - ListMsgHeight - ListLinesHeight,
  334. (Rect.right - Rect.left) / 2,
  335. ListStateHeight,
  336. TRUE
  337. );
  338. return 0;
  339. case WM_COMMAND:
  340. switch ( HIWORD(wParam) ) {
  341. case EN_CHANGE:
  342. GetWindowText( hwndEdit, CmdBuf, sizeof(CmdBuf) );
  343. i = _tcslen(CmdBuf);
  344. if (i && CmdBuf[i-1] == TEXT('\n')) {
  345. SetWindowText( hwndEdit, TEXT("") );
  346. CmdBuf[i-2] = 0;
  347. ConsoleDebugPrint( CmdBuf );
  348. switch( _totlower( CmdBuf[0] ) ) {
  349. case TEXT('q'):
  350. DestroyWindow( hwnd );
  351. break;
  352. default:
  353. break;
  354. }
  355. }
  356. break;
  357. case LBN_SELCHANGE:
  358. if ((HWND)lParam == hwndListLines) {
  359. extern PLINE_INFO TapiLines;
  360. extern CRITICAL_SECTION CsLine;
  361. print_line_state:
  362. i = SendMessage( hwndListLines, LB_GETCURSEL, 0, 0 );
  363. if (i != LB_ERR) {
  364. SendMessage( hwndListState, WM_SETREDRAW, FALSE, 0 );
  365. SendMessage( hwndListState, LB_RESETCONTENT, 0, 0 );
  366. if (TapiLines[i].Provider) {
  367. lbprintf( hwndListState, TEXT("Provider: %s"), TapiLines[i].Provider->ProviderName );
  368. lbprintf( hwndListState, TEXT("Heap: 0x%08x"), TapiLines[i].Provider->HeapHandle );
  369. lbprintf( hwndListState, TEXT("Base: 0x%08x"), TapiLines[i].Provider->hModule );
  370. }
  371. lbprintf( hwndListState, TEXT("DeviceId: %d"), TapiLines[i].DeviceId );
  372. lbprintf( hwndListState, TEXT("Line Handle: 0x%08x"), TapiLines[i].hLine );
  373. lbprintf( hwndListState, TEXT("Job: 0x%08x"), TapiLines[i].JobEntry );
  374. SendMessage( hwndListState, WM_SETREDRAW, TRUE, 0 );
  375. }
  376. }
  377. break;
  378. default:
  379. break;
  380. }
  381. return 0;
  382. case WM_SERVICE_INIT:
  383. SendMessage( hwndListLines, LB_SETCURSEL, 0, 0 );
  384. goto print_line_state;
  385. return 0;
  386. case WM_CTLCOLOREDIT:
  387. SetBkColor( (HDC)wParam, RGB(128,128,0) );
  388. return (LPARAM)CreateSolidBrush( RGB(128,128,0) );
  389. case WM_CTLCOLORLISTBOX:
  390. if ((HWND)lParam == hwndListLines || (HWND)lParam == hwndListState) {
  391. SetBkColor( (HDC)wParam, RGB(192,192,192) );
  392. return (LPARAM)CreateSolidBrush( RGB(192,192,192) );
  393. }
  394. if ((HWND)lParam == hwndListMsg) {
  395. SetBkColor( (HDC)wParam, RGB(192,192,192) );
  396. return (LPARAM)CreateSolidBrush( RGB(192,192,192) );
  397. }
  398. return 0;
  399. case WM_DESTROY:
  400. ServiceStop();
  401. #ifdef FAX_HEAP_DEBUG
  402. PrintAllocations();
  403. #endif
  404. PostQuitMessage( 0 );
  405. return 0;
  406. }
  407. return DefWindowProc( hwnd, message, wParam, lParam );
  408. }