📄 filterwnd.c
字号:
/******************************************************************//* *//* Winpooch : Windows Watchdog *//* Copyright (C) 2004-2006 Benoit Blanchon *//* *//* This program is free software; you can redistribute it *//* and/or modify it under the terms of the GNU General Public *//* License as published by the Free Software Foundation; either *//* version 2 of the License, or (at your option) any later *//* version. *//* *//* This program is distributed in the hope that it will be *//* useful, but WITHOUT ANY WARRANTY; without even the implied *//* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *//* PURPOSE. See the GNU General Public License for more *//* details. *//* *//* You should have received a copy of the GNU General Public *//* License along with this program; if not, write to the Free *//* Software Foundation, Inc., *//* 675 Mass Ave, Cambridge, MA 02139, USA. *//* *//******************************************************************//******************************************************************//* Build configuration *//******************************************************************/#define TRACE_LEVEL 2 /* warning *//******************************************************************//* Includes *//******************************************************************/// module's interface#include "FilterWnd.h"// standard headers#include <windows.h>#include <windowsx.h>#include <commctrl.h>#include <stdio.h>#include <tchar.h>// project's headers#include "Assert.h"#include "FiltCond.h"#include "Filter.h"#include "FilterSet.h"#include "FilterTools.h"#include "Language.h"#include "ProgPathDlg.h"#include "ProjectInfo.h"#include "Resources.h"#include "RuleDlg.h"#include "SpyServer.h"#include "Trace.h"/******************************************************************//* Internal constants *//******************************************************************/// column identifiers#define COL_PROGRAM 0#define COL_REASON 0#define COL_PARAM1 1#define COL_PARAM2 2#define COL_REACTION 3#define COL_VERBOSITY 4#define COL_OPTIONS 5// radio button height#define CY_RADIOBTN 20#define CX_TOOLBAR 40// window class name#define WC_FILTERWND TEXT("FilterWnd")// window messages#define WM_UPDATEPROGRAMLIST (WM_UPDATEFILTERS+1)#define WM_UPDATERULELIST (WM_UPDATEFILTERS+2)LPCTSTR g_szAddProgram = TEXT("Add program") ;LPCTSTR g_szEditProgram = TEXT("Edit program") ;LPCTSTR g_szRemoveProgram = TEXT("Remove program") ;LPCTSTR g_szAddRule = TEXT("Add rule") ;LPCTSTR g_szEditRule = TEXT("Edit rule") ;LPCTSTR g_szRemoveRule = TEXT("Remove rule") ;LPCTSTR g_szMoveUpRule = TEXT("Move up rule") ;LPCTSTR g_szMoveDownRule = TEXT("Move down rule") ;/******************************************************************//* Internal functions *//******************************************************************/LRESULT CALLBACK _FilterWnd_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ;DWORD WINAPI _FilterWnd_UpdateIconThread (VOID*) ;VOID _FilterWnd_UpdateRuleItem (HWND hwndList, PFILTRULE pRule) ;/******************************************************************//* Exported function : RegisterClass *//******************************************************************/BOOL FilterWnd_RegisterClass (HINSTANCE hInstance) { WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = _FilterWnd_WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = WC_FILTERWND ; return 0!=RegisterClass (&wndclass) ;}/******************************************************************//* Exported function : CreateWindow *//******************************************************************/HWND FilterWnd_CreateWindow (HINSTANCE hInstance, HWND hwndParent){ return CreateWindow (WC_FILTERWND, NULL, WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndParent, NULL, hInstance, NULL) ;}/******************************************************************//* Internal function : EnumRulesCallback *//******************************************************************/VOID _FilterWnd_EnumRulesCallback (LPVOID pContext, PFILTRULE pRule) { LVITEM lvi = { 0 } ; HWND hwndList = (HWND)pContext ; //TCHAR szBuffer[1024] ; ASSERT (pRule!=NULL) ; lvi.mask = LVIF_PARAM ; lvi.iItem = ListView_GetItemCount (hwndList) ; lvi.iSubItem = 0 ; lvi.lParam = (LPARAM)pRule ; ListView_InsertItem (hwndList, &lvi) ; _FilterWnd_UpdateRuleItem (hwndList, pRule) ;}/******************************************************************//* Internal function *//******************************************************************/VOID _FilterWnd_UpdateRuleItem (HWND hwndList, PFILTRULE pRule) { int i ; LVFINDINFO lvfi = { 0 } ; LVITEM lvi = { 0 } ; TCHAR szBuffer[1024] ; lvfi.flags = LVFI_PARAM ; lvfi.lParam = (LPARAM)pRule ; i = ListView_FindItem (hwndList,-1,&lvfi) ; if( i < 0 ) return ; FiltCond_GetReasonAsString (&pRule->condition, szBuffer, 64) ; lvi.mask = LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE ; lvi.iItem = i ; lvi.iSubItem = COL_REASON ; lvi.pszText = szBuffer ; lvi.iImage = pRule->condition.nReason ; lvi.lParam = (LPARAM)pRule ; ListView_SetItem (hwndList, &lvi) ; FiltCond_GetParamAsString (&pRule->condition, 0, szBuffer, 128) ; lvi.mask = LVIF_TEXT ; lvi.iSubItem = COL_PARAM1 ; lvi.pszText = szBuffer ; ListView_SetItem (hwndList, &lvi) ; FiltCond_GetParamAsString (&pRule->condition, 1, szBuffer, 128) ; lvi.mask = LVIF_TEXT ; lvi.iSubItem = COL_PARAM2 ; lvi.pszText = szBuffer ; ListView_SetItem (hwndList, &lvi) ; // reaction FiltRule_GetReactionString (pRule, szBuffer, 64) ; lvi.mask = LVIF_TEXT ; lvi.iSubItem = COL_REACTION ; lvi.pszText = szBuffer ; ListView_SetItem (hwndList, &lvi) ; // verbosity FiltRule_GetVerbosityString (pRule, szBuffer, 64) ; lvi.mask = LVIF_TEXT ; lvi.iSubItem = COL_VERBOSITY ; lvi.pszText = szBuffer ; ListView_SetItem (hwndList, &lvi) ; // options FiltRule_GetOptionsString (pRule, szBuffer, 64) ; lvi.mask = LVIF_TEXT ; lvi.iSubItem = COL_OPTIONS ; lvi.pszText = szBuffer ; ListView_SetItem (hwndList, &lvi) ;}/******************************************************************//* Internal function *//******************************************************************/VOID _FilterWnd_RemoveRuleItem (HWND hwndList, PFILTRULE pRule) { int i ; LVFINDINFO lvfi = { 0 } ; lvfi.flags = LVFI_PARAM ; lvfi.lParam = (LPARAM)pRule ; i = ListView_FindItem (hwndList,-1,&lvfi) ; if( i < 0 ) return ; ListView_DeleteItem (hwndList, i) ;}/******************************************************************//* Internal function *//******************************************************************/VOID _FilterWnd_UpdateProgramItem (HWND hwndList, HFILTER hFilter){ LVFINDINFO lvfi = { 0 } ; LVITEM lvi ; HANDLE hThread ; DWORD dwThreadId ; int i ; lvfi.flags = LVFI_PARAM ; lvfi.lParam = (LPARAM)hFilter ; i = ListView_FindItem (hwndList,-1,&lvfi) ; if( i < 0 ) return ; ZeroMemory (&lvi, sizeof(lvi)) ; lvi.mask = LVIF_TEXT|LVIF_IMAGE ; lvi.iItem = i ; lvi.iImage = -1 ; lvi.pszText = (TCHAR*)Filter_GetProgram(hFilter) ; ListView_SetItem (hwndList, &lvi) ; hThread = CreateThread (NULL, 0, _FilterWnd_UpdateIconThread, hwndList, 0, &dwThreadId) ; CloseHandle (hThread) ;}/******************************************************************//* Internal function *//******************************************************************/VOID _FilterWnd_RemoveProgramItem (HWND hwndList, HFILTER hFilter){ LVFINDINFO lvfi = { 0 } ; int i ; lvfi.flags = LVFI_PARAM ; lvfi.lParam = (LPARAM)hFilter ; i = ListView_FindItem (hwndList,-1,&lvfi) ; if( i < 0 ) return ; ListView_DeleteItem (hwndList, i) ;}/******************************************************************//* Internal function : WndProc *//******************************************************************/LRESULT CALLBACK _FilterWnd_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ static HWND g_hwndPrograms ; static HWND g_hwndRules ; static HWND g_hwndEnableHook ; static HWND g_hwndDisableHook ; static HWND g_hwndProgTools ; static HWND g_hwndRulesTools ; static HINSTANCE g_hInstance ; static HMENU g_hmenuPrograms ; static HMENU g_hmenuRules ; static HFILTER g_hfltCurrent ; static FILTRULE *g_pCurRule ; TCHAR szBuffer[1024] ; int nWidth, nHeight ; POINT point ; HFILTERSET hFilterSet ; //HFILTER hFilter ; LVCOLUMN lvc ; HIMAGELIST hImageList ; TBBUTTON tbb ; union { NMHDR *header ; NMITEMACTIVATE *itemactivate ; NMLISTVIEW *listview ; NMTTDISPINFO *getdispinfo ; NMLVKEYDOWN *keydown ; } pnm ; switch (message) { case WM_CREATE: g_hfltCurrent = NULL ; g_pCurRule = NULL ; g_hInstance = ((CREATESTRUCT*)lParam)->hInstance ; g_hwndPrograms = CreateWindowEx (WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT|LVS_SINGLESEL| LVS_SHOWSELALWAYS|LVS_NOSORTHEADER, 0,0,0,0, hwnd, (HMENU)IDC_PROGRAMLIST, g_hInstance, NULL) ; ListView_SetExtendedListViewStyle (g_hwndPrograms, LVS_EX_FULLROWSELECT) ; g_hwndProgTools = CreateWindow (TOOLBARCLASSNAME, NULL, WS_CHILD|WS_VISIBLE|CCS_NORESIZE|CCS_NOPARENTALIGN| TBSTYLE_WRAPABLE|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT, 0,0,0,0, hwnd, NULL, g_hInstance, NULL) ; SendMessage (g_hwndProgTools, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); g_hwndRules = CreateWindowEx (WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT| LVS_SINGLESEL|LVS_SHOWSELALWAYS|LVS_NOSORTHEADER, 0,0,0,0, hwnd, (HMENU)IDC_RULELIST, g_hInstance, NULL) ; ListView_SetExtendedListViewStyle (g_hwndRules, LVS_EX_FULLROWSELECT) ; g_hwndRulesTools = CreateWindow (TOOLBARCLASSNAME, NULL, WS_CHILD|WS_VISIBLE|CCS_NORESIZE|CCS_NOPARENTALIGN| TBSTYLE_WRAPABLE|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT, 0,0,0,0, hwnd, NULL, g_hInstance, NULL) ; SendMessage (g_hwndRulesTools, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); g_hwndEnableHook = CreateWindow (WC_BUTTON, NULL, WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON, 0,0,0,0, hwnd, (HMENU)IDC_ENABLE_HOOK, g_hInstance, NULL) ; SendMessage (g_hwndEnableHook, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0) ; g_hwndDisableHook = CreateWindow (WC_BUTTON, NULL, WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON, 0,0,0,0, hwnd, (HMENU)IDC_DISABLE_HOOK, g_hInstance, NULL) ; SendMessage (g_hwndDisableHook, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0) ; // // Init image list for filter list // hImageList = ImageList_Create (16,16,ILC_COLOR32,16,8) ; ListView_SetImageList (g_hwndPrograms, hImageList, LVSIL_SMALL) ; // // Init image list for rules window // hImageList = ImageList_Create (16,16,ILC_COLOR32|ILC_MASK,6,4) ; ImageList_AddIcon (hImageList, LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_UNKNOWN))) ; ImageList_AddIcon (hImageList, LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_REASON_FILE_READ))) ; ImageList_AddIcon (hImageList, LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_REASON_FILE_WRITE))) ; ImageList_AddIcon (hImageList, LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_REASON_NET_CONNECT))) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -