Windows NT 4.0 source code leak
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.

305 lines
8.1 KiB

4 years ago
  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. {
  80. // no need to draw anything if iconic
  81. return ;
  82. }
  83. GetClientRect (hWnd, &rectClient) ;
  84. RectContract (&rectClient, StatusTopMargin (), StatusLeftMargin ()) ;
  85. if (PaintOptions == PaintAll)
  86. {
  87. ThreeDConcave1 (hDC,
  88. rectClient.left, rectClient.top,
  89. rectClient.right, rectClient.bottom) ;
  90. }
  91. rectClient.left += StatusLeftMargin () ;
  92. if (PaintOptions & PaintText)
  93. {
  94. rectClient.left += 1 ;
  95. rectClient.top += 1 ;
  96. rectClient.right -= 1 ;
  97. rectClient.bottom -= 1 ;
  98. ExtTextOut (hDC, rectClient.left, rectClient.top, ETO_CLIPPED | ETO_OPAQUE,
  99. &rectClient, szStatusLine, szStatusLineLen, NULL) ;
  100. }
  101. } // PaintStatusBar
  102. LRESULT APIENTRY StatusWndProc (HWND hWnd,
  103. WORD wMsg,
  104. WPARAM wParam,
  105. LPARAM lParam)
  106. { // StatusWndProc
  107. BOOL bCallDefProc ;
  108. LRESULT lReturnValue ;
  109. HDC hDC ;
  110. PAINTSTRUCT ps ;
  111. bCallDefProc = FALSE ;
  112. lReturnValue = 0L ;
  113. switch (wMsg)
  114. { // 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 = (WNDPROC) 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. {
  181. return (TRUE) ;
  182. }
  183. strclr (szStatusLine) ;
  184. if (LoadString (hInstance, wStringID, szFormat, MessageLen))
  185. {
  186. va_start (vaList, wStringID) ;
  187. wvsprintf (szStatusLine, szFormat, vaList) ;
  188. va_end (vaList) ;
  189. dwCurrentMenuID = MenuIDToHelpID (wStringID) ;
  190. szStatusLineLen = lstrlen (szStatusLine) ;
  191. }
  192. else
  193. {
  194. dwCurrentMenuID = 0 ;
  195. szStatusLineLen = 0 ;
  196. }
  197. PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ;
  198. return (TRUE) ;
  199. } // StatusLine
  200. void StatusLineReady (HWND hWnd)
  201. {
  202. LPTSTR pFileName = NULL ;
  203. pFileName = pChartFileName ;
  204. if (pFileName)
  205. {
  206. TSPRINTF (szStatusLine, szStatusFormat2, pFileName) ;
  207. }
  208. else
  209. {
  210. szStatusLine[0] = TEXT('\0') ;
  211. }
  212. szStatusLineLen = lstrlen (szStatusLine) ;
  213. PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ;
  214. }
  215. void StatusUpdateIcons (HWND hWndStatus)
  216. {
  217. PaintStatusBar (hWndStatus, hStatusDC, PaintIcons) ;
  218. }