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.

342 lines
8.7 KiB

  1. /**************************************************************************
  2. *
  3. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. * PURPOSE.
  7. *
  8. * Copyright (c) 1992 - 1995 Microsoft Corporation. All Rights Reserved.
  9. *
  10. **************************************************************************/
  11. /****************************************************************************
  12. *
  13. * status.c: Status bar window
  14. *
  15. * Vidcap32 Source code
  16. *
  17. ***************************************************************************/
  18. #include <windows.h>
  19. #include <windowsx.h>
  20. //#include <win32.h>
  21. #include <mmsystem.h>
  22. #include "status.h"
  23. /* for compiling under win3.0 - we don't have this attribute */
  24. #ifndef COLOR_BTNHIGHLIGHT
  25. #define COLOR_BTNHIGHLIGHT 20
  26. #endif
  27. #ifdef _WIN32
  28. typedef WNDPROC LPWNDPROC;
  29. #else
  30. typedef long (FAR PASCAL *LPWNDPROC)();
  31. #endif
  32. // class names for status bar and static text windows
  33. TCHAR szStatusClass[] = "StatusClass";
  34. TCHAR szText[] = "SText";
  35. int gStatusStdHeight; // based on font metrics
  36. static HBRUSH ghbrBackground;
  37. static HANDLE ghFont;
  38. static HBRUSH ghbrHL, ghbrShadow;
  39. /* Function Prototypes */
  40. LRESULT FAR PASCAL statusWndProc(HWND hwnd, unsigned msg,
  41. WPARAM wParam, LPARAM lParam);
  42. LRESULT FAR PASCAL fnText(HWND, unsigned, WPARAM, LPARAM);
  43. static VOID NEAR PASCAL PaintText(HWND hwnd, HDC hdc);
  44. /*
  45. * create the brushes we need
  46. */
  47. void
  48. statusCreateTools(void)
  49. {
  50. HDC hdc;
  51. TEXTMETRIC tm;
  52. HFONT hfont;
  53. ghbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  54. ghbrHL = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT));
  55. ghbrShadow = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
  56. /* Create the font we'll use for the status bar - use system as default */
  57. ghFont = CreateFont(12, 0, // height, width
  58. 0, 0, // escapement, orientation
  59. FW_NORMAL, // weight,
  60. FALSE, FALSE, FALSE, // attributes
  61. ANSI_CHARSET, // charset
  62. OUT_DEFAULT_PRECIS, // output precision
  63. CLIP_DEFAULT_PRECIS, // clip precision
  64. DEFAULT_QUALITY, // quality
  65. VARIABLE_PITCH | FF_MODERN,
  66. "Helv");
  67. if (ghFont == NULL) {
  68. ghFont = GetStockObject(SYSTEM_FONT);
  69. }
  70. // find the char size to calc standard status bar height
  71. hdc = GetDC(NULL);
  72. hfont = SelectObject(hdc, ghFont);
  73. GetTextMetrics(hdc, &tm);
  74. SelectObject(hdc, hfont);
  75. ReleaseDC(NULL, hdc);
  76. gStatusStdHeight = tm.tmHeight * 3 / 2;
  77. }
  78. void
  79. statusDeleteTools(void)
  80. {
  81. DeleteObject(ghbrBackground);
  82. DeleteObject(ghbrHL);
  83. DeleteObject(ghbrShadow);
  84. DeleteObject(ghFont);
  85. }
  86. /*--------------------------------------------------------------+
  87. | statusInit - initialize for status window, register the |
  88. | Window's class. |
  89. | |
  90. +--------------------------------------------------------------*/
  91. #pragma alloc_text(INIT_TEXT, statusInit)
  92. BOOL statusInit(HANDLE hInst, HANDLE hPrev)
  93. {
  94. WNDCLASS cls;
  95. statusCreateTools();
  96. if (!hPrev){
  97. cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  98. cls.hIcon = NULL;
  99. cls.lpszMenuName = NULL;
  100. cls.lpszClassName = szStatusClass;
  101. cls.hbrBackground = ghbrBackground;
  102. cls.hInstance = hInst;
  103. cls.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  104. cls.lpfnWndProc = statusWndProc;
  105. cls.cbClsExtra = 0;
  106. cls.cbWndExtra = 0;
  107. if (!RegisterClass(&cls))
  108. return FALSE;
  109. cls.hCursor = LoadCursor(NULL,IDC_ARROW);
  110. cls.hIcon = NULL;
  111. cls.lpszMenuName = NULL;
  112. cls.lpszClassName = (LPSTR)szText;
  113. cls.hbrBackground = ghbrBackground;
  114. cls.hInstance = hInst;
  115. cls.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  116. cls.lpfnWndProc = (LPWNDPROC)fnText;
  117. cls.cbClsExtra = 0;
  118. cls.cbWndExtra = 0;
  119. if (!RegisterClass(&cls))
  120. return FALSE;
  121. }
  122. return TRUE;
  123. }
  124. /*
  125. * returns the recommended height for a status bar based on the
  126. * character dimensions of the font used
  127. */
  128. int
  129. statusGetHeight(void)
  130. {
  131. return(gStatusStdHeight);
  132. }
  133. /*--------------------------------------------------------------+
  134. | statusUpdateStatus - update the status line |
  135. | |
  136. | The argument can either be NULL, a string, or a resource ID |
  137. | cast to a LPCSTR with MAKEINTRESOURCE. |
  138. +--------------------------------------------------------------*/
  139. void statusUpdateStatus(HWND hwnd, LPCTSTR lpsz)
  140. {
  141. TCHAR ach[80];
  142. HWND hwndtext;
  143. if ((lpsz != NULL) && (HIWORD((DWORD) (DWORD_PTR) lpsz) == 0)) {
  144. LoadString(GetWindowInstance(hwnd), LOWORD((DWORD) (DWORD_PTR) lpsz), ach, sizeof(ach));
  145. lpsz = ach;
  146. }
  147. hwndtext = GetDlgItem(hwnd, 1);
  148. if (!lpsz || *lpsz == '\0') {
  149. SetWindowText(hwndtext,"");
  150. } else {
  151. SetWindowText(hwndtext, lpsz);
  152. }
  153. }
  154. /*--------------------------------------------------------------+
  155. | statusWndProc - window proc for status window |
  156. | |
  157. +--------------------------------------------------------------*/
  158. LRESULT FAR PASCAL
  159. statusWndProc(HWND hwnd, unsigned msg, WPARAM wParam, LPARAM lParam)
  160. {
  161. PAINTSTRUCT ps;
  162. HDC hdc;
  163. HWND hwndSText;
  164. switch(msg){
  165. case WM_CREATE:
  166. /* we need to create the static text control for the status bar */
  167. hwndSText = CreateWindow(
  168. szText,
  169. "",
  170. WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
  171. 0, 0, 0, 0,
  172. hwnd,
  173. (HMENU) 1, // child id
  174. GetWindowInstance(hwnd),
  175. NULL);
  176. if (!hwndSText) {
  177. return -1;
  178. }
  179. break;
  180. case WM_DESTROY:
  181. statusDeleteTools();
  182. break;
  183. case WM_SIZE:
  184. {
  185. RECT rc;
  186. GetClientRect(hwnd, &rc);
  187. MoveWindow(
  188. GetDlgItem(hwnd, 1), // get child window handle
  189. 2, 1, // xy just inside
  190. rc.right - 4,
  191. rc.bottom - 2,
  192. TRUE);
  193. break;
  194. }
  195. case WM_PAINT:
  196. hdc = BeginPaint(hwnd, &ps);
  197. // only the background and the child window need painting
  198. EndPaint(hwnd, &ps);
  199. break;
  200. case WM_SYSCOLORCHANGE:
  201. statusDeleteTools();
  202. statusCreateTools();
  203. #ifdef _WIN32
  204. SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (LONG_PTR) ghbrBackground);
  205. #else
  206. SetClassWord(hwnd, GCW_HBRBACKGROUND, (WORD) ghbrBackground);
  207. #endif
  208. break;
  209. case WM_ERASEBKGND:
  210. break;
  211. }
  212. return DefWindowProc(hwnd, msg, wParam, lParam);
  213. }
  214. /*
  215. * window proc for static text window
  216. */
  217. LRESULT FAR PASCAL
  218. fnText(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  219. {
  220. PAINTSTRUCT ps;
  221. switch (msg) {
  222. case WM_SETTEXT:
  223. DefWindowProc(hwnd, msg, wParam, lParam);
  224. InvalidateRect(hwnd,NULL,FALSE);
  225. UpdateWindow(hwnd);
  226. return 0L;
  227. case WM_ERASEBKGND:
  228. return 0L;
  229. case WM_PAINT:
  230. BeginPaint(hwnd, &ps);
  231. PaintText(hwnd, ps.hdc);
  232. EndPaint(hwnd, &ps);
  233. return 0L;
  234. }
  235. return DefWindowProc(hwnd, msg, wParam, lParam);
  236. }
  237. /*--------------------------------------------------------------+
  238. | PaintText - paint the shadowed static text field. |
  239. | |
  240. +--------------------------------------------------------------*/
  241. VOID NEAR PASCAL
  242. PaintText(HWND hwnd, HDC hdc)
  243. {
  244. RECT rc;
  245. TCHAR ach[128];
  246. int len;
  247. int dx, dy;
  248. RECT rcFill;
  249. HFONT hfontOld;
  250. HBRUSH hbrSave;
  251. GetClientRect(hwnd, &rc);
  252. len = GetWindowText(hwnd,ach,sizeof(ach));
  253. SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
  254. SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
  255. hfontOld = SelectObject(hdc, ghFont);
  256. rcFill.left = rc.left + 1;
  257. rcFill.right = rc.right - 1;
  258. rcFill.top = rc.top + 1;
  259. rcFill.bottom = rc.bottom - 1;
  260. /* move in some and do background and text in one swoosh */
  261. ExtTextOut(hdc,4,1,ETO_OPAQUE,&rcFill,ach,len,NULL);
  262. dx = rc.right - rc.left;
  263. dy = rc.bottom - rc.top;
  264. hbrSave = SelectObject(hdc, ghbrShadow);
  265. PatBlt(hdc, rc.left, rc.top, 1, dy, PATCOPY);
  266. PatBlt(hdc, rc.left, rc.top, dx, 1, PATCOPY);
  267. SelectObject(hdc, ghbrHL);
  268. PatBlt(hdc, rc.right-1, rc.top+1, 1, dy-1, PATCOPY);
  269. PatBlt(hdc, rc.left+1, rc.bottom -1, dx-1, 1, PATCOPY);
  270. if (hfontOld)
  271. SelectObject(hdc, hfontOld);
  272. if (hbrSave)
  273. SelectObject(hdc, hbrSave);
  274. return ;
  275. }