|
|
1.1 ! root 1: #include "perfmon.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: ! 6: #include "log.h" // for LogCollecting ! 7: #include "perfmops.h" // for SmallFileSizeString ! 8: #include "playback.h" // for PlayingBackLog ! 9: #include "utils.h" ! 10: ! 11: //================================// ! 12: // Options for PaintStatusBar // ! 13: //================================// ! 14: #define PaintText 1 ! 15: #define PaintIcons 2 ! 16: #define PaintBoundary 4 ! 17: #define PaintAll (PaintText + PaintIcons + PaintBoundary) ! 18: ! 19: //==========================================================================// ! 20: // Constants // ! 21: //==========================================================================// ! 22: ! 23: #define szStatusClass TEXT("PerfmonStatusClass") ! 24: #define dwStatusClassStyle (CS_HREDRAW | CS_VREDRAW | CS_OWNDC) ! 25: #define iStatusClassExtra (0) ! 26: #define iStatusWindowExtra (0) ! 27: #define dwStatusWindowStyle (WS_CHILD | WS_VISIBLE) ! 28: ! 29: ! 30: #define szAlertMax TEXT(" 99 ") ! 31: #define szAlertFormat TEXT(" %2d ") ! 32: #define szAlertOverflow TEXT(" ++") ! 33: ! 34: #define szLogMax TEXT(" 9,999.9M ") ! 35: ! 36: //==========================================================================// ! 37: // Local Data // ! 38: //==========================================================================// ! 39: ! 40: ! 41: HDC hStatusDC ; // for OWN_DC ! 42: ! 43: HDC hLogBitmapDC ; ! 44: int xLogBitmapWidth ; ! 45: int yLogBitmapHeight ; ! 46: ! 47: HDC hAlertBitmapDC ; ! 48: int xAlertBitmapWidth ; ! 49: int yAlertBitmapHeight ; ! 50: ! 51: int yStatusHeight ; ! 52: int xStatusAlertWidth ; // of alert bm and num alerts ! 53: int xStatusLogWidth ; // of log bitmap and file size ! 54: ! 55: int szStatusLineLen ; // no. of char. in szStatusLine ! 56: TCHAR szStatusLine [MessageLen+ResourceStringLen] ; ! 57: TCHAR szCurrentActivity [ResourceStringLen] ; ! 58: TCHAR szStatusFormat [ResourceStringLen] ; ! 59: TCHAR szStatusFormat2 [ResourceStringLen] ; ! 60: ! 61: HBITMAP hBitmapAlertStatus ; ! 62: HBITMAP hBitmapLogStatus ; ! 63: ! 64: ! 65: ! 66: //==========================================================================// ! 67: // Macros // ! 68: //==========================================================================// ! 69: ! 70: ! 71: #define StatusTopMargin() (2) ! 72: #define StatusLeftMargin() (2) ! 73: ! 74: ! 75: //==========================================================================// ! 76: // Local Functions // ! 77: //==========================================================================// ! 78: ! 79: ! 80: void DrawAlerts (HDC hDC, ! 81: LPRECT lpRect) ! 82: { ! 83: TCHAR szText [10] ; ! 84: RECT rectText ; ! 85: int yBitmapTop ; ! 86: ! 87: if (!iUnviewedAlerts) ! 88: return ; ! 89: ! 90: yBitmapTop = lpRect->top + ! 91: (lpRect->bottom - ! 92: lpRect->top - ! 93: yAlertBitmapHeight) / 2 ; ! 94: ! 95: SetTextColor (hDC, crLastUnviewedAlert) ; ! 96: ! 97: BitBlt (hDC, // DC for Destination surface ! 98: lpRect->right - xStatusAlertWidth, // x pos for Destination surface ! 99: yBitmapTop, // y for Destination surface ! 100: xAlertBitmapWidth, // width of bitmap ! 101: yAlertBitmapHeight, // height of bitmap ! 102: hAlertBitmapDC, // DC for source surface ! 103: 0, 0, // location in source surface ! 104: SRCCOPY) ; // ROP code ! 105: ! 106: SetTextColor (hDC, crBlack) ; ! 107: ! 108: if (iUnviewedAlerts > 99) ! 109: lstrcpy (szText, szAlertOverflow) ; ! 110: else ! 111: TSPRINTF (szText, szAlertFormat, iUnviewedAlerts) ; ! 112: ! 113: rectText.left = lpRect->right - xStatusAlertWidth + xAlertBitmapWidth ; ! 114: rectText.top = lpRect->top + 1 ; ! 115: rectText.right = lpRect->right - 1 ; ! 116: rectText.bottom = lpRect->bottom - 1 ; ! 117: ! 118: ExtTextOut (hDC, rectText.left, rectText.top, ETO_CLIPPED | ETO_OPAQUE, ! 119: &rectText, szText, lstrlen (szText), NULL) ; ! 120: ! 121: lpRect->right -= (xStatusAlertWidth + (xAlertBitmapWidth >> 2)) ; ! 122: } // DrawAlerts ! 123: ! 124: ! 125: void DrawLog (HDC hDC, ! 126: LPRECT lpRect) ! 127: { ! 128: TCHAR szText [10] ; ! 129: RECT rectText ; ! 130: int yBitmapTop ; ! 131: ! 132: if (!LogCollecting (hWndLog)) ! 133: return ; ! 134: ! 135: yBitmapTop = lpRect->top + ! 136: (lpRect->bottom - ! 137: lpRect->top - ! 138: yLogBitmapHeight) / 2 ; ! 139: BitBlt (hDC, // DC for Destination surface ! 140: lpRect->right - xStatusLogWidth, // x pos for Destination surface ! 141: yBitmapTop, // y for Destination surface ! 142: xLogBitmapWidth, // width of bitmap ! 143: yLogBitmapHeight, // height of bitmap ! 144: hLogBitmapDC, // DC for source surface ! 145: 0, 0, // location in source surface ! 146: SRCCOPY) ; // ROP code ! 147: ! 148: ! 149: SmallFileSizeString (LogFileSize (hWndLog), szText) ; ! 150: ! 151: rectText.left = lpRect->right - xStatusLogWidth + ! 152: xLogBitmapWidth + 1 ; ! 153: rectText.top = lpRect->top + 1 ; ! 154: rectText.right = lpRect->right - 1 ; ! 155: rectText.bottom = lpRect->bottom - 1 ; ! 156: ! 157: ExtTextOut (hDC, rectText.left, rectText.top, ETO_CLIPPED | ETO_OPAQUE, ! 158: &rectText, szText, lstrlen (szText), NULL) ; ! 159: ! 160: lpRect->right -= xStatusLogWidth ; ! 161: } // DrawLog ! 162: ! 163: ! 164: //==========================================================================// ! 165: // Message Handlers // ! 166: //==========================================================================// ! 167: ! 168: ! 169: void static OnCreate (HWND hWnd) ! 170: /* ! 171: Effect: Perform any actions needed when a status window is created. ! 172: In particular, set the instance data to initial values, ! 173: determine the size and placement of the various elements ! 174: of the status display. ! 175: ! 176: Called By: StatusWndProc only, in response to a WM_CREATE message. ! 177: */ ! 178: { // OnCreate ! 179: HDC hDC ; ! 180: ! 181: ! 182: hBitmapAlertStatus = LoadBitmap (hInstance, idBitmapAlertStatus) ; ! 183: hBitmapLogStatus = LoadBitmap (hInstance, idBitmapLogStatus) ; ! 184: ! 185: hDC = hStatusDC = GetDC (hWnd) ; ! 186: SelectFont (hDC, hFontScales) ; ! 187: SetBkColor (hDC, ColorBtnFace) ; ! 188: SetTextAlign (hDC, TA_LEFT) ; ! 189: SetBkMode (hDC, OPAQUE) ; ! 190: ! 191: yStatusHeight = 2 * StatusTopMargin () + ! 192: FontHeight (hDC, TRUE) + ! 193: 2 * ThreeDPad ; ! 194: ! 195: // pre-load the log and alert bitmaps for perfmormance ! 196: xLogBitmapWidth = BitmapWidth (hBitmapLogStatus) ; ! 197: yLogBitmapHeight = BitmapHeight (hBitmapLogStatus) ; ! 198: xAlertBitmapWidth = BitmapWidth (hBitmapAlertStatus) ; ! 199: yAlertBitmapHeight = BitmapHeight (hBitmapAlertStatus) ; ! 200: ! 201: hLogBitmapDC = CreateCompatibleDC (hDC) ; ! 202: SelectObject (hLogBitmapDC, hBitmapLogStatus) ; ! 203: ! 204: hAlertBitmapDC = CreateCompatibleDC (hDC) ; ! 205: SelectObject (hAlertBitmapDC, hBitmapAlertStatus) ; ! 206: ! 207: ! 208: xStatusAlertWidth = xAlertBitmapWidth + 1 + ! 209: TextWidth (hDC, szAlertMax) ; ! 210: xStatusLogWidth = xLogBitmapWidth + ! 211: TextWidth (hDC, szLogMax) ; ! 212: ! 213: ! 214: StringLoad (IDS_CURRENTACTIVITY, szCurrentActivity) ; ! 215: StringLoad (IDS_STATUSFORMAT, szStatusFormat) ; ! 216: StringLoad (IDS_STATUSFORMAT2, szStatusFormat2) ; ! 217: ! 218: StatusLineReady (hWnd) ; ! 219: } // OnCreate ! 220: ! 221: void static OnDestroy (HWND hWnd) ! 222: { ! 223: if (hBitmapAlertStatus) ! 224: { ! 225: DeleteObject (hBitmapAlertStatus) ; ! 226: hBitmapAlertStatus = 0 ; ! 227: } ! 228: ! 229: if (hBitmapLogStatus) ! 230: { ! 231: DeleteObject (hBitmapLogStatus) ; ! 232: hBitmapLogStatus = 0 ; ! 233: } ! 234: ReleaseDC (hWnd, hStatusDC) ; ! 235: ! 236: } // OnDestroy ! 237: ! 238: void static PaintStatusBar (HWND hWnd, HDC hDC, int PaintOptions) ! 239: /* ! 240: Effect: Paint the invalid surface of hWnd. Draw each label, each ! 241: recessed value box, and each value. ! 242: ! 243: Called By: StatusWndProc only, in response to a WM_PAINT message. ! 244: */ ! 245: { ! 246: RECT rectClient ; ! 247: ! 248: if (bPerfmonIconic) ! 249: { ! 250: // no need to draw anything if iconic ! 251: return ; ! 252: } ! 253: ! 254: GetClientRect (hWnd, &rectClient) ; ! 255: ! 256: RectContract (&rectClient, StatusTopMargin (), StatusLeftMargin ()) ; ! 257: ! 258: if (PaintOptions == PaintAll) ! 259: { ! 260: ThreeDConcave1 (hDC, ! 261: rectClient.left, rectClient.top, ! 262: rectClient.right, rectClient.bottom) ; ! 263: } ! 264: ! 265: rectClient.left += StatusLeftMargin () ; ! 266: ! 267: // Always draw the icons and need to draw log before Alerts! ! 268: DrawLog (hDC, &rectClient) ; ! 269: DrawAlerts (hDC, &rectClient) ; ! 270: ! 271: if (PaintOptions & PaintText) ! 272: { ! 273: rectClient.left += 1 ; ! 274: rectClient.top += 1 ; ! 275: rectClient.right -= 1 ; ! 276: rectClient.bottom -= 1 ; ! 277: ExtTextOut (hDC, rectClient.left, rectClient.top, ETO_CLIPPED | ETO_OPAQUE, ! 278: &rectClient, szStatusLine, szStatusLineLen, NULL) ; ! 279: } ! 280: ! 281: } // PaintStatusBar ! 282: ! 283: ! 284: ! 285: ! 286: LRESULT APIENTRY StatusWndProc (HWND hWnd, ! 287: WORD wMsg, ! 288: WPARAM wParam, ! 289: LPARAM lParam) ! 290: { // StatusWndProc ! 291: BOOL bCallDefProc ; ! 292: LRESULT lReturnValue ; ! 293: HDC hDC ; ! 294: PAINTSTRUCT ps ; ! 295: ! 296: ! 297: bCallDefProc = FALSE ; ! 298: lReturnValue = 0L ; ! 299: ! 300: switch (wMsg) ! 301: { // switch ! 302: case WM_PAINT: ! 303: hDC = BeginPaint (hWnd, &ps) ; ! 304: PaintStatusBar (hWnd, hDC, PaintAll) ; ! 305: EndPaint (hWnd, &ps) ; ! 306: break ; ! 307: ! 308: case WM_CREATE: ! 309: OnCreate (hWnd) ; ! 310: break ; ! 311: ! 312: case WM_DESTROY: ! 313: OnDestroy (hWnd) ; ! 314: break ; ! 315: ! 316: default: ! 317: bCallDefProc = TRUE ; ! 318: } // switch ! 319: ! 320: ! 321: if (bCallDefProc) ! 322: lReturnValue = DefWindowProc (hWnd, wMsg, wParam, lParam) ; ! 323: ! 324: return (lReturnValue); ! 325: } // StatusWndProc ! 326: ! 327: ! 328: int StatusHeight (HWND hWnd) ! 329: /* ! 330: Effect: A status window has a preferred height, based on the font ! 331: used in its display. Return the preferred height, determined ! 332: when the window was created. ! 333: ! 334: Assert: OnCreate has already been called, and it set ! 335: StatusData.yHeight. ! 336: */ ! 337: { ! 338: return (yStatusHeight) ; ! 339: } ! 340: ! 341: ! 342: ! 343: ! 344: HWND CreatePMStatusWindow (HWND hWnd) ! 345: { ! 346: return (CreateWindow (szStatusClass, // class ! 347: NULL, // caption ! 348: dwStatusWindowStyle, // window style ! 349: 0, 0, // position ! 350: 0, 0, // size ! 351: hWnd, // parent window ! 352: NULL, // menu ! 353: hInstance, // program instance ! 354: NULL)) ; // user-supplied data ! 355: } // CreateStatusWindow ! 356: ! 357: ! 358: ! 359: ! 360: BOOL StatusInitializeApplication (void) ! 361: /* ! 362: Called By: InitializeApplication only ! 363: */ ! 364: { ! 365: WNDCLASS wc ; ! 366: ! 367: wc.style = dwStatusClassStyle ; ! 368: wc.lpfnWndProc = (WNDPROC) StatusWndProc ; ! 369: wc.hInstance = hInstance ; ! 370: wc.cbClsExtra = iStatusClassExtra ; ! 371: wc.cbWndExtra = iStatusWindowExtra ; ! 372: wc.hIcon = NULL ; ! 373: wc.hCursor = LoadCursor (NULL, IDC_ARROW) ; ! 374: wc.hbrBackground = hbLightGray ; ! 375: wc.lpszMenuName = NULL ; ! 376: wc.lpszClassName = szStatusClass ; ! 377: ! 378: return (RegisterClass (&wc)) ; ! 379: } ! 380: ! 381: BOOL _cdecl StatusLine (HWND hWnd, ! 382: WORD wStringID, ...) ! 383: { ! 384: TCHAR szFormat [MessageLen] ; ! 385: va_list vaList ; ! 386: ! 387: if (wStringID == 0) ! 388: { ! 389: return (TRUE) ; ! 390: } ! 391: ! 392: strclr (szStatusLine) ; ! 393: ! 394: if (LoadString (hInstance, wStringID, szFormat, MessageLen)) ! 395: { ! 396: va_start (vaList, wStringID) ; ! 397: wvsprintf (szStatusLine, szFormat, vaList) ; ! 398: va_end (vaList) ; ! 399: dwCurrentMenuID = MenuIDToHelpID (wStringID) ; ! 400: szStatusLineLen = lstrlen (szStatusLine) ; ! 401: } ! 402: else ! 403: { ! 404: dwCurrentMenuID = 0 ; ! 405: szStatusLineLen = 0 ; ! 406: } ! 407: PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ; ! 408: ! 409: return (TRUE) ; ! 410: } // StatusLine ! 411: ! 412: ! 413: ! 414: void StatusLineReady (HWND hWnd) ! 415: { ! 416: int stringLen ; ! 417: LPTSTR pFileName = NULL ; ! 418: ! 419: TSPRINTF (szStatusLine, szStatusFormat, ! 420: PlayingBackLog () ? ! 421: PlaybackLog.szFileTitle : szCurrentActivity) ; ! 422: ! 423: switch (iPerfmonView) ! 424: { ! 425: case IDM_VIEWCHART: ! 426: pFileName = pChartFileName ; ! 427: break ; ! 428: ! 429: case IDM_VIEWALERT: ! 430: pFileName = pAlertFileName ; ! 431: break ; ! 432: ! 433: case IDM_VIEWLOG: ! 434: pFileName = pLogFileName ; ! 435: break ; ! 436: ! 437: case IDM_VIEWREPORT: ! 438: pFileName = pReportFileName ; ! 439: break ; ! 440: } ! 441: ! 442: if (pFileName) ! 443: { ! 444: stringLen = lstrlen (szStatusLine) ; ! 445: TSPRINTF (&szStatusLine[stringLen], szStatusFormat2, pFileName) ; ! 446: } ! 447: ! 448: szStatusLineLen = lstrlen (szStatusLine) ; ! 449: ! 450: PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ; ! 451: } ! 452: ! 453: ! 454: void StatusUpdateIcons (HWND hWndStatus) ! 455: { ! 456: PaintStatusBar (hWndStatus, hStatusDC, PaintIcons) ; ! 457: } ! 458:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.