📄 regmon.c
字号:
wsprintf( msgbuf, _T("Error adding item %d to list view"), seq );
MessageBox( hWndList, msgbuf, _T("Regmon Error"), MB_OK );
return FALSE;
}
LastRow = row;
}
// Process name
if ( itemcnt>0 && *items[0] ) {
OemToChar( items[0], msgbuf );
ListView_SetItemText( hWndList, row, 1, msgbuf );
}
// Request type
if ( itemcnt>1 && *items[1] ) {
OemToChar( items[1], msgbuf );
ListView_SetItemText( hWndList, row, 2, msgbuf );
}
// Path
if ( itemcnt>2 && *items[2] ) {
OemToChar( items[2], msgbuf );
ListView_SetItemText( hWndList, row, 3, msgbuf );
}
// Result
if ( itemcnt>3 && *items[3] ) {
OemToChar( items[3], msgbuf );
ListView_SetItemText( hWndList, row, 4, msgbuf );
}
// Additional
if ( itemcnt>4 && *items[4] ) {
OemToChar( items[4], msgbuf );
ListView_SetItemText( hWndList, row, 5, msgbuf );
}
return TRUE;
}
/******************************************************************************
*
* FUNCTION: UpdateStatistics
*
* PURPOSE: Clear the statistics window and refill it with the current
* contents of the statistics buffer. Does not refresh the
* buffer from the device driver.
*
******************************************************************************/
void UpdateStatistics( HWND hWnd, HWND hWndList, BOOL Clear )
{
PENTRY ptr;
BOOLEAN itemsAdded = FALSE;
int totitems, i;
// Just return if nothing to do
if ( !Clear && StatsLen < sizeof(int)+2 )
return;
if( !IsNT ) {
hSaveCursor = SetCursor(hHourGlass);
SendMessage(hWndList, WM_SETREDRAW, FALSE, 0);
}
// Start with empty list
if ( Clear ) {
if( IsNT ) {
ListView_DeleteAllItems( hWndList );
} else {
totitems = ListView_GetItemCount( hWndList );
Deleting = TRUE;
for(i = 0; i < totitems; i++)
ListView_DeleteItem( hWndList, 0 );
Deleting = FALSE;
}
LastRow = 0;
}
// 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);
if( IsNT ) {
len += 4; len &= 0xFFFFFFFC; // +1 for null-terminator +3 for 32bit alignment
}
itemsAdded |= List_Append( hWndList, ptr->seq, ptr->text );
if( IsNT ) ptr = (void *)(ptr->text + len);
else ptr = (void *)(ptr->text + len + 1);
}
// Empty the buffer
StatsLen = 0;
// only do this if we added items
if( itemsAdded ) {
// 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 ) {
if( hBalloon ) DestroyWindow( hBalloon );
ListView_EnsureVisible( hWndList, ListView_GetItemCount(hWndList)-1, FALSE );
}
}
if( !IsNT ) {
SetCursor( hSaveCursor );
SendMessage(hWndList, WM_SETREDRAW, TRUE, 0);
InvalidateRect( hWndList, NULL, FALSE );
}
}
/****************************************************************************
*
* FUNCTION: ListViewSubclass(HWND,UINT,WPARAM)
*
* PURPOSE: Subclasses the listview so that we can do tooltips
*
****************************************************************************/
LRESULT CALLBACK ListViewSubclass(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
ITEM_CLICK itemClick;
LVHITTESTINFO hitItem;
static initTrack = FALSE;
POINT hitPoint, topleftPoint, bottomrightPoint;
RECT listRect;
static POINTS mousePosition;
if( !initTrack ) {
SetTimer( hWnd, 2, BALLOONDELAY, NULL );
initTrack = TRUE;
}
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_KEYDOWN:
case WM_VSCROLL:
case WM_HSCROLL:
if( hBalloon ) DestroyWindow( hBalloon );
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, 1,
LVIR_BOUNDS, &itemClick.itemPosition);
itemClick.itemPosition.bottom -= itemClick.itemPosition.top;
itemClick.itemPosition.right = itemClick.itemPosition.left;
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, _T("BALLOON"),
_T("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 struct {
TCHAR * Label; // title of column
DWORD Width; // width of column in pixels
DWORD Fmt;
} column[] = {
{ "#" , 35 },
{ "Process" , 90 },
{ "Request" , 90 },
{ "Path" , 225 },
{ "Result" , 90 },
{ "Other" , 150 },
};
// 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_CLIENTEDGE */ 0L, WC_LISTVIEW, _T(""),
WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT |
LVS_SINGLESEL,
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 );
// sub-class
ListViewWinMain = (WNDPROC) SetWindowLong(hWndList,
GWL_WNDPROC,
(DWORD)ListViewSubclass);
return hWndList;
}
/****************************************************************************
*
* FUNCTION: SaveFile()
*
* PURPOSE: Lets the user go select a file.
*
****************************************************************************/
void SaveFile( HWND hWnd, HWND ListBox, BOOLEAN SaveAs )
{
OPENFILENAME SaveFileName;
char szFile[256] = "", 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 = "Reg Data (*.RGD)\0*.RGD\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 = "Save File Info...";
SaveFileName.nFileOffset = 0;
SaveFileName.nFileExtension = 0;
SaveFileName.lpstrDefExt = "*.rgd";
SaveFileName.lpfnHook = NULL;
SaveFileName.Flags = OFN_LONGNAMES|OFN_HIDEREADONLY;
if( !GetSaveFileName( &SaveFileName ))
return;
} else
// open previous szFile
strcpy( szFile, szFileName );
// open the file
hFile = fopen( szFile, "w" );
if( !hFile ) {
MessageBox( NULL, "Create File Failed.",
"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 < 6; subitem++ ) {
fieldtext[0] = 0;
ListView_GetItemText( ListBox, row, subitem, fieldtext, 256 );
strcat( output, fieldtext );
strcat( output, "\t" );
}
fprintf( hFile, "%s\n", output );
}
fclose( hFile );
strcpy( szFileName, szFile );
FileChosen = TRUE;
SetCursor( hSaveCursor );
ReleaseCapture();
}
/****************************************************************************
*
* FUNCTION: FilterProc
*
* PURPOSE: Processes messages for "Filter" dialog box
*
****************************************************************************/
BOOL APIENTRY FilterProc( HWND hDlg, UINT message, UINT wParam, LONG lParam )
{
int nb;
FILTER upcaseFilter;
DWORD newMaxLines;
char history[64];
switch ( message ) {
case WM_INITDIALOG:
// initialize the controls to reflect the current filter
SetDlgItemText( hDlg, IDC_PROCFILTER, FilterDefinition.processfilter );
SetDlgItemText( hDlg, IDC_PROCEXCLUDE, FilterDefinition.processexclude );
SetDlgItemText( hDlg, IDC_PATHFILTER, FilterDefinition.pathfilter );
SetDlgItemText( hDlg, IDC_EXCLUDEFILTER, FilterDefinition.excludefilter );
CheckDlgButton( hDlg, IDC_SUCCESS, FilterDefinition.logsuccess );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -