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.

297 lines
8.1 KiB

  1. #include "setedit.h"
  2. #include "status.h" // External declarations for this file
  3. #include <stdio.h> // for sprintf.
  4. #include <stdarg.h> // For ANSI variable args. Dont use UNIX <varargs.h>
  5. #include "perfmops.h" // for SmallFileSizeString
  6. #include "utils.h"
  7. //================================//
  8. // Options for PaintStatusBar //
  9. //================================//
  10. #define PaintText 1
  11. #define PaintIcons 2
  12. #define PaintBoundary 4
  13. #define PaintAll (PaintText + PaintIcons + PaintBoundary)
  14. //==========================================================================//
  15. // Constants //
  16. //==========================================================================//
  17. #define szStatusClass TEXT("PerfmonStatusClass")
  18. #define dwStatusClassStyle (CS_HREDRAW | CS_VREDRAW | CS_OWNDC)
  19. #define iStatusClassExtra (0)
  20. #define iStatusWindowExtra (0)
  21. #define dwStatusWindowStyle (WS_CHILD | WS_VISIBLE)
  22. //==========================================================================//
  23. // Local Data //
  24. //==========================================================================//
  25. HDC hStatusDC ; // for OWN_DC
  26. int yStatusHeight ;
  27. int szStatusLineLen ; // no. of char. in szStatusLine
  28. TCHAR szStatusLine [MessageLen+ResourceStringLen] ;
  29. // TCHAR szCurrentActivity [ResourceStringLen] ;
  30. // TCHAR szStatusFormat [ResourceStringLen] ;
  31. TCHAR szStatusFormat2 [ResourceStringLen] ;
  32. //==========================================================================//
  33. // Macros //
  34. //==========================================================================//
  35. #define StatusTopMargin() (2)
  36. #define StatusLeftMargin() (2)
  37. //==========================================================================//
  38. // Local Functions //
  39. //==========================================================================//
  40. //==========================================================================//
  41. // Message Handlers //
  42. //==========================================================================//
  43. void static OnCreate (HWND hWnd)
  44. /*
  45. Effect: Perform any actions needed when a status window is created.
  46. In particular, set the instance data to initial values,
  47. determine the size and placement of the various elements
  48. of the status display.
  49. Called By: StatusWndProc only, in response to a WM_CREATE message.
  50. */
  51. { // OnCreate
  52. HDC hDC ;
  53. hDC = hStatusDC = GetDC (hWnd) ;
  54. SelectFont (hDC, hFontScales) ;
  55. SetBkColor (hDC, ColorBtnFace) ;
  56. SetTextAlign (hDC, TA_LEFT) ;
  57. SetBkMode (hDC, OPAQUE) ;
  58. yStatusHeight = 2 * StatusTopMargin () +
  59. FontHeight (hDC, TRUE) +
  60. 2 * ThreeDPad ;
  61. // StringLoad (IDS_CURRENTACTIVITY, szCurrentActivity) ;
  62. // StringLoad (IDS_STATUSFORMAT, szStatusFormat) ;
  63. StringLoad (IDS_STATUSFORMAT2, szStatusFormat2) ;
  64. StatusLineReady (hWnd) ;
  65. } // OnCreate
  66. void static OnDestroy (HWND hWnd)
  67. {
  68. ReleaseDC (hWnd, hStatusDC) ;
  69. } // OnDestroy
  70. void static PaintStatusBar (HWND hWnd, HDC hDC, int PaintOptions)
  71. /*
  72. Effect: Paint the invalid surface of hWnd. Draw each label, each
  73. recessed value box, and each value.
  74. Called By: StatusWndProc only, in response to a WM_PAINT message.
  75. */
  76. {
  77. RECT rectClient ;
  78. if (bPerfmonIconic) {
  79. // no need to draw anything if iconic
  80. return ;
  81. }
  82. GetClientRect (hWnd, &rectClient) ;
  83. RectContract (&rectClient, StatusTopMargin (), StatusLeftMargin ()) ;
  84. if (PaintOptions == PaintAll) {
  85. ThreeDConcave1 (hDC,
  86. rectClient.left, rectClient.top,
  87. rectClient.right, rectClient.bottom) ;
  88. }
  89. rectClient.left += StatusLeftMargin () ;
  90. if (PaintOptions & PaintText) {
  91. rectClient.left += 1 ;
  92. rectClient.top += 1 ;
  93. rectClient.right -= 1 ;
  94. rectClient.bottom -= 1 ;
  95. ExtTextOut (hDC, rectClient.left, rectClient.top, ETO_CLIPPED | ETO_OPAQUE,
  96. &rectClient, szStatusLine, szStatusLineLen, NULL) ;
  97. }
  98. } // PaintStatusBar
  99. LRESULT
  100. APIENTRY
  101. StatusWndProc (
  102. HWND hWnd,
  103. UINT wMsg,
  104. WPARAM wParam,
  105. LPARAM lParam
  106. )
  107. { // StatusWndProc
  108. BOOL bCallDefProc ;
  109. LRESULT lReturnValue ;
  110. HDC hDC ;
  111. PAINTSTRUCT ps ;
  112. bCallDefProc = FALSE ;
  113. lReturnValue = 0L ;
  114. switch (wMsg) { // switch
  115. case WM_PAINT:
  116. hDC = BeginPaint (hWnd, &ps) ;
  117. PaintStatusBar (hWnd, hDC, PaintAll) ;
  118. EndPaint (hWnd, &ps) ;
  119. break ;
  120. case WM_CREATE:
  121. OnCreate (hWnd) ;
  122. break ;
  123. case WM_DESTROY:
  124. OnDestroy (hWnd) ;
  125. break ;
  126. default:
  127. bCallDefProc = TRUE ;
  128. } // switch
  129. if (bCallDefProc)
  130. lReturnValue = DefWindowProc (hWnd, wMsg, wParam, lParam) ;
  131. return (lReturnValue);
  132. } // StatusWndProc
  133. int StatusHeight (HWND hWnd)
  134. /*
  135. Effect: A status window has a preferred height, based on the font
  136. used in its display. Return the preferred height, determined
  137. when the window was created.
  138. Assert: OnCreate has already been called, and it set
  139. StatusData.yHeight.
  140. */
  141. {
  142. return (yStatusHeight) ;
  143. }
  144. HWND CreatePMStatusWindow (HWND hWnd)
  145. {
  146. return (CreateWindow (szStatusClass, // class
  147. NULL, // caption
  148. dwStatusWindowStyle, // window style
  149. 0, 0, // position
  150. 0, 0, // size
  151. hWnd, // parent window
  152. NULL, // menu
  153. hInstance, // program instance
  154. NULL)) ; // user-supplied data
  155. } // CreateStatusWindow
  156. BOOL StatusInitializeApplication (void)
  157. /*
  158. Called By: InitializeApplication only
  159. */
  160. {
  161. WNDCLASS wc ;
  162. wc.style = dwStatusClassStyle ;
  163. wc.lpfnWndProc = StatusWndProc ;
  164. wc.hInstance = hInstance ;
  165. wc.cbClsExtra = iStatusClassExtra ;
  166. wc.cbWndExtra = iStatusWindowExtra ;
  167. wc.hIcon = NULL ;
  168. wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  169. wc.hbrBackground = hbLightGray ;
  170. wc.lpszMenuName = NULL ;
  171. wc.lpszClassName = szStatusClass ;
  172. return (RegisterClass (&wc)) ;
  173. }
  174. BOOL _cdecl StatusLine (HWND hWnd,
  175. WORD wStringID, ...)
  176. {
  177. TCHAR szFormat [MessageLen] ;
  178. va_list vaList ;
  179. if (wStringID == 0) {
  180. return (TRUE) ;
  181. }
  182. strclr (szStatusLine) ;
  183. if (LoadString (hInstance, wStringID, szFormat, MessageLen)) {
  184. va_start (vaList, wStringID) ;
  185. wvsprintf (szStatusLine, szFormat, vaList) ;
  186. va_end (vaList) ;
  187. dwCurrentMenuID = MenuIDToHelpID (wStringID) ;
  188. szStatusLineLen = lstrlen (szStatusLine) ;
  189. } else {
  190. dwCurrentMenuID = 0 ;
  191. szStatusLineLen = 0 ;
  192. }
  193. PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ;
  194. return (TRUE) ;
  195. } // StatusLine
  196. void StatusLineReady (HWND hWnd)
  197. {
  198. LPTSTR pFileName = NULL ;
  199. pFileName = pChartFileName ;
  200. if (pFileName) {
  201. TSPRINTF (szStatusLine, szStatusFormat2, pFileName) ;
  202. } else {
  203. szStatusLine[0] = TEXT('\0') ;
  204. }
  205. szStatusLineLen = lstrlen (szStatusLine) ;
  206. PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ;
  207. }
  208. void StatusUpdateIcons (HWND hWndStatus)
  209. {
  210. PaintStatusBar (hWndStatus, hStatusDC, PaintIcons) ;
  211. }