📄 vcmon.c
字号:
if( mygraph->numplots == 1) {
SetTextColor( hdcMem, MYBLUE );
sprintf( tmp, "%g/%g", mygraph->yval[0][ mygraph->xval ], mygraph->highpty[0] );
TextOut( hdcMem, 0, 0, tmp, strlen( tmp ) );
} else {
SetTextColor( hdcMem, MYBLUE );
sprintf( tmp, mygraph->titles[0] );
TextOut( hdcMem, 0, 0, tmp, strlen( tmp ) );
sprintf( tmp, "%g/%g", mygraph->yval[0][mygraph->xval], mygraph->highpty[0] );
TextOut( hdcMem, mygraph->graphbmp.bmWidth/2, 0,
tmp, strlen( tmp ));
}
if( hOldFont ) SelectObject( hdcMem, hOldFont);
mygraph->haxisbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
// update lower graph legend (if there is one)
if( mygraph->numplots == 2 ) {
hdcMem = CreateCompatibleDC (hDC) ;
DeleteObject( mygraph->hlegendbmp );
mygraph->hlegendbmp = CreateCompatibleBitmap( hDC,
mygraph->graphwidth,
FontTM.tmHeight );
GetObject( mygraph->hlegendbmp, sizeof (BITMAP),
(LPSTR) &mygraph->legendbmp);
oldbitmap = SelectObject( hdcMem, mygraph->hlegendbmp );
// fill bitmap with grey background and draw seperator
rc.top = 0;
rc.left = 0;
rc.bottom = mygraph->legendbmp.bmHeight;
rc.right = mygraph->legendbmp.bmWidth;
FillStock( hdcMem, &rc, LTGRAY_BRUSH );
DrawSeperator( hdcMem, 0, mygraph->legendbmp.bmWidth );
// divide things up into different colors
SetBkColor( hdcMem, GetSysColor(COLOR_BTNFACE));
if (hFont) hOldFont = SelectObject( hdcMem, hFont);
SetTextColor( hdcMem, MYRED );
sprintf( tmp, mygraph->titles[1] );
TextOut( hdcMem, 0, 3, tmp, strlen( tmp ) );
sprintf( tmp, "%g/%g", mygraph->yval[1][mygraph->xval], mygraph->highpty[1] );
TextOut( hdcMem, mygraph->graphbmp.bmWidth/2, 3,
tmp, strlen( tmp ));
if( hOldFont ) SelectObject( hdcMem, hOldFont);
mygraph->hlegendbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
}
// release the DC
ReleaseDC( mygraph->graphwnd, hDC );
}
//----------------------------------------------------------------------
//
// RescaleGraph
//
// Takes a graph, new axis information and rescales it.
//
//----------------------------------------------------------------------
void RescaleGraph( graphdata *mygraph, long prevx, double newxaxis1, double newxaxis2 )
{
HDC hdcMem, hDC;
HBRUSH hbrBkGnd;
HBITMAP oldbitmap;
HFONT hOldFont = NULL;
RECT rc;
BOOL noprev;
int i;
long grheight, firstheight;
// update axis
if( newxaxis1 )
mygraph->xaxis[0] = newxaxis1;
if( newxaxis2 )
mygraph->xaxis[1] = newxaxis2;
// prepare for drawing on bitmap
hDC = GetDC( mygraph->graphwnd );
hdcMem = CreateCompatibleDC( hDC ) ;
oldbitmap = SelectObject( hdcMem, mygraph->hgraphbmp );
// fill with black
rc.left = 0;
rc.top = 0;
rc.bottom = mygraph->graphbmp.bmHeight;
rc.right = mygraph->graphbmp.bmWidth;
hbrBkGnd = GRAPHBKGRND;
FillRect(hdcMem, &rc, hbrBkGnd);
DeleteObject(hbrBkGnd);
// now, time to redraw and update all the y-values for the first plot
SelectObject( hdcMem, BluePen );
grheight = mygraph->halfheight[0];
noprev = TRUE;
mygraph->yprev[0] = -1;
for( i = 0; i < mygraph->graphwidth ; i++ ) {
if( noprev && mygraph->yval[0][i] != -1.0 ) {
noprev = FALSE;
MoveToEx( hdcMem, i, (long) (grheight - mygraph->yval[0][i] * grheight/mygraph->xaxis[0]),
NULL );
} else if( mygraph->yval[0][i] == -1.0 )
noprev = TRUE;
if( mygraph->yval[0][i] != -1.0) {
LineTo( hdcMem, i, (long) (grheight - (mygraph->yval[0][i] * grheight)/
mygraph->xaxis[0] ));
if( i == prevx )
mygraph->yprev[0] = (long) (grheight - (mygraph->yval[0][i] *
grheight)/mygraph->xaxis[0] );
}
}
// do the second plot (if any)
if( mygraph->numplots == 2 ) {
SelectObject( hdcMem, RedPen );
grheight = mygraph->halfheight[1];
noprev = TRUE;
mygraph->yprev[1] = -1;
firstheight = mygraph->halfheight[0] + 3;
for( i = 0; i < mygraph->graphwidth ; i++ ) {
if( noprev && mygraph->yval[1][i] != -1.0 ) {
noprev = FALSE;
MoveToEx( hdcMem, i, (long) (grheight - mygraph->yval[1][i] *
grheight/mygraph->xaxis[1] + firstheight ), NULL );
} else if( mygraph->yval[1][i] == -1.0 )
noprev = TRUE;
if( mygraph->yval[1][i] != -1.0 ) {
LineTo ( hdcMem, i, (long) (grheight - (mygraph->yval[1][i] * grheight)/
mygraph->xaxis[1] + firstheight ));
if( i == prevx )
mygraph->yprev[1] = (long) (grheight - (mygraph->yval[1][i] * grheight)/
mygraph->xaxis[1] );
}
}
// draw the graph seperator
DrawSeperator( hdcMem, firstheight - 2, rc.right - rc.left );
}
// release the bitmap
mygraph->hgraphbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
ReleaseDC( mygraph->graphwnd, hDC );
}
//----------------------------------------------------------------------
//
// ScanGraph
//
// Looks through a graph and extracts the highest point, remembering its
// position and returning its value.
//
//----------------------------------------------------------------------
double ScanGraph( graphdata *mygraph, int graphnum)
{
int i;
mygraph->highpty[ graphnum ] = 0.0;
mygraph->highptx[ graphnum ] = 0;
for( i = 0; i< mygraph->graphwidth; i++) {
if( mygraph->yval[ graphnum ][ i ] > mygraph->highpty[ graphnum ] ) {
mygraph->highpty[ graphnum ] = mygraph->yval[ graphnum][ i ];
mygraph->highptx[ graphnum ] = i;
}
}
return mygraph->highpty[ graphnum ];
}
//----------------------------------------------------------------------
//
// PlotPoints
//
// Draw the indicated point(s) on the graph of the indicated graph
// bitmap and tells the graph it needs to update
//
//----------------------------------------------------------------------
void PlotPoints( graphdata *mygraph, double newy1, double newy2 )
{
HDC hdcMem, hDC;
RECT rc;
HBITMAP oldbitmap;
HBRUSH hbrBkGnd;
long prevx, yval1, yval2;
BOOL rescale = FALSE;
int i, j, numclear;
double oldhigh, scale1 = 0, scale2 = 0;
// do each point twice for better look
for(j=0;j<2;j++ ) {
// first, calculate what coordinate the new points represent
yval1 = (long) (mygraph->halfheight[0] - (newy1 * mygraph->halfheight[0])/mygraph->xaxis[0]);
yval2 = (long) (mygraph->halfheight[1] - (newy2 * mygraph->halfheight[1])/mygraph->xaxis[1]);
// see if we've wrapped
prevx = mygraph->xval;
if( mygraph->xval == mygraph->graphwidth ) {
mygraph->xval = 0;
mygraph->yprev[0] = yval1;
mygraph->yprev[1] = yval2;
} else if( !mygraph->xval ) {
mygraph->yprev[0] = yval1;
mygraph->yprev[1] = yval2;
mygraph->xval++;
} else {
mygraph->xval++;
}
// see if we need to rescale because of running off the top
if( newy1 >= mygraph->xaxis[0] ) {
rescale = TRUE;
scale1 = newy1 * 3.0/2.0;
}
if( newy2 >= mygraph->xaxis[1] ) {
rescale = TRUE;
scale2 = newy2 * 3.0/2.0;
}
// zero-out the y-values for points we are going to clear
// do it now, because we may be getting rid of points that
// might result in us needing to down-size or adjust highest point
if( mygraph->xval > mygraph->graphbmp.bmWidth - CLEARAHEAD )
numclear = mygraph->graphbmp.bmWidth - mygraph->xval;
else
numclear = CLEARAHEAD;
for( i=0; i < numclear; i++) {
mygraph->yval[0][ mygraph->xval+i ] = -1.0;
if( mygraph->xval + i == mygraph->highptx[0] ) {
oldhigh = mygraph->highpty[0];
if( (mygraph->highpty[0] = ScanGraph( mygraph, 0 )) != oldhigh )
NewHighPt( mygraph );
}
if( mygraph->numplots == 2 ) {
if( mygraph->xval + i == mygraph->highptx[1] ) {
oldhigh = mygraph->highpty[1];
if( (mygraph->highpty[1] = ScanGraph( mygraph, 1 )) != oldhigh )
NewHighPt( mygraph );
}
mygraph->yval[1][ mygraph->xval+i ] = -1.0;
}
}
// see if we need to down-size
if( mygraph->highpty[0] < mygraph->xaxis[0]/3 ) {
rescale = TRUE;
scale1 = mygraph->highpty[0] * 3/2;
}
if( mygraph->numplots == 2 && mygraph->highpty[1] < mygraph->xaxis[1]/3 ) {
rescale = TRUE;
scale2 = mygraph->highpty[1] * 3/2;
}
// do any rescaling
if( rescale ) {
RescaleGraph( mygraph, prevx, scale1, scale2 );
// need to recalculate new points
if( scale1 )
yval1 = (long) (mygraph->halfheight[0] - (newy1 * mygraph->halfheight[0])/
mygraph->xaxis[0]);
if( scale2 )
yval2 = (long) (mygraph->halfheight[1] - (newy2 * mygraph->halfheight[1])/
mygraph->xaxis[1]);
}
// do we have a new high point?
if( newy1 > mygraph->highpty[0] ) {
mygraph->highpty[0] = newy1;
mygraph->highptx[0] = mygraph->xval;
NewHighPt( mygraph );
}
if( newy2 > mygraph->highpty[1] ) {
mygraph->highpty[1] = newy2;
mygraph->highptx[1] = mygraph->xval;
NewHighPt( mygraph );
}
// prepare for drawing on bitmap
hDC = GetDC( mygraph->graphwnd );
hdcMem = CreateCompatibleDC (hDC) ;
ReleaseDC( mygraph->graphwnd, hDC );
oldbitmap = SelectObject( hdcMem, mygraph->hgraphbmp ) ;
// clear area ahead of point
rc.left = mygraph->xval;
rc.top = 0;
rc.bottom = mygraph->graphbmp.bmHeight;
rc.right = (mygraph->xval > mygraph->graphbmp.bmWidth - CLEARAHEAD) ?
mygraph->graphbmp.bmWidth : mygraph->xval + CLEARAHEAD;
hbrBkGnd = GRAPHBKGRND;
FillRect( hdcMem, &rc, hbrBkGnd );
DeleteObject( hbrBkGnd );
// draw the first point
SelectObject( hdcMem, BluePen );
if( mygraph->yprev[0] == -1 ) mygraph->yprev[0] = yval1;
MoveToEx( hdcMem, mygraph->xval-1, mygraph->yprev[0], NULL );
LineTo ( hdcMem, mygraph->xval, yval1 );
// update previous point value and graph point value
mygraph->yprev[0] = yval1;
mygraph->yval[0][mygraph->xval] = newy1;
// draw the second point
if( mygraph->numplots == 2 ) {
SelectObject( hdcMem, RedPen );
if( mygraph->yprev[1] == -1 ) mygraph->yprev[1] = yval2;
MoveToEx( hdcMem, mygraph->xval-1, mygraph->yprev[1] + mygraph->halfheight[0] + 3, NULL );
LineTo( hdcMem, mygraph->xval, yval2 + mygraph->halfheight[0] + 3 );
// update previous point value
mygraph->yprev[1] = yval2;
mygraph->yval[1][mygraph->xval] = newy2;
// draw the graph seperator
DrawSeperator( hdcMem, mygraph->halfheight[0] + 1, mygraph->graphbmp.bmWidth );
}
// update labels
NewHighPt( mygraph );
// release the bitmap
mygraph->hgraphbmp = SelectObject( hdcMem, oldbitmap );
DeleteDC (hdcMem) ;
}
// force a paint of the graph
GetClientRect( mygraph->graphwnd, &rc );
rc.top = mygraph->axisbmp.bmHeight;
rc.bottom -= mygraph->legendbmp.bmHeight;
InvalidateRect( mygraph->graphwnd, NULL, FALSE );
}
//----------------------------------------------------------------------
//
// CloseGraphs
//
// When the info box is closing, we close all the graph windows.
//
//----------------------------------------------------------------------
void CloseGraphs( HWND hDlg )
{
int i;
for( i = 0; i< NUMGRAPHS; i++ ) {
if( Graph[i].graphstat ) {
DestroyWindow( Graph[i].graphwnd );
Graph[i].graphstat = 0;
}
}
}
//----------------------------------------------------------------------
//
// InitializeGraphs
//
// Each graph has its own title, legend, etc. that must be initialized
// once at application start-up.
//
//----------------------------------------------------------------------
void InitializeGraphs( HDC hDC )
{
int i;
// create pens
BluePen = CreatePen( PS_SOLID, 1, MYBLUE );
RedPen = CreatePen( PS_SOLID, 1, MYRED );
BlackPen = CreatePen( PS_SOLID, 1, MYBLACK );
WhitePen = CreatePen( PS_SOLID, 1, MYWHITE );
GrayPen = CreatePen( PS_SOLID, 1, MYGRAY );
// create font for use in graphs
SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LogFont),
(PVOID) &LogFont, FALSE);
// this is the height for 8 point size font in pixels
LogFont.lfHeight = 8 * GetDeviceCaps( hDC, LOGPIXELSY ) / 72;
hFont = CreateFontIndirect(&LogFont);
GetTextMetrics(hDC, &FontTM);
// intialize graph data structures
for( i=0; i < NUMGRAPHS; i++ ) {
Graph[i].graphstat = 0;
Graph[i].buttonid = 0;
Graph[i].xaxis[0] = 1.0;
Graph[i].xaxis[1] = 1.0;
Graph[i].highpty[0] = 0.0;
Graph[i].highpty[1] = 0.0;
switch( i ) {
case SIZEINDEX:
Graph[i].numplots = 2;
sprintf(Graph[i].graphtitle,"VCache Size" );
sprintf(Graph[i].titles[0], "VCache Size (KB)" );
sprintf(Graph[i].titles[1], "Free Memory (KB)" );
break;
case HITINDEX:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -