⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcmon.c

📁 磁盘工具
💻 C
📖 第 1 页 / 共 4 页
字号:
//----------------------------------------------------------------------
//
// VCMON.C: Disk Cache Monitor for Windows 95.
//
// Copyright (c) 1996 by Mark Russinovich and Bryce Cogswell
//
//----------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <process.h>
#include <commctrl.h>
#include "resource.h"  
#include "vxd\stats.h"

//----------------------------------------------------------------------
//
// typedefs
//
//----------------------------------------------------------------------

// this data structure contains all the relevant information about
// a graph
typedef struct {
	int			graphstat;		// is graph on or off?

	// related to our parent and our checkbox
	HWND		graphdlg;		// our parent dialog
	int			buttonid;		// control button id for us

	// our stuff
	HWND		graphwnd;		// window handle
	int			graphwidth;		// width of graph (in pixels)
	int			graphheight;	// height of graph (in pixels)
	int			halfheight[2];	// height of subgraphs (in pixels)
	BITMAP		graphbmp;		// graph bitmap
	HBITMAP		hgraphbmp;
	BITMAP		legendbmp;		// legend bitmap
	HBITMAP		hlegendbmp;
	BITMAP		axisbmp;		// axis bitmap
	HBITMAP		haxisbmp;	
	int			numplots;		// number of things plotted on graph
	char		graphtitle[64]; // window title
	char		titles[2][64];	// line titles

	// numeric values
	double		highpty[2];		// highest value on graph
	long		highptx[2];		// x-coord of highest value
	double		xaxis[2];		// real value of x-axis
	long		xval;			// current x value
	long		yprev[2];		// previous y value
	double		*yval[2];		// y values on entire graph
} graphdata;


//----------------------------------------------------------------------
//
// defines
//
//----------------------------------------------------------------------

// name of vxd to connect with
#define	VXD_NAME		"\\\\.\\VCMON.VXD"

// color definitions
#define MYBLACK 		PALETTERGB( 0, 0, 0 )
#define MYGRAY			PALETTERGB( 0x80, 0x80, 0x80 )
#define MYWHITE			PALETTERGB( 0xFF, 0xFF, 0xFF )
#define MYBLUE  		PALETTERGB( 0, 0, 0xFF )
#define MYRED			PALETTERGB( 0xFF, 0, 0 )

// graph background color
#define GRAPHBKGRND		GetStockObject( LTGRAY_BRUSH )

// initial size of graph windows
#define GRAPHWIDTH 		450
#define GRAPHHEIGHT		300

// number of points ahead of current one that we clear
#define CLEARAHEAD		20

// distance away from checkbox that graph appears
#define XGRAPHSPACE		20
#define YGRAPHSPACE		20

// indexes into the graph array
#define NUMGRAPHS		6
#define SIZEINDEX		0
#define HITINDEX		1
#define	HOLDINDEX		2
#define	NEWINDEX		3
#define PGFLTINDEX		4
#define REPINDEX		5


//----------------------------------------------------------------------
//
// globals
//
//----------------------------------------------------------------------

// sample rate for getting info from VxD
DWORD				SampleRate = 500; // default == 0.5 second


// VxD related globals
HANDLE				VxDHandle = INVALID_HANDLE_VALUE;
OVERLAPPED  		Ovrlp = {0,0,0,0,0};
VcmonStatus_s		*Stats_p;
VcmonStatus_s		CurStats, LastStats;

// general windows things
static char			msgbuf[ 2048 ];
static HINSTANCE	hInst;

// pens for graph drawing
HPEN				BluePen, RedPen, BlackPen, WhitePen, GrayPen;

// indicates id of new graph being created
int					NewGraph;

// window handle of main dialog
HWND				hMainDlg;

// graphs				 
graphdata			Graph[NUMGRAPHS];
HANDLE				DrawCrit;

// font info
TEXTMETRIC 			FontTM;
LOGFONT    			LogFont;	
HFONT 				hFont = (HFONT) NULL;


//----------------------------------------------------------------------
//  
// Abort
//
// If there is a fatal problem, pop up a message box and die. Assumes
// that it is called from the dialog box.
//
//----------------------------------------------------------------------
void Abort( HWND hWnd, char * Msg )
{
	MessageBox( hWnd, Msg, "VCache Monitor", MB_OK );
	EndDialog( hWnd, 1 );
	PostQuitMessage( 1 );
}


//----------------------------------------------------------------------
//  
// centerWindow
// 
// Centers the Window on the screen.
//
//----------------------------------------------------------------------
VOID centerWindow( HWND hDlg )
{
	RECT            aRt;

	// center the dialog box
	GetWindowRect( hDlg, &aRt );
	OffsetRect( &aRt, -aRt.left, -aRt.top );
	MoveWindow( hDlg,
			((GetSystemMetrics( SM_CXSCREEN ) -
				aRt.right ) / 2 + 4) & ~7,
  			(GetSystemMetrics( SM_CYSCREEN ) -
				aRt.bottom) / 2,
			aRt.right, aRt.bottom, 0 );
}


//----------------------------------------------------------------------
//  
// AboutDlgProc
//
// Pops up the standard About dialog box.
//
//----------------------------------------------------------------------
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, UINT wParam,
                       		LONG lParam) {
	switch (message) {
	case WM_INITDIALOG :
		// center the dialog
		centerWindow( hDlg );
		return TRUE ;
 
	case WM_COMMAND :
		switch (wParam) {

		case IDOK :
			EndDialog (hDlg, 0) ;
			return TRUE ;
		}
		break; 

	case WM_CLOSE:	
		EndDialog (hDlg, 0);
		return TRUE;
	}
	return FALSE ;
}


//----------------------------------------------------------------------
//  
// SliderDlgProc
//
// Pops up a dialog with a slider that is used to set the sample
// frequency.
//
//----------------------------------------------------------------------
BOOL CALLBACK SliderDlgProc (HWND hDlg, UINT message, UINT wParam,
                       		LONG lParam) {
	DWORD			NewRate;
	static HWND		hwndTrack;

	switch (message) {
	case WM_INITDIALOG :
		// center the dialog
		centerWindow( hDlg );

		// initialize the trackbar
		hwndTrack = GetDlgItem( hDlg, IDC_SLIDE ); 

		// 10 ticks so 1 == .5 seconds
		SendMessage(hwndTrack, TBM_SETRANGE, 
	        (WPARAM) TRUE,                
	        (LPARAM) MAKELONG(0, 10));

		// place one tick every 1 second
		SendMessage(hwndTrack, TBM_SETTICFREQ, 
	        (WPARAM) 2,                  
	        (LPARAM) 0 );

		// move slider to current sample rate
		SendMessage(hwndTrack, TBM_SETPOS, 
        	(WPARAM) TRUE,                   
        	(LPARAM) SampleRate/500); 
		return TRUE ;

	case WM_HSCROLL:
		switch( LOWORD(wParam) ) {
		case TB_ENDTRACK:
			// don't let an illegal value get through
            NewRate = SendMessage(hwndTrack, TBM_GETPOS, 0, 0);
            if( NewRate < 1 )
				SendMessage(hwndTrack, TBM_SETPOS, 
                    (WPARAM) TRUE,  
                    (LPARAM) 1); 
			break;
		}
		break;
 
	case WM_COMMAND :
		switch (wParam) {
		case IDOK:
			// set new sample rate
			SampleRate = SendMessage(hwndTrack, TBM_GETPOS, 0, 0) * 500;

			// tell VxD to change rate
			if ( ! DeviceIoControl(	VxDHandle, VCMON_SETRATE,
						&SampleRate, sizeof( SampleRate ), NULL, 0,  
						NULL, NULL ) ) {
				wsprintf( msgbuf, "Can't set rate with %s.", VXD_NAME );
				Abort( hDlg, msgbuf );
				return FALSE;
			}
			EndDialog( hDlg, 0);
			return TRUE;

		case IDCANCEL:
			EndDialog( hDlg, 0 );
			return TRUE ;			
		}
		break; 

	case WM_CLOSE:	
		EndDialog (hDlg, 0);
		return TRUE;
	}
	return FALSE ;
}


//----------------------------------------------------------------------
//
// FillStock
// 
// Fills a rectangle with the specified color.
//
//----------------------------------------------------------------------
void FillStock( HDC hDC, RECT *rc, int color )
{
	HBRUSH		hbrBkGnd;

	hbrBkGnd 	= GetStockObject( color );
    FillRect( hDC, rc, hbrBkGnd);
    DeleteObject( hbrBkGnd );
}


//----------------------------------------------------------------------
//  
// DrawSeperator
//
// Draws the 3-d lines seperating the graph from the upper and lower
// parts of the window
//
//----------------------------------------------------------------------
void DrawSeperator( HDC hDC, long top, long width )
{
	// white line
	SelectObject( hDC, WhitePen );
	MoveToEx( hDC, 0, top + 1, NULL );
	LineTo( hDC, width, top + 1 );

	// gray line
	SelectObject( hDC, GrayPen );
	MoveToEx( hDC, 0, top, NULL );
	LineTo( hDC, width , top );
}


//----------------------------------------------------------------------
//  
// DrawBitmap
//
// Draws the logo onto the dialog box. We have bitmaps for large and
// small font cases, but if the system is using an odd size we stretch
// the appropriate bitmap. Looks great for all the cases I tried.
//
//----------------------------------------------------------------------
void DrawBitmap (HDC hdc, HBITMAP hBitmap, short xStart, short yStart,
	int xLen, int yLen, int stretch )
{
     BITMAP    bm ;
     HDC       hdcMem ;
     POINT     ptSize, ptOrg , ptBSize;

     hdcMem = CreateCompatibleDC (hdc) ;
     SelectObject (hdcMem, hBitmap) ;
     SetMapMode (hdcMem, GetMapMode (hdc)) ;

     GetObject (hBitmap, sizeof (BITMAP), (LPSTR) &bm) ;
     ptSize.x = xLen; 
     ptSize.y = yLen; 
     DPtoLP (hdc, &ptSize, 1) ;

     ptOrg.x = 0 ;
     ptOrg.y = 0 ;
     DPtoLP (hdcMem, &ptOrg, 1) ;

	 ptBSize.x = bm.bmWidth;
	 ptBSize.y = bm.bmHeight;
	 DPtoLP (hdcMem, &ptBSize, 1);

	 if((ptSize.x < ptBSize.x - 10) || (ptSize.x > ptBSize.x) || stretch)
	 	StretchBlt (hdc, xStart, yStart, ptSize.x, ptSize.y,
	 		hdcMem, ptOrg.x, ptOrg.y, ptBSize.x, ptBSize.y, SRCCOPY);
	 else
	 	BitBlt (hdc, xStart, yStart, ptSize.x, ptSize.y,
     		hdcMem, ptOrg.x, ptOrg.y, SRCCOPY) ;

     DeleteDC (hdcMem) ;
}


//----------------------------------------------------------------------
//
// NewHightPt
//
// If we get a new high point for the graph, we have to reset the
// label bitmap
//
//----------------------------------------------------------------------
void NewHighPt( graphdata *mygraph )
{
	HDC				hdcMem, hDC;
	HBITMAP			oldbitmap;
	HFONT      		hOldFont = NULL;
	RECT			rc;
	char			tmp[64];

   	// prepare for drawing on bitmap
	hDC = GetDC( mygraph->graphwnd );
	hdcMem = CreateCompatibleDC (hDC) ;

	DeleteObject( mygraph->haxisbmp );
	mygraph->haxisbmp = CreateCompatibleBitmap( hDC, 
								mygraph->graphwidth,
								FontTM.tmHeight );
	GetObject( mygraph->haxisbmp, sizeof (BITMAP), 
							(LPSTR) &mygraph->axisbmp);
	oldbitmap = SelectObject( hdcMem, mygraph->haxisbmp );

	// fill bitmap with grey background	and draw seperator
	rc.top = 0;
	rc.left = 0;
	rc.bottom = mygraph->axisbmp.bmHeight;
	rc.right  = mygraph->axisbmp.bmWidth;
	FillStock( hdcMem, &rc, LTGRAY_BRUSH );
	DrawSeperator( hdcMem, mygraph->axisbmp.bmHeight - 2, 
					mygraph->axisbmp.bmWidth );

	// divide things up into different colors
	SetBkColor( hdcMem, GetSysColor(COLOR_BTNFACE));
	if (hFont) hOldFont = SelectObject( hdcMem, hFont);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -