📄 filemon.c
字号:
}
switch (uMsg) {
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_MOUSEMOVE:
// delete any existing balloon
if( hBalloon ) DestroyWindow( hBalloon );
// save mouse position and reset the timer
mousePosition = MAKEPOINTS( lParam );
SetTimer( hWnd, 2, BALLOONDELAY, NULL );
break;
case WM_VSCROLL:
case WM_HSCROLL:
case WM_KEYDOWN:
if( hBalloon ) DestroyWindow( hBalloon );
if( uMsg == WM_KEYDOWN &&
wParam == VK_ESCAPE &&
hWndFind ) {
DestroyWindow( hWndFind );
hWndFind = NULL;
}
break;
case WM_RBUTTONDOWN:
mousePosition = MAKEPOINTS( lParam );
SetTimer( hWnd, 2, BALLOONDELAY, NULL );
// fall-through
case WM_TIMER:
// are we currently in the listview?
GetCursorPos( &hitPoint );
GetClientRect( hWnd, &listRect );
topleftPoint.x = listRect.left;
topleftPoint.y = listRect.top;
ClientToScreen( hWnd, &topleftPoint );
bottomrightPoint.x = listRect.right;
bottomrightPoint.y = listRect.bottom;
ClientToScreen( hWnd, &bottomrightPoint );
if( hitPoint.x < topleftPoint.x ||
hitPoint.x > bottomrightPoint.x ||
hitPoint.y < topleftPoint.y ||
hitPoint.y > bottomrightPoint.y ||
(hWndFind && GetFocus() != hWndList) ) {
// delete any existing balloon
if( hBalloon ) DestroyWindow( hBalloon );
break;
}
hitItem.pt.x = mousePosition.x;
hitItem.pt.y = mousePosition.y;
if( ListView_SubItemHitTest( hWndList, &hitItem ) != -1 ) {
itemClick.itemText[0] = 0;
ListView_GetItemText( hWndList, hitItem.iItem,
hitItem.iSubItem, itemClick.itemText, 1024 );
// delete any existing balloon
if( hBalloon ) DestroyWindow( hBalloon );
if( strlen( itemClick.itemText ) ) {
if( hitItem.iSubItem ) {
ListView_GetSubItemRect( hWndList, hitItem.iItem, hitItem.iSubItem,
LVIR_BOUNDS, &itemClick.itemPosition);
itemClick.itemPosition.bottom -= itemClick.itemPosition.top;
itemClick.itemPosition.right -= itemClick.itemPosition.left;
} else {
ListView_GetSubItemRect( hWndList, hitItem.iItem, 0,
LVIR_BOUNDS, &itemClick.itemPosition);
itemClick.itemPosition.bottom -= itemClick.itemPosition.top;
itemClick.itemPosition.right = ListView_GetColumnWidth( hWndList, 0 );
itemClick.itemPosition.left = 0;
}
hitPoint.y = itemClick.itemPosition.top;
hitPoint.x = itemClick.itemPosition.left;
ClientToScreen( hWnd, &hitPoint );
itemClick.itemPosition.left = hitPoint.x;
itemClick.itemPosition.top = hitPoint.y;
// pop-up a balloon (tool-tip like window)
hBalloon = CreateWindowEx( 0, "BALLOON",
"balloon",
WS_POPUP|WS_BORDER,
100, 100,
200, 200,
hWndMain, NULL, hInst,
&itemClick );
if( hBalloon) SetFocus( hWnd );
}
}
break;
}
// pass-through to real listview handler
return CallWindowProc(ListViewWinMain, hWnd, uMsg, wParam,
lParam);
}
/****************************************************************************
*
* 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 char process9xLabel[] = {"Process"};
static struct {
TCHAR * Label; // title of column
DWORD Width;
} column[] = {
{ "#" },
{ "Time" },
{ "Process" },
{ "Request" },
{ "Path" },
{ "Result" },
{ "Other" },
};
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Set the column widths according to the user-settings
for( j = 0; j < NUMCOLUMNS; j++ ) {
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( WS_EX_OVERLAPPEDWINDOW, WC_LISTVIEW, TEXT(""),
WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT |
LVS_OWNERDRAWFIXED,
0, ShowToolbar ? TOOLBARHEIGHT : 0,
rc.right - rc.left,
rc.bottom - rc.top - (ShowToolbar ? TOOLBARHEIGHT : 0),
hWndParent, (HMENU)ID_LIST, hInst, NULL );
if ( hWndList == NULL )
return NULL;
// Make it a nice fix-width font for easy reading
SendMessage( hWndList, WM_SETFONT, (WPARAM) hFont, (LPARAM) 0 );
// 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;
if( j == 2 && !IsNT )
lvC.pszText = process9xLabel;
else
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 );
// Sub-class
ListViewWinMain = (WNDPROC) SetWindowLongPtr(hWndList,
GWLP_WNDPROC,
(LONG_PTR) ListViewSubclass);
return hWndList;
}
/****************************************************************************
*
* FUNCTION: SaveFile()
*
* PURPOSE: Lets the user go select a file.
*
****************************************************************************/
void SaveFile( HWND hWnd, HWND ListBox, BOOLEAN SaveAs )
{
OPENFILENAME SaveFileName;
TCHAR szFile[MAX_PATH] = _T(""), fieldtext[MAXITEMLENGTH];
TCHAR output[MAXITEMLENGTH*NUMCOLUMNS];
FILE *hFile;
int numitems;
int row, subitem;
if( SaveAs || !FileChosen ) {
SaveFileName.lStructSize = sizeof (SaveFileName);
SaveFileName.hwndOwner = hWnd;
SaveFileName.hInstance = hInst;
SaveFileName.lpstrFilter = _T("File Info (*.LOG)\0*.LOG\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("*.log");
SaveFileName.lpfnHook = NULL;
SaveFileName.Flags = OFN_LONGNAMES|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
if( !GetSaveFileName( &SaveFileName ))
return;
} else
// open previous szFile
_tcscpy( szFile, szFileName );
// open the file
hFile = _tfopen( 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;
for( subitem = 0; subitem < NUMCOLUMNS; subitem++ ) {
fieldtext[0] = 0;
ListView_GetItemText( ListBox, row, subitem, fieldtext, 256 );
_tcscat( output, fieldtext );
_tcscat( output, _T("\t") );
}
_ftprintf( hFile, _T("%s\n"), output );
}
fclose( hFile );
_tcscpy( szFileName, szFile );
FileChosen = TRUE;
SetCursor( hSaveCursor );
ReleaseCapture();
}
/****************************************************************************
*
* FUNCTION: HistoryProc
*
* PURPOSE: Processes messages for "Filter" dialog box
*
****************************************************************************/
BOOL APIENTRY HistoryProc( HWND hDlg, UINT message, UINT wParam, LONG lParam )
{
DWORD newMaxLines, numRows;
char history[64];
switch ( message ) {
case WM_INITDIALOG:
// initialize the controls to reflect the current filter
sprintf( history, "%d", MaxLines );
SetDlgItemTextA( hDlg, IDC_HISTORY, history );
SendMessage (GetDlgItem( hDlg, IDC_SPIN), UDM_SETRANGE, 0L,
MAKELONG (9999, 0));
return TRUE;
case WM_COMMAND:
if ( LOWORD( wParam ) == IDOK ) {
// make sure that max lines is legal
GetDlgItemTextA( hDlg, IDC_HISTORY, history, 64 );
if( !sscanf( history, "%d", &newMaxLines )) {
MessageBox( NULL, TEXT("Invalid History Depth."),
TEXT("Filter Error"), MB_OK|MB_ICONWARNING );
return TRUE;
}
MaxLines = newMaxLines;
EndDialog( hDlg, TRUE );
if (MaxLines ) {
numRows = ListView_GetItemCount( hWndList );
SendMessage(hWndList, WM_SETREDRAW, FALSE, 0);
while ( numRows >= MaxLines ) {
ListView_DeleteItem ( hWndList, 0 );
numRows--;
}
SendMessage(hWndList, WM_SETREDRAW, TRUE, 0);
}
return TRUE;
} else if( LOWORD( wParam ) == IDCANCEL ) {
EndDialog( hDlg, TRUE );
} else if( LOWORD( wParam ) == IDRESET ) {
// reset filter to default of none
SetDlgItemTextA( hDlg, IDC_HISTORY, "0" );
}
break;
case WM_CLOSE:
EndDialog( hDlg, TRUE );
return TRUE;
}
return FALSE;
}
/****************************************************************************
*
* FUNCTION: AboutDlgProc
*
* PURPOSE: Processes messages for "About" dialog box
*
****************************************************************************/
BOOL CALLBACK AboutDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam )
{
RECT parentRc, childRc;
static HWND hLink;
static BOOL underline_link;
static HFONT hFontNormal = NULL;
static HFONT hFontUnderline = NULL;
static HCURSOR hHandCursor = NULL;
static HCURSOR hRegularCursor;
LOGFONT logfont;
switch ( message ) {
case WM_INITDIALOG:
GetWindowRect( GetParent(hDlg), &parentRc );
GetWindowRect( hDlg, &childRc );
parentRc.left += 70;
parentRc.top += 60;
MoveWindow( hDlg, parentRc.left, parentRc.top, childRc.right - childRc.left, childRc.bottom - childRc.top, TRUE );
underline_link = TRUE;
hLink = GetDlgItem( hDlg, IDC_LINK );
// get link fonts
hFontNormal = GetStockObject(DEFAULT_GUI_FONT);
GetObject( hFontNormal, sizeof logfont, &logfont);
logfont.lfUnderline = TRUE;
hFontUnderline = CreateFontIndirect( &logfont );
// get hand
hHandCursor = LoadCursor( hInst, TEXT("HAND") );
hRegularCursor = LoadCursor( NULL, IDC_ARROW );
return TRUE;
case WM_CTLCOLORSTATIC:
if ( (HWND)lParam == hLink ) {
HDC hdc = (HDC)wParam;
SetBkMode( hdc, TRANSPARENT );
if ( GetSysColorBrush(26/*COLOR_HOTLIGHT*/) )
SetTextColor( hdc, GetSysColor(26/*COLOR_HOTLIGHT*/) );
else
SetTextColor( hdc, RGB(0,0,255) );
SelectObject( hdc, underline_link ? hFontUnderline : hFontNormal );
return (LONG)GetSysColorBrush( COLOR_BTNFACE );
}
break;
case WM_MOUSEMOVE: {
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
HWND hChild = ChildWindowFromPoint( hDlg, pt );
if ( underline_link == (hChild == hLink) ) {
underline_link = !underline_link;
InvalidateRect( hLink, NULL, FALSE );
}
if ( underline_link )
SetCursor( hRegularCursor );
else
SetCursor( hHandCursor );
break;
}
case WM_LBUTTONDOWN: {
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
HWND hChild = ChildWindowFromPoint( hDlg, pt );
if ( hChild == hLink ) {
ShellExecute( hDlg, TEXT("open"), TEXT("http://www.sysinternals.com"), NULL, NULL, SW_SHOWNORMAL );
}
break;
}
case WM_COMMAND:
switch ( wParam ) {
case IDOK:
case IDCANCEL:
EndDialog( hDlg, 0 );
return TRUE;
}
break;
case WM_CLOSE:
EndDialog( hDlg, 0 );
return TRUE;
default:
break;
}
return FALSE;
}
/******************************************************************************
*
* FUNCTION: GetDLLVersion
*
* PURPOSE: Gets the version number of the specified DLL.
*
******************************************************************************/
HRESULT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -