Leaked source code of windows server 2003
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.

365 lines
8.2 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: wndstuff.cpp
  3. *
  4. * This file contains the code to support a simple window that has
  5. * a menu with a single item called "Test". When "Test" is selected
  6. * vTest(HWND) is called.
  7. *
  8. * Created: 09-Dec-1992 10:44:31
  9. * Author: Kirk Olynyk [kirko]
  10. *
  11. * Copyright (c) 1991 Microsoft Corporation
  12. *
  13. \**************************************************************************/
  14. // for Win95 compile
  15. #undef UNICODE
  16. #undef _UNICODE
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <tchar.h>
  20. #include <objbase.h>
  21. #include <gdiplus.h>
  22. #include "wndstuff.h"
  23. #include "../gpinit.inc"
  24. HINSTANCE ghInstance;
  25. HWND ghwndMain;
  26. HWND ghwndDebug;
  27. HWND ghwndList;
  28. HBRUSH ghbrWhite;
  29. /***************************************************************************\
  30. * lMainWindowProc(hwnd, message, wParam, lParam)
  31. *
  32. * Processes all messages for the main window.
  33. *
  34. * History:
  35. * 04-07-91 -by- KentD
  36. * Wrote it.
  37. \***************************************************************************/
  38. LONG_PTR
  39. lMainWindowProc(
  40. HWND hwnd,
  41. UINT message,
  42. WPARAM wParam,
  43. LPARAM lParam
  44. )
  45. {
  46. PAINTSTRUCT ps;
  47. switch (message)
  48. {
  49. case WM_CREATE:
  50. break;
  51. case WM_COMMAND:
  52. switch(LOWORD(wParam))
  53. {
  54. case MM_TEST:
  55. Test(hwnd);
  56. break;
  57. default:
  58. break;
  59. }
  60. break;
  61. case WM_DESTROY:
  62. DeleteObject(ghbrWhite);
  63. PostQuitMessage(0);
  64. return(DefWindowProc(hwnd, message, wParam, lParam));
  65. default:
  66. return(DefWindowProc(hwnd, message, wParam, lParam));
  67. }
  68. return(0);
  69. }
  70. /******************************Public*Routine******************************\
  71. * DebugWndProc
  72. *
  73. * List box is maintained here.
  74. *
  75. \**************************************************************************/
  76. LONG_PTR FAR PASCAL DebugWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  77. {
  78. RECT rcl;
  79. HDC hdc;
  80. LONG_PTR lRet = 0;
  81. // Process window message.
  82. switch (message)
  83. {
  84. case WM_SIZE:
  85. lRet = DefWindowProc(ghwndList, message, wParam, lParam);
  86. GetClientRect(ghwndMain, &rcl);
  87. MoveWindow(
  88. ghwndList,
  89. rcl.left, rcl.top,
  90. (rcl.right - rcl.left), (rcl.bottom - rcl.top),
  91. TRUE
  92. );
  93. UpdateWindow(ghwndList);
  94. break;
  95. case WM_DESTROY:
  96. PostQuitMessage(0);
  97. break;
  98. default:
  99. lRet = DefWindowProc(hwnd, message, wParam, lParam);
  100. break;
  101. }
  102. return lRet;
  103. }
  104. /******************************Public*Routine******************************\
  105. * LBprintf
  106. *
  107. * ListBox printf implementation.
  108. *
  109. * History:
  110. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  111. * Wrote it.
  112. \**************************************************************************/
  113. void LBprintf(PCH msg, ...)
  114. {
  115. if (ghwndList)
  116. {
  117. va_list ap;
  118. char buffer[256];
  119. va_start(ap, msg);
  120. vsprintf(buffer, msg, ap);
  121. SendMessage(ghwndList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
  122. SendMessage(ghwndList, WM_SETREDRAW, (WPARAM) TRUE, (LPARAM) 0);
  123. InvalidateRect(ghwndList, NULL, TRUE);
  124. UpdateWindow(ghwndList);
  125. va_end(ap);
  126. }
  127. }
  128. /******************************Public*Routine******************************\
  129. * LBreset
  130. *
  131. * Reset ListBox state (clear).
  132. *
  133. * History:
  134. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  135. * Wrote it.
  136. \**************************************************************************/
  137. void LBreset()
  138. {
  139. if (ghwndList)
  140. SendMessage(ghwndList, LB_RESETCONTENT, (WPARAM) FALSE, (LPARAM) 0);
  141. }
  142. /***************************************************************************\
  143. * bInitApp()
  144. *
  145. * Initializes app.
  146. *
  147. * History:
  148. * 04-07-91 -by- KentD
  149. * Wrote it.
  150. \***************************************************************************/
  151. BOOL bInitApp(BOOL debug)
  152. {
  153. WNDCLASS wc;
  154. ghbrWhite = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
  155. wc.style = 0;
  156. wc.lpfnWndProc = lMainWindowProc;
  157. wc.cbClsExtra = 0;
  158. wc.cbWndExtra = 0;
  159. wc.hInstance = ghInstance;
  160. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  161. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  162. wc.hbrBackground = ghbrWhite;
  163. wc.lpszMenuName = _T("MainMenu");
  164. wc.lpszClassName = _T("TestClass");
  165. if (!RegisterClass(&wc))
  166. {
  167. return(FALSE);
  168. }
  169. ghwndMain =
  170. CreateWindowEx(
  171. 0,
  172. _T("TestClass"),
  173. _T("Win32 Test"),
  174. WS_OVERLAPPED |
  175. WS_CAPTION |
  176. WS_BORDER |
  177. WS_THICKFRAME |
  178. WS_MAXIMIZEBOX |
  179. WS_MINIMIZEBOX |
  180. WS_CLIPCHILDREN |
  181. WS_VISIBLE |
  182. WS_SYSMENU,
  183. 80,
  184. 70,
  185. 500,
  186. 500,
  187. NULL,
  188. NULL,
  189. ghInstance,
  190. NULL);
  191. if (ghwndMain == NULL)
  192. {
  193. return(FALSE);
  194. }
  195. if (debug)
  196. {
  197. RECT rcl;
  198. memset(&wc, 0, sizeof(wc));
  199. wc.style = 0;
  200. wc.lpfnWndProc = DebugWndProc;
  201. wc.cbClsExtra = 0;
  202. wc.cbWndExtra = 0;
  203. wc.hInstance = ghInstance;
  204. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  205. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  206. wc.hbrBackground = ghbrWhite;
  207. wc.lpszClassName = "DebugWClass";
  208. RegisterClass(&wc);
  209. ghwndDebug = CreateWindow(
  210. "DebugWClass",
  211. "Debug output",
  212. WS_OVERLAPPEDWINDOW|WS_MAXIMIZE,
  213. 600,
  214. 70,
  215. 300,
  216. 500,
  217. NULL,
  218. NULL,
  219. ghInstance,
  220. NULL
  221. );
  222. if (ghwndDebug)
  223. {
  224. ShowWindow(ghwndDebug, SW_NORMAL);
  225. UpdateWindow(ghwndDebug);
  226. // Create the list box to fill the main window.
  227. GetClientRect(ghwndDebug, &rcl);
  228. ghwndList = CreateWindow(
  229. "LISTBOX",
  230. "Debug output",
  231. WS_CHILD | WS_VISIBLE | WS_VSCROLL
  232. | WS_HSCROLL | LBS_NOINTEGRALHEIGHT,
  233. rcl.left, rcl.top,
  234. (rcl.right - rcl.left), (rcl.bottom - rcl.top),
  235. ghwndDebug,
  236. NULL,
  237. ghInstance,
  238. NULL
  239. );
  240. if (ghwndList)
  241. {
  242. SendMessage(
  243. ghwndList,
  244. WM_SETFONT,
  245. (WPARAM) GetStockObject(ANSI_FIXED_FONT),
  246. (LPARAM) FALSE
  247. );
  248. LBreset();
  249. ShowWindow(ghwndList, SW_NORMAL);
  250. UpdateWindow(ghwndList);
  251. }
  252. }
  253. }
  254. SetFocus(ghwndMain);
  255. return(TRUE);
  256. }
  257. /***************************************************************************\
  258. * main(argc, argv[])
  259. *
  260. * Sets up the message loop.
  261. *
  262. * History:
  263. * 04-07-91 -by- KentD
  264. * Wrote it.
  265. \***************************************************************************/
  266. _cdecl
  267. main(
  268. INT argc,
  269. PCHAR argv[])
  270. {
  271. MSG msg;
  272. HACCEL haccel;
  273. CHAR* pSrc;
  274. CHAR* pDst;
  275. if (!gGdiplusInitHelper.IsValid())
  276. {
  277. return 0;
  278. }
  279. BOOL wantDebugWindow = FALSE;
  280. CoInitialize(NULL);
  281. // Parse arguments
  282. for (argc--, argv++ ; argc && '-' == **argv ; argc--, argv++ )
  283. {
  284. switch ( *(++(*argv)) )
  285. {
  286. case 'd':
  287. case 'D':
  288. wantDebugWindow = TRUE;
  289. break;
  290. }
  291. }
  292. ghInstance = GetModuleHandle(NULL);
  293. if (!bInitApp(wantDebugWindow))
  294. {
  295. return(0);
  296. }
  297. haccel = LoadAccelerators(ghInstance, MAKEINTRESOURCE(1));
  298. while (GetMessage(&msg, NULL, 0, 0))
  299. {
  300. if (!TranslateAccelerator(msg.hwnd, haccel, &msg))
  301. {
  302. TranslateMessage(&msg);
  303. DispatchMessage(&msg);
  304. }
  305. }
  306. CoUninitialize();
  307. return(1);
  308. }