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.

240 lines
5.3 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: viewer.c
  3. *
  4. * Main window.
  5. *
  6. * Created: 14-Mar-1995 23:42:08
  7. * Author: Gilman Wong [gilmanw]
  8. *
  9. * Copyright (c) 1995 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <ctype.h>
  16. #include "global.h"
  17. #include "glwindow.h"
  18. // Window functions.
  19. void MyCreateWindows(HINSTANCE);
  20. long FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
  21. // Global window handles. Always handy to have around.
  22. HINSTANCE ghInstance;
  23. HWND hwndMain = (HWND) NULL;
  24. HWND hwndList = (HWND) NULL;
  25. /******************************Public*Routine******************************\
  26. * WinMain
  27. *
  28. * Main loop.
  29. *
  30. * History:
  31. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  32. * Wrote it.
  33. \**************************************************************************/
  34. int WINAPI
  35. WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
  36. int nCmdShow)
  37. {
  38. MSG msg;
  39. SCENE *scene;
  40. MyCreateWindows(hInstance);
  41. MyCreateGLWindow(hInstance, lpCmdLine);
  42. while ( GetMessage(&msg, (HWND) NULL, (UINT) NULL, (UINT) NULL) )
  43. {
  44. TranslateMessage(&msg);
  45. DispatchMessage(&msg);
  46. }
  47. return (msg.wParam);
  48. }
  49. /******************************Public*Routine******************************\
  50. * MyCreateWindows
  51. *
  52. * Setup the windows.
  53. *
  54. * History:
  55. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  56. * Wrote it.
  57. \**************************************************************************/
  58. void MyCreateWindows(HINSTANCE hInstance)
  59. {
  60. WNDCLASS wc;
  61. RECT rcl;
  62. ghInstance = hInstance;
  63. // Register and create the main window, which contains the info listbox.
  64. wc.style = 0;
  65. wc.lpfnWndProc = MainWndProc;
  66. wc.cbClsExtra = 0;
  67. wc.cbWndExtra = 0;
  68. wc.hInstance = hInstance;
  69. wc.hIcon = LoadIcon(hInstance, "ViewerIcon");
  70. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  71. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  72. wc.lpszMenuName = NULL;
  73. wc.lpszClassName = "MainWClass";
  74. RegisterClass(&wc);
  75. hwndMain = CreateWindow(
  76. "MainWClass",
  77. "3D Viewer",
  78. WS_OVERLAPPEDWINDOW|WS_MAXIMIZE,
  79. 0,
  80. 0,
  81. 300,
  82. 768,
  83. NULL,
  84. NULL,
  85. hInstance,
  86. NULL
  87. );
  88. if (hwndMain)
  89. {
  90. ShowWindow(hwndMain, SW_NORMAL);
  91. UpdateWindow(hwndMain);
  92. // Create the list box to fill the main window.
  93. GetClientRect(hwndMain, &rcl);
  94. hwndList = CreateWindow(
  95. "LISTBOX",
  96. "3D Viewer Info",
  97. WS_CHILD | WS_VISIBLE | WS_VSCROLL
  98. | WS_HSCROLL | LBS_NOINTEGRALHEIGHT,
  99. rcl.left, rcl.top,
  100. (rcl.right - rcl.left), (rcl.bottom - rcl.top),
  101. hwndMain,
  102. NULL,
  103. hInstance,
  104. NULL
  105. );
  106. if (hwndList)
  107. {
  108. SendMessage(
  109. hwndList,
  110. WM_SETFONT,
  111. (WPARAM) GetStockObject(ANSI_FIXED_FONT),
  112. (LPARAM) FALSE
  113. );
  114. LBreset();
  115. ShowWindow(hwndList, SW_NORMAL);
  116. UpdateWindow(hwndList);
  117. }
  118. }
  119. }
  120. /******************************Public*Routine******************************\
  121. * MainWndProc
  122. *
  123. * WndProc for the main window. List box is maintained here.
  124. *
  125. * History:
  126. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  127. * Wrote it.
  128. \**************************************************************************/
  129. long FAR PASCAL MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  130. {
  131. RECT rcl;
  132. long lRet = 0;
  133. // Process window message.
  134. switch (message)
  135. {
  136. case WM_SIZE:
  137. lRet = DefWindowProc(hwndList, message, wParam, lParam);
  138. GetClientRect(hwndMain, &rcl);
  139. MoveWindow(
  140. hwndList,
  141. rcl.left, rcl.top,
  142. (rcl.right - rcl.left), (rcl.bottom - rcl.top),
  143. TRUE
  144. );
  145. UpdateWindow(hwndList);
  146. break;
  147. case WM_KEYDOWN:
  148. switch (wParam)
  149. {
  150. case VK_ESCAPE: // <ESC> is quick exit
  151. PostMessage(hwnd, WM_DESTROY, 0, 0);
  152. break;
  153. default:
  154. break;
  155. }
  156. break;
  157. case WM_DESTROY:
  158. PostQuitMessage(0);
  159. break;
  160. default:
  161. lRet = DefWindowProc(hwnd, message, wParam, lParam);
  162. break;
  163. }
  164. return lRet;
  165. }
  166. /******************************Public*Routine******************************\
  167. * LBprintf
  168. *
  169. * ListBox printf implementation.
  170. *
  171. * History:
  172. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  173. * Wrote it.
  174. \**************************************************************************/
  175. void LBprintf(PCH msg, ...)
  176. {
  177. va_list ap;
  178. char buffer[256];
  179. va_start(ap, msg);
  180. vsprintf(buffer, msg, ap);
  181. SendMessage(hwndList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
  182. SendMessage(hwndList, WM_SETREDRAW, (WPARAM) TRUE, (LPARAM) 0);
  183. InvalidateRect(hwndList, NULL, TRUE);
  184. UpdateWindow(hwndList);
  185. va_end(ap);
  186. }
  187. /******************************Public*Routine******************************\
  188. * LBreset
  189. *
  190. * Reset ListBox state (clear).
  191. *
  192. * History:
  193. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  194. * Wrote it.
  195. \**************************************************************************/
  196. void LBreset()
  197. {
  198. SendMessage(hwndList, LB_RESETCONTENT, (WPARAM) FALSE, (LPARAM) 0);
  199. }