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.

369 lines
7.9 KiB

  1. /*************************************************************************
  2. **
  3. ** OLE 2.0 Sample Code
  4. **
  5. ** status.c
  6. **
  7. ** This file contains the window handlers, and various initialization
  8. ** and utility functions for an application status bar.
  9. **
  10. ** (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved
  11. **
  12. *************************************************************************/
  13. // Application specific include files
  14. #include "outline.h"
  15. #include "message.h"
  16. #include "status.h"
  17. // Current status message.
  18. static LPSTR lpszStatusMessage = NULL;
  19. // Window proc for status window.
  20. LRESULT FAR PASCAL StatusWndProc
  21. (HWND hwnd, unsigned message, WPARAM wParam, LPARAM lParam);
  22. // List of all constant messages.
  23. static STATMESG ControlList[2] =
  24. {
  25. { STATUS_READY, "Ready." },
  26. { STATUS_BLANK, " " }
  27. };
  28. // List of all system menu messages.
  29. static STATMESG SysMenuList[16] =
  30. {
  31. { SC_SIZE, "Change the size of the window." },
  32. { SC_MOVE, "Move the window." },
  33. { SC_MINIMIZE, "Make the window iconic." },
  34. { SC_MAXIMIZE, "Make the window the size of the screen." },
  35. { SC_NEXTWINDOW, "Activate the next window." },
  36. { SC_PREVWINDOW, "Activate the previous window." },
  37. { SC_CLOSE, "Close this window." },
  38. { SC_VSCROLL, "Vertical scroll?" },
  39. { SC_HSCROLL, "Horizontal scroll?" },
  40. { SC_MOUSEMENU, "A menu for mice." },
  41. { SC_KEYMENU, "A menu for keys (I guess)." },
  42. { SC_ARRANGE, "Arrange something." },
  43. { SC_RESTORE, "Make the window noramally sized." },
  44. { SC_TASKLIST, "Put up the task list dialog." },
  45. { SC_SCREENSAVE, "Save the screen! Run for your life!" },
  46. { SC_HOTKEY, "Boy, is this key hot!" }
  47. };
  48. // Message type for popup messages.
  49. typedef struct {
  50. HMENU hmenu;
  51. char string[MAX_MESSAGE];
  52. } STATPOPUP;
  53. // List of all popup messages.
  54. static STATPOPUP PopupList[NUM_POPUP];
  55. static UINT nCurrentPopup = 0;
  56. /* RegisterStatusClass
  57. * -------------------
  58. *
  59. * Creates classes for status window.
  60. *
  61. * HINSTANCE hInstance
  62. *
  63. * RETURNS: TRUE if class successfully registered.
  64. * FALSE otherwise.
  65. *
  66. * CUSTOMIZATION: Change class name.
  67. *
  68. */
  69. BOOL RegisterStatusClass(HINSTANCE hInstance)
  70. {
  71. WNDCLASS wc;
  72. wc.lpszClassName = "ObjStatus";
  73. wc.lpfnWndProc = StatusWndProc;
  74. wc.style = 0;
  75. wc.hInstance = hInstance;
  76. wc.hIcon = NULL;
  77. wc.cbClsExtra = 4;
  78. wc.cbWndExtra = 0;
  79. wc.lpszMenuName = NULL;
  80. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  81. wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  82. if (!RegisterClass(&wc))
  83. return FALSE;
  84. return TRUE;
  85. }
  86. /* CreateStatusWindow
  87. * ------------------
  88. *
  89. * Creates status window.
  90. *
  91. * HWND hwndMain
  92. *
  93. * RETURNS: HWND of status window if creation is successful.
  94. * NULL otherwise.
  95. *
  96. * CUSTOMIZATION: Change class name.
  97. *
  98. */
  99. HWND CreateStatusWindow(HWND hWndApp, HINSTANCE hInst)
  100. {
  101. RECT rect;
  102. int width, height;
  103. HWND hWndStatusBar;
  104. lpszStatusMessage = ControlList[0].string;
  105. GetClientRect(hWndApp, &rect);
  106. width = rect.right - rect.left;
  107. height = rect.bottom - rect.top;
  108. hWndStatusBar = CreateWindow (
  109. "ObjStatus",
  110. "SvrStatus",
  111. WS_CHILD |
  112. WS_CLIPSIBLINGS |
  113. WS_VISIBLE,
  114. 0, height - STATUS_HEIGHT,
  115. width,
  116. STATUS_HEIGHT,
  117. hWndApp,
  118. NULL,
  119. hInst,
  120. NULL
  121. );
  122. return hWndStatusBar;
  123. }
  124. /* DestroyStatusWindow
  125. * -------------------
  126. *
  127. * Destroys status window.
  128. *
  129. * CUSTOMIZATION: None.
  130. *
  131. */
  132. void DestroyStatusWindow(HWND hWndStatusBar)
  133. {
  134. DestroyWindow(hWndStatusBar);
  135. }
  136. /* AssignPopupMessage
  137. * ------------------
  138. *
  139. * Associates a string with a popup menu handle.
  140. *
  141. * HMENU hmenuPopup
  142. * char *szMessage
  143. *
  144. * CUSTOMIZATION: None.
  145. *
  146. */
  147. void AssignPopupMessage(HMENU hmenuPopup, char *szMessage)
  148. {
  149. if (nCurrentPopup < NUM_POPUP) {
  150. PopupList[nCurrentPopup].hmenu = hmenuPopup;
  151. lstrcpy(PopupList[nCurrentPopup].string, szMessage);
  152. ++nCurrentPopup;
  153. }
  154. }
  155. /* SetStatusText
  156. * -------------
  157. *
  158. * Show the message in the status line.
  159. */
  160. void SetStatusText(HWND hWndStatusBar, LPSTR lpszMessage)
  161. {
  162. lpszStatusMessage = lpszMessage;
  163. InvalidateRect (hWndStatusBar, (LPRECT)NULL, TRUE);
  164. UpdateWindow (hWndStatusBar);
  165. }
  166. /* GetItemMessage
  167. * --------------
  168. *
  169. * Retrieve the message associated with the given menu command item number.
  170. *
  171. * UINT wIDItem
  172. * LPVOID lpDoc
  173. *
  174. * CUSTOMIZATION: None.
  175. *
  176. */
  177. void GetItemMessage(UINT wIDItem, LPSTR FAR* lplpszMessage)
  178. {
  179. UINT i;
  180. *lplpszMessage = ControlList[1].string;
  181. for (i = 0; i < NUM_STATS; ++i) {
  182. if (wIDItem == MesgList[i].wIDItem) {
  183. *lplpszMessage = MesgList[i].string;
  184. break;
  185. }
  186. }
  187. }
  188. /* GetPopupMessage
  189. * ---------------
  190. *
  191. * Retrieve the message associated with the given popup menu.
  192. *
  193. * HMENU hmenuPopup
  194. * LPVOID lpDoc
  195. *
  196. * CUSTOMIZATION: None.
  197. *
  198. */
  199. void GetPopupMessage(HMENU hmenuPopup, LPSTR FAR* lplpszMessage)
  200. {
  201. UINT i;
  202. *lplpszMessage = ControlList[1].string;
  203. for (i = 0; i < nCurrentPopup; ++i) {
  204. if (hmenuPopup == PopupList[i].hmenu) {
  205. *lplpszMessage = PopupList[i].string;
  206. break;
  207. }
  208. }
  209. }
  210. /* GetSysMenuMessage
  211. * -----------------
  212. *
  213. * Retrieves the messages to correspond to items on the system menu.
  214. *
  215. *
  216. * UINT wIDItem
  217. * LPVOID lpDoc
  218. *
  219. * CUSTOMIZATION: None.
  220. *
  221. */
  222. void GetSysMenuMessage(UINT wIDItem, LPSTR FAR* lplpszMessage)
  223. {
  224. UINT i;
  225. *lplpszMessage = ControlList[1].string;
  226. for (i = 0; i < 16; ++i) {
  227. if (wIDItem == SysMenuList[i].wIDItem) {
  228. *lplpszMessage = SysMenuList[i].string;
  229. break;
  230. }
  231. }
  232. }
  233. /* GetControlMessage
  234. * -----------------
  235. *
  236. * Retrieves the general system messages.
  237. *
  238. *
  239. * STATCONTROL scCommand
  240. * LPVOID lpDoc
  241. *
  242. * CUSTOMIZATION: Add new messages.
  243. *
  244. */
  245. void GetControlMessage(STATCONTROL scCommand, LPSTR FAR* lplpszMessage)
  246. {
  247. UINT i;
  248. *lplpszMessage = ControlList[1].string;
  249. for (i = 0; i < 2; ++i) {
  250. if ((UINT)scCommand == ControlList[i].wIDItem) {
  251. *lplpszMessage = ControlList[i].string;
  252. break;
  253. }
  254. }
  255. }
  256. /* StatusWndProc
  257. * -------------
  258. *
  259. * Message handler for the statusbar window.
  260. *
  261. *
  262. * CUSTOMIZATION: None
  263. *
  264. */
  265. LRESULT FAR PASCAL StatusWndProc
  266. (HWND hwnd, unsigned message, WPARAM wParam, LPARAM lParam)
  267. {
  268. if (message == WM_PAINT) {
  269. RECT rc;
  270. HDC hdc;
  271. PAINTSTRUCT paintstruct;
  272. HPEN hpenOld;
  273. HPEN hpen;
  274. HFONT hfontOld;
  275. HFONT hfont;
  276. HPALETTE hpalOld = NULL;
  277. POINT point;
  278. BeginPaint (hwnd, &paintstruct);
  279. hdc = GetDC (hwnd);
  280. GetClientRect (hwnd, (LPRECT) &rc);
  281. hpenOld = SelectObject (hdc, GetStockObject (BLACK_PEN));
  282. MoveToEx (hdc, 0, 0, &point);
  283. LineTo (hdc, rc.right, 0);
  284. SelectObject (hdc, GetStockObject (WHITE_PEN));
  285. MoveToEx (hdc, STATUS_RRIGHT, STATUS_RTOP, &point);
  286. LineTo (hdc, STATUS_RRIGHT, STATUS_RBOTTOM);
  287. LineTo (hdc, STATUS_RLEFT-1, STATUS_RBOTTOM);
  288. hpen = CreatePen (PS_SOLID, 1, /* DKGRAY */ 0x00808080);
  289. SelectObject (hdc, hpen);
  290. MoveToEx (hdc, STATUS_RLEFT, STATUS_RBOTTOM-1, &point);
  291. LineTo (hdc, STATUS_RLEFT, STATUS_RTOP);
  292. LineTo (hdc, STATUS_RRIGHT, STATUS_RTOP);
  293. SetBkMode (hdc, TRANSPARENT);
  294. SetTextAlign (hdc, TA_LEFT | TA_TOP);
  295. hfont = CreateFont (STATUS_THEIGHT, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
  296. FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
  297. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  298. DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
  299. hfontOld = SelectObject(hdc, hfont);
  300. TextOut (hdc, STATUS_TLEFT, STATUS_TTOP,
  301. lpszStatusMessage,
  302. lstrlen(lpszStatusMessage));
  303. // Restore original objects
  304. SelectObject (hdc, hfontOld);
  305. SelectObject (hdc, hpenOld);
  306. DeleteObject (hpen);
  307. DeleteObject (hfont);
  308. ReleaseDC (hwnd, hdc);
  309. EndPaint (hwnd, &paintstruct);
  310. return 0;
  311. }
  312. else {
  313. return DefWindowProc(hwnd, message, wParam, lParam);
  314. }
  315. }