?? filemon.c
字號:
}
// Add all List items from Stats[] data
for ( ptr = (void *)Stats; (char *)ptr < min(Stats+StatsLen,Stats + sizeof (Stats)); ) {
// Add to list
ULONG len = strlen(ptr->text);
len += 4; len &= 0xFFFFFFFC; // +1 for null-terminator +3 for 32bit alignment
List_Append( hWndList, ptr->seq, ptr->time.QuadPart, ptr->text );
ptr = (void *)(ptr->text + len);
}
// Empty the buffer
StatsLen = 0;
// limit number of lines saved
if (MaxLines) {
SendMessage(hWndList, WM_SETREDRAW, FALSE, 0);
while ( LastRow > MaxLines ) {
ListView_DeleteItem ( hWndList, 0 );
LastRow--;
}
SendMessage(hWndList, WM_SETREDRAW, TRUE, 0);
}
// Scroll so newly added items are visible
if ( Autoscroll )
ListView_EnsureVisible( hWndList, ListView_GetItemCount(hWndList)-1, FALSE );
}
/****************************************************************************
*
* FUNCTION: CreateListView(HWND)
*
* PURPOSE: Creates the statistics list view window and initializes it
*
****************************************************************************/
HWND CreateList( HWND hWndParent )
{
HWND hWndList; // handle to list view window
RECT rc; // rectangle for setting size of window
LV_COLUMN lvC; // list view column structure
DWORD j;
static struct {
TCHAR * Label; // title of column
DWORD Width; // width of column in pixels
DWORD Fmt;
} column[] = {
{ _T("#"), 35 },
{ _T("Time"), 50 },
#if GETPROCESS
{ _T("Process"), 90 },
#endif
{ _T("Request"), 130 },
{ _T("Path"), 200 },
{ _T("Result"), 70 },
{ _T("Other"), 150 },
};
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Set the column widths according to the user-settings
#if GETPROCESS
for( j = 0; j < NUMCOLUMNS; j++ ) {
#else
for( j = 0; j < NUMCOLUMNS-1; j++ ) {
#endif
column[j].Width = PositionInfo.column[j];
}
// Get the size and position of the parent window.
GetClientRect( hWndParent, &rc );
// Create the list view window
hWndList = CreateWindowEx( 0L, WC_LISTVIEW, _T(""),
WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT |
LVS_SINGLESEL | WS_EX_CLIENTEDGE, // styles
0, TOOLBARHEIGHT, rc.right - rc.left, rc.bottom - rc.top - TOOLBARHEIGHT,
hWndParent, (HMENU)ID_LIST, hInst, NULL );
if ( hWndList == NULL )
return NULL;
// Initialize columns
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvC.fmt = LVCFMT_LEFT; // left-align column
// Add the columns.
for ( j = 0; j < sizeof column/sizeof column[0]; ++j ) {
lvC.iSubItem = j;
lvC.cx = column[j].Width;
lvC.pszText = column[j].Label;
if ( ListView_InsertColumn( hWndList, j, &lvC ) == -1 )
return NULL;
}
// set full-row selection
SendMessage( hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT );
return hWndList;
}
/****************************************************************************
*
* FUNCTION: SaveFile()
*
* PURPOSE: Lets the user go select a file.
*
****************************************************************************/
void SaveFile( HWND hWnd, HWND ListBox, BOOLEAN SaveAs )
{
OPENFILENAME SaveFileName;
TCHAR szFile[256] = _T(""), fieldtext[256], output[1024];
FILE *hFile;
int numitems;
int row, subitem;
if( SaveAs || !FileChosen ) {
SaveFileName.lStructSize = sizeof (SaveFileName);
SaveFileName.hwndOwner = hWnd;
SaveFileName.hInstance = (HANDLE) hInst;
SaveFileName.lpstrFilter = _T("File Info (*.FIL)\0*.FIL\0All (*.*)\0*.*\0");
SaveFileName.lpstrCustomFilter = (LPTSTR)NULL;
SaveFileName.nMaxCustFilter = 0L;
SaveFileName.nFilterIndex = 1L;
SaveFileName.lpstrFile = szFile;
SaveFileName.nMaxFile = 256;
SaveFileName.lpstrFileTitle = NULL;
SaveFileName.nMaxFileTitle = 0;
SaveFileName.lpstrInitialDir = NULL;
SaveFileName.lpstrTitle = _T("Save File Info...");
SaveFileName.nFileOffset = 0;
SaveFileName.nFileExtension = 0;
SaveFileName.lpstrDefExt = _T("*.fil");
SaveFileName.lpfnHook = NULL;
SaveFileName.Flags = OFN_LONGNAMES|OFN_HIDEREADONLY;
if( !GetSaveFileName( &SaveFileName ))
return;
} else
// open previous szFile
wcscpy( szFile, szFileName );
// open the file
hFile = _wfopen( szFile, _T("w") );
if( !hFile ) {
MessageBox( NULL, _T("Create File Failed."),
_T("Save Error"), MB_OK|MB_ICONSTOP );
return;
}
// post hourglass icon
SetCapture(hWnd);
hSaveCursor = SetCursor(hHourGlass);
numitems = ListView_GetItemCount(ListBox);
for ( row = 0; row < numitems; row++ ) {
output[0] = 0;
#if GETPROCESS
for( subitem = 0; subitem < NUMCOLUMNS; subitem++ ) {
#else
for( subitem = 0; subitem < NUMCOLUMNS-1; subitem++ ) {
#endif
fieldtext[0] = 0;
ListView_GetItemText( ListBox, row, subitem, fieldtext, 256 );
wcscat( output, fieldtext );
wcscat( output, _T("\t") );
}
fwprintf( hFile, _T("%s\n"), output );
}
fclose( hFile );
wcscpy( szFileName, szFile );
FileChosen = TRUE;
SetCursor( hSaveCursor );
ReleaseCapture();
}
/****************************************************************************
*
* FUNCTION: About
*
* PURPOSE: Processes messages for "About" dialog box
*
****************************************************************************/
BOOL APIENTRY About( HWND hDlg, UINT message, UINT wParam, LONG lParam )
{
switch ( message ) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if ( LOWORD( wParam ) == IDOK ) {
EndDialog( hDlg, TRUE );
return TRUE;
}
break;
case WM_CLOSE:
EndDialog( hDlg, TRUE );
return TRUE;
}
return FALSE;
}
/******************************************************************************
*
* FUNCTION: GetDLLVersion
*
* PURPOSE: Gets the version number of the specified DLL.
*
******************************************************************************/
HRESULT GetDLLVersion( PWCHAR DllName, LPDWORD pdwMajor, LPDWORD pdwMinor)
{
HINSTANCE hDll;
HRESULT hr = S_OK;
DLLVERSIONINFO_ dvi;
*pdwMajor = 0;
*pdwMinor = 0;
//Load the DLL.
hDll = LoadLibrary(DllName);
if( hDll ) {
pDllGetVersionProc = (PVOID)GetProcAddress(hDll, "DllGetVersion");
if(pDllGetVersionProc) {
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersionProc)(&dvi);
if(SUCCEEDED(hr)) {
*pdwMajor = dvi.dwMajorVersion;
*pdwMinor = dvi.dwMinorVersion;
}
} else {
// If GetProcAddress failed, the DLL is a version previous to the one
// shipped with IE 3.x.
*pdwMajor = 4;
*pdwMinor = 0;
}
FreeLibrary(hDll);
return hr;
}
return E_FAIL;
}
/****************************************************************************
*
* FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
*
* PURPOSE: Processes messages for the statistics window.
*
****************************************************************************/
LONG APIENTRY MainWndProc( HWND hWnd, UINT message, UINT wParam, LONG lParam)
{
static DWORD MaxDriveSet = 0;
static HMENU DriveMenu;
static HWND hWndTT;
static HWND hWndToolbar;
DWORD newDriveSet;
LPTOOLTIPTEXT lpToolTipText;
LPFINDREPLACE findMessageInfo;
#if _DEBUG
ULONG irpcount;
#endif
DWORD nb, versionNumber;
DWORD drive, drivetype;
TCHAR Path[ 256 ];
static TCHAR szBuf[128];
TCHAR name[32];
TCHAR *File;
DWORD majorver, minorver;
ITEM_CLICK itemClick;
LVHITTESTINFO hitItem;
DWORD startTime;
switch ( message ) {
case WM_CREATE:
// get hourglass icon ready
hHourGlass = LoadCursor( NULL, IDC_WAIT );
// post hourglass icon
SetCapture(hWnd);
hSaveCursor = SetCursor(hHourGlass);
// determine performance counter frequency
QueryPerformanceFrequency( &PerfFrequency );
// Create the toolbar control - use modern style if available.
GetDLLVersion( L"comctl32.dll", &majorver, &minorver );
if( majorver > 4 || (majorver == 4 && minorver >= 70) ) {
hWndToolbar = CreateToolbarEx(
hWnd, TOOLBAR_FLAT | WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS,
ID_TOOLBAR, 11, hInst, IDB_TOOLBAR, (LPCTBBUTTON)&tbButtons,
NUMBUTTONS, 16,16,16,15, sizeof(TBBUTTON));
} else {
hWndToolbar = CreateToolbarEx(
hWnd, WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS,
ID_TOOLBAR, 11, hInst, IDB_TOOLBAR, (LPCTBBUTTON)&tbButtonsOld,
NUMBUTTONSOLD, 16,16,16,15, sizeof(TBBUTTON));
}
if (hWndToolbar == NULL )
MessageBox (NULL, _T("Toolbar not created!"), NULL, MB_OK );
// Create the ListBox within the main window
hWndList = CreateList( hWnd );
if ( hWndList == NULL )
MessageBox( NULL, _T("List not created!"), NULL, MB_OK );
// open the handle to the device
if( !SearchPath( NULL, SYS_FILE, NULL, sizeof(Path), Path, &File ) ) {
// that failed, last ditch - try current directory again.
GetCurrentDirectory( sizeof Path, Path );
wsprintf( Path+lstrlen(Path), _T("\\%s"), SYS_FILE );
}
if ( ! LoadDeviceDriver( SYS_NAME, Path, &sys_handle ) ) {
wsprintf( msgbuf, _T("Opening %s (%s): error %d"), SYS_NAME, Path,
GetLastError( ) );
Abort( hWnd, msgbuf );
}
// Correct driver version?
if ( ! DeviceIoControl( sys_handle, FILEMON_version,
NULL, 0, &versionNumber, sizeof(DWORD), &nb, NULL ) ||
versionNumber != FILEMONVERSION )
{
MessageBox( hWnd, _T("Filemon located a driver with the wrong version.\n")
_T("If you just installed a new version you must reboot before you are\n")
_T("able to use it."), _T("Filemon"), MB_ICONERROR);
PostQuitMessage( 1 );
return 0;
}
// Have driver zero information
if ( ! DeviceIoControl( sys_handle, FILEMON_zerostats,
NULL, 0, NULL, 0, &nb, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return 0;
}
// Give the user to change initial filter
if( strcmp(FilterDefinition.processfilter, "*") ||
strcmp(FilterDefinition.excludeprocess, "") ||
strcmp(FilterDefinition.pathfilter, "*") ||
strcmp(FilterDefinition.excludefilter, "") ||
!FilterDefinition.logreads ||
!FilterDefinition.logwrites ) {
DialogBox( hInst, _T("InitFilter"), hWnd, (DLGPROC) FilterProc );
} else {
// tell the driver the initial filter
if ( ! DeviceIoControl( sys_handle, FILEMON_setfilter,
&FilterDefinition, sizeof(FILTER), NULL,
0, &nb, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return 0;
}
}
// tell the driver the timing type
if ( !DeviceIoControl( sys_handle, FILEMON_timetype,
(PVOID) &TimeIsDuration, sizeof(BOOLEAN),
NULL, 0, &nb, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return 0;
}
CheckMenuItem( GetMenu(hWnd), IDM_TIME,
MF_BYCOMMAND|(TimeIsDuration?MF_CHECKED:MF_UNCHECKED) );
// Tell driver to start filtering
if ( ! DeviceIoControl( sys_handle, FILEMON_startfilter,
NULL, 0, NULL, 0, &nb, NULL ) )
{
Abort( hWnd, _T("Couldn't access device driver") );
return 0;
}
// Create a pop-up menu item with the drives
DriveMenu = CreateMenu();
// Get available drives we can monitor
MaxDriveSet = GetLogicalDrives();
if( PositionInfo.curdriveset != (DWORD) -1 )
CurDriveSet = PositionInfo.curdriveset;
else
CurDriveSet = MaxDriveSet;
for ( drive = 0; drive < 32; ++drive ) {
if ( MaxDriveSet & (1 << drive) ) {
wsprintf( name, _T("%c:\\"), 'A'+drive );
switch ( GetDriveType( name ) ) {
// We don't like these: remove them
case 0: // The drive type cannot be determined.
case 1: // The root directory does not exist.
drivetype = DRVUNKNOWN;
CurDriveSet &= ~(1 << drive);
break;
case DRIVE_REMOVABLE: // The drive can be removed from the drive.
drivetype = DRVREMOVE;
CurDriveSet &= ~(1 << drive);
break;
case DRIVE_CDROM: // The drive is a CD-ROM drive.
drivetype = DRVCD;
CurDriveSet &= ~(1 << drive);
break;
// We like these types
case DRIVE_FIXED: // The disk cannot be removed from the drive.
drivetype = DRVFIXED;
break;
case DRIVE_REMOTE: // The drive is a remote (network) drive.
drivetype = DRVREMOTE;
break;
case DRIVE_RAMDISK: // The drive is a RAM disk.
drivetype = DRVRAM;
break;
}
wsprintf( name, _T("Drive &%c: (%s)"), 'A'+drive, DrvNames[drivetype] );
InsertMenu( DriveMenu, 0xFFFFFFFF, MF_BYPOSITION|MF_STRING,
IDC_DRIVE+drive, name );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -