|
|
1.1 ! root 1: /***************************************************************************** ! 2: * ! 3: * Graph.c - This module handles the graphing window. ! 4: * ! 5: * Microsoft Confidential ! 6: * Copyright (c) 1992-1993 Microsoft Corporation ! 7: * ! 8: * ! 9: ****************************************************************************/ ! 10: ! 11: /* ! 12: File Contents: ! 13: ! 14: This file contains the code for creating and manipulating the graph ! 15: window. This window is a child of hWndMain and represents one of the ! 16: three "views" of the program. The other views are log and alert. ! 17: ! 18: The graph window is actually just a container window, whose surface ! 19: is completely filled by its children: hWndGraphDisplay, , ! 20: hWndGraphLegend, and hWndGraphStatus. Therefore much of this file is ! 21: merely calls to the appropriate functions for these children. ! 22: ! 23: The graph window is responsible for the graph structure itself, ! 24: however. Conceptually this should be instance data for the graph ! 25: window. Right now, however, there is only one window and only one ! 26: graph structure. Nevertheless, we go through the GraphData(hWnd) ! 27: function to get a pointer to the graph structure for the graph window. ! 28: ! 29: */ ! 30: ! 31: ! 32: //==========================================================================// ! 33: // Includes // ! 34: //==========================================================================// ! 35: ! 36: ! 37: #include "perfmon.h" ! 38: #include "graph.h" ! 39: #include "grafdisp.h" ! 40: #include "legend.h" ! 41: #include "valuebar.h" ! 42: #include "utils.h" // for WindowShow ! 43: ! 44: ! 45: //==========================================================================// ! 46: // Constants // ! 47: //==========================================================================// ! 48: ! 49: ! 50: //=============================// ! 51: // Graph Class // ! 52: //=============================// ! 53: ! 54: ! 55: TCHAR szGraphWindowClass[] = TEXT("PerfmonGraphClass") ; ! 56: #define dwGraphClassStyle (CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS) ! 57: #define iGraphClassExtra (0) ! 58: #define iGraphWindowExtra (0) ! 59: #define dwGraphWindowStyle (WS_CHILD) ! 60: ! 61: ! 62: ! 63: //==========================================================================// ! 64: // Local Functions // ! 65: //==========================================================================// ! 66: ! 67: ! 68: void static OnCreate (HWND hWnd) ! 69: { // OnCreate ! 70: hWndGraphDisplay = CreateGraphDisplayWindow (hWnd) ; ! 71: hWndGraphLegend = CreateGraphLegendWindow (hWnd) ; ! 72: hWndGraphStatus = CreateGraphStatusWindow (hWnd) ; ! 73: } // OnCreate ! 74: ! 75: ! 76: void static OnPaint (HWND hWnd) ! 77: { ! 78: HDC hDC ; ! 79: PAINTSTRUCT ps ; ! 80: ! 81: hDC = BeginPaint (hWnd, &ps) ; ! 82: EndPaint (hWnd, &ps) ; ! 83: } ! 84: ! 85: ! 86: void static OnSize (HWND hWnd, int xWidth, int yHeight) ! 87: { // OnSize ! 88: SizeGraphComponents (hWnd) ; ! 89: } // OnSize ! 90: ! 91: ! 92: //==========================================================================// ! 93: // Message Handlers // ! 94: //==========================================================================// ! 95: ! 96: ! 97: ! 98: LRESULT APIENTRY GraphWndProc (HWND hWnd, ! 99: WORD wMsg, ! 100: DWORD wParam, ! 101: LONG lParam) ! 102: { // GraphWndProc ! 103: BOOL bCallDefProc ; ! 104: LRESULT lReturnValue ; ! 105: ! 106: ! 107: bCallDefProc = FALSE ; ! 108: lReturnValue = 0L ; ! 109: ! 110: switch (wMsg) ! 111: { // switch ! 112: case WM_CREATE: ! 113: OnCreate (hWnd) ; ! 114: break ; ! 115: ! 116: case WM_LBUTTONDBLCLK: ! 117: SendMessage (hWndMain, WM_LBUTTONDBLCLK, wParam, lParam) ; ! 118: break ; ! 119: ! 120: case WM_PAINT: ! 121: OnPaint (hWnd) ; ! 122: break ; ! 123: ! 124: case WM_SIZE: ! 125: OnSize (hWnd, LOWORD (lParam), HIWORD (lParam)) ; ! 126: break ; ! 127: ! 128: default: ! 129: bCallDefProc = TRUE ; ! 130: } // switch ! 131: ! 132: ! 133: if (bCallDefProc) ! 134: lReturnValue = DefWindowProc (hWnd, wMsg, wParam, lParam) ; ! 135: ! 136: return (lReturnValue); ! 137: } // GraphWndProc ! 138: ! 139: ! 140: ! 141: BOOL GraphInitializeApplication (void) ! 142: /* ! 143: Note: There is no background brush set for the MainWindow ! 144: class so that the main window is never erased. The ! 145: client area of MainWindow is always covered by one ! 146: of the view windows. If we erase it, it would just ! 147: flicker needlessly. ! 148: */ ! 149: { // GraphInitializeApplication ! 150: BOOL bSuccess ; ! 151: WNDCLASS wc ; ! 152: ! 153: //=============================// ! 154: // Register GraphWindow class // ! 155: //=============================// ! 156: ! 157: ! 158: wc.style = dwGraphClassStyle ; ! 159: wc.lpfnWndProc = (WNDPROC) GraphWndProc ; ! 160: wc.hInstance = hInstance ; ! 161: wc.cbClsExtra = iGraphWindowExtra ; ! 162: wc.cbWndExtra = iGraphClassExtra ; ! 163: wc.hIcon = NULL ; ! 164: wc.hCursor = LoadCursor(NULL, IDC_ARROW) ; ! 165: wc.hbrBackground = NULL ; // see note above ! 166: wc.lpszMenuName = NULL ; ! 167: wc.lpszClassName = szGraphWindowClass ; ! 168: ! 169: bSuccess = RegisterClass (&wc) ; ! 170: ! 171: ! 172: //=============================// ! 173: // Register Child classes // ! 174: //=============================// ! 175: ! 176: if (bSuccess) ! 177: bSuccess = GraphDisplayInitializeApplication () ; ! 178: ! 179: if (bSuccess) ! 180: bSuccess = GraphLegendInitializeApplication () ; ! 181: ! 182: if (bSuccess) ! 183: bSuccess = GraphStatusInitializeApplication () ; ! 184: ! 185: return (bSuccess) ; ! 186: } // GraphInitializeApplication ! 187: ! 188: ! 189: HWND CreateGraphWindow (HWND hWndParent) ! 190: /* ! 191: Effect: Create the graph window. This window is a child of ! 192: hWndMain and is a container for the graph data, ! 193: graph label, graph legend, and graph status windows. ! 194: ! 195: Note: We dont worry about the size here, as this window ! 196: will be resized whenever the main window is resized. ! 197: ! 198: */ ! 199: { ! 200: return (CreateWindow (szGraphWindowClass, // window class ! 201: NULL, // caption ! 202: dwGraphWindowStyle, // style for window ! 203: 0, 0, // initial position ! 204: 0, 0, // initial size ! 205: hWndParent, // parent ! 206: NULL, // menu ! 207: hInstance, // program instance ! 208: NULL)) ; // user-supplied data ! 209: } ! 210: ! 211: ! 212: void SizeGraphComponents (HWND hWnd) ! 213: /* ! 214: Effect: Move and show the various components of the graph to ! 215: fill the size (xWidth x yHeight). Take into account ! 216: whether the user wants to show the legend or status ! 217: bars. Also take into account if we have room for these ! 218: items. ! 219: ! 220: Internals: If the user doesn't want the status or legend windows, ! 221: they aren't shown. Also, if the user wanted the status ! 222: window but not the legend window, the status window is ! 223: not shown. ! 224: ! 225: We may disregard the user's desire for the legend or ! 226: status bar if there is not room. In particular, a legend ! 227: window has a minimum width (LegendMinWidth ()) and a ! 228: minimum height (LegendMinHeight ()). These values are ! 229: fixed for a given session of perfmon. It also has a ! 230: preferred height, which takes into consideration the ! 231: size of the graph window and the number of items in ! 232: the legend. This value is returned by LegendHeight(). ! 233: ! 234: We don't show the legend if its minimum height would ! 235: take up more than half the graph height. ! 236: ! 237: If we feel we don't have room for the legend, we don't ! 238: show the status window either. ! 239: ! 240: See Also: LegendMinWidth, LegendMinHeight, LegendHeight, ! 241: ValuebarHeight. ! 242: ! 243: Called By: OnSize, any other function that may remove or add one ! 244: of the graph components. ! 245: */ ! 246: { // SizeGraphComponents ! 247: RECT rectClient ; ! 248: BOOL bShowLegend ; ! 249: BOOL bShowStatus ; ! 250: int yStatusHeight ; ! 251: int yLegendHeight ; ! 252: int xWidth ; ! 253: int yHeight ; ! 254: ! 255: GetClientRect (hWnd, &rectClient) ; ! 256: xWidth = rectClient.right - rectClient.left ; ! 257: yHeight = rectClient.bottom - rectClient.top ; ! 258: ! 259: // if the graph window has no size, neither will its children. ! 260: if (!xWidth || !yHeight) ! 261: return ; ! 262: ! 263: //=============================// ! 264: // Show the Legend Window? // ! 265: //=============================// ! 266: ! 267: if (!pGraphs->gOptions.bLegendChecked) ! 268: bShowLegend = FALSE ; ! 269: else if (xWidth < LegendMinWidth (hWndGraphLegend)) ! 270: bShowLegend = FALSE ; ! 271: else if (yHeight < 5 * LegendMinHeight (hWndGraphLegend)) ! 272: bShowLegend = FALSE ; ! 273: else ! 274: bShowLegend = TRUE ; ! 275: ! 276: //=============================// ! 277: // Show the Status Window? // ! 278: //=============================// ! 279: ! 280: if (!pGraphs->gOptions.bStatusBarChecked) ! 281: bShowStatus = FALSE ; ! 282: else if (!bShowLegend) ! 283: bShowStatus = FALSE ; ! 284: else ! 285: bShowStatus = TRUE ; ! 286: ! 287: ! 288: yStatusHeight = bShowStatus ? ! 289: ValuebarHeight (hWndGraphStatus) : 0 ; ! 290: yLegendHeight = bShowLegend ? ! 291: LegendHeight (hWndGraphLegend, yHeight) : 0 ; ! 292: ! 293: ! 294: //=============================// ! 295: // Update the status window // ! 296: //=============================// ! 297: ! 298: if (bShowStatus) ! 299: MoveWindow (hWndGraphStatus, ! 300: 0, yHeight - yStatusHeight - yLegendHeight, ! 301: xWidth, yStatusHeight, ! 302: TRUE) ; ! 303: WindowShow (hWndGraphStatus, bShowStatus) ; ! 304: ! 305: ! 306: //=============================// ! 307: // Update the legend window // ! 308: //=============================// ! 309: ! 310: if (bShowLegend) ! 311: MoveWindow (hWndGraphLegend, ! 312: 0, yHeight - yLegendHeight, ! 313: xWidth, yLegendHeight, ! 314: TRUE) ; ! 315: WindowShow (hWndGraphLegend, bShowLegend) ; ! 316: ! 317: ! 318: //=============================// ! 319: // Update the display window // ! 320: //=============================// ! 321: ! 322: MoveWindow (hWndGraphDisplay, ! 323: 0, 0, ! 324: xWidth, yHeight - yStatusHeight - yLegendHeight, ! 325: TRUE) ; ! 326: SizeGraphDisplayComponents (hWndGraphDisplay) ; ! 327: WindowInvalidate (hWndGraphDisplay) ; ! 328: WindowShow (hWndGraphDisplay, TRUE) ; ! 329: } // SizeGraphComponents ! 330: ! 331:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.