just alpha test……
// KBFilter.cpp : Defines the entry point for the application.
//
#include “stdafx.h”
#include “KBFilter.h”
#define MAX_LOADSTRING 100
// GetDllVersion要用到的一个宏
#define PACKVERSION(major,minor) MAKELONG(minor,major)
#define TRAYICONID 1
#define SWM_TRAYMSG WM_APP
#define SWM_SHOW WM_APP + 1
#define SWM_HIDE WM_APP + 2
#define SWM_EXIT WM_APP + 3
#define SWM_ABOUT WM_APP + 4
#define SWM_KALL WM_APP + 5
#define SWM_KLWIN WM_APP + 6
#define SWM_KRWIN WM_APP + 7
#define SWM_KDOC WM_APP + 8
#define SWM_CALL WM_APP + 9
#define SWM_CSTI WM_APP + 10
#define SWM_CTOG WM_APP + 11
#define SWM_CFIL WM_APP + 12
// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                    // The title bar text
TCHAR szINI[256];                                // Ini file path
TCHAR szApp[260];                                // App to launch
HANDLE hThread;
HHOOK g_hKeyboardHook;                            // 全局键盘钩子
STICKYKEYS g_StartupStickyKeys = {
TOGGLEKEYS g_StartupToggleKeys = {
FILTERKEYS g_StartupFilterKeys = {
NOTIFYICONDATA stNID;                            // 托盘图标所要结构
bool g_bAutoExit;
// 保存几个屏蔽状态的bool变量
bool g_bLWin;
bool g_bRWin;
bool g_bDoc;
bool g_bSti;
bool g_bTog;
bool g_bFil;
// Forward declarations of functions included in this code module:
DWORD    GetDllVersion(LPCTSTR);
LRESULT CALLBACK    DlgProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK    LowLevelKeyboardProc(int, WPARAM, LPARAM);
void    AllowAccessibilityShortcutKeysS(bool);
void    AllowAccessibilityShortcutKeysT(bool);
void    AllowAccessibilityShortcutKeysF(bool);
void    ShowContextMenu(HWND);
void    UpdateToolTip();
void    UpdateAccKeys();
void    OnSelectApp(HWND);
void    RunApp(HWND);
VOID WINAPI OnMeasureItem(HWND, LPMEASUREITEMSTRUCT);
VOID WINAPI OnDrawItem(HWND, LPDRAWITEMSTRUCT);
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
     // TODO: Place code here.
    MSG msg;
    hInst = hInstance;
    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    // 初始化,从INI文件中读取设置
    GetCurrentDirectory(
    lstrcat(szINI,_T(“\\Config.ini“));
    GetPrivateProfileString(_T(“AUTORUN“),_T(“APP“),_T(““),szApp,
    g_bAutoExit = GetPrivateProfileInt(_T(“AUTORUN“),_T(“AUTOEXIT“),1,szINI)==1?
    //TCHAR szBuf[20];
    //RtlZeroMemory(&szBuf,sizeof(szBuf)/sizeof(TCHAR));
    g_bLWin = GetPrivateProfileInt(_T(“KEYS“),_T(“LWIN“),1,szINI)==1?
    g_bRWin = GetPrivateProfileInt(_T(“KEYS“),_T(“RWIN“),1,szINI)==1?
    g_bDoc = GetPrivateProfileInt(_T(“KEYS“),_T(“DOC“),1,szINI)==1?
    g_bFil = GetPrivateProfileInt(_T(“ACCS“),_T(“FIL“),1,szINI)==1?
    g_bSti = GetPrivateProfileInt(_T(“ACCS“),_T(“STI“),1,szINI)==1?
    g_bTog = GetPrivateProfileInt(_T(“ACCS“),_T(“TOG“),1,szINI)==1?
    // Save the current sticky/toggle/filter key settings so they can be restored them later
    SystemParametersInfo(SPI_GETSTICKYKEYS,
    SystemParametersInfo(SPI_GETTOGGLEKEYS,
    SystemParametersInfo(SPI_GETFILTERKEYS,
    // Perform application initialization:
    InitCommonControls();
    // 挂钩键盘
    g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,  LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );
    UpdateAccKeys();
    // 创建对话框但不显示,做接受托盘图标事件和设置用
    HWND hDlg = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOGMAIN),NULL,(DLGPROC)DlgProc);
    ZeroMemory(&stNID,
    ULONGLONG ullVersion = GetDllVersion(_T(“Shell32.dll“));
        stNID.cbSize =
        stNID.cbSize = NOTIFYICONDATA_V2_SIZE;
    stNID.hWnd = hDlg;
    stNID.uID = TRAYICONID;
    stNID.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
    stNID.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_KBFILTER));
    stNID.uCallbackMessage = SWM_TRAYMSG;
    //lstrcpyn(stNID.szTip, _T(“Time flies like an arrow but\n fruit flies like a banana!”), sizeof(stNID.szTip)/sizeof(TCHAR));
    Shell_NotifyIcon(NIM_ADD,&stNID);
    UpdateToolTip();
    //(int)DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOGMAIN),NULL,(DLGPROC)DlgProc);
    // Main message loop:
    {
        //if (!IsDialogMessage(msg.hwnd,&msg))
        //{
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        //}
    }
    // free icon handle如果在消息循环前des的话,后面修改会导致图标消失
        stNID.hIcon = NULL;
    WritePrivateProfileString(_T(“KEYS“),_T(“LWIN“),g_bLWin?_T(“1“):_T(“0“),szINI);
    WritePrivateProfileString(_T(“KEYS“),_T(“RWIN“),g_bRWin?_T(“1“):_T(“0“),szINI);
    WritePrivateProfileString(_T(“KEYS“),_T(“DOC“),g_bDoc?_T(“1“):_T(“0“),szINI);
    WritePrivateProfileString(_T(“ACCS“),_T(“STI“),g_bSti?_T(“1“):_T(“0“),szINI);
    WritePrivateProfileString(_T(“ACCS“),_T(“FIL“),g_bFil?_T(“1“):_T(“0“),szINI);
    WritePrivateProfileString(_T(“ACCS“),_T(“TOG“),g_bTog?_T(“1“):_T(“0“),szINI);
    // 还原辅助功能屏蔽
    g_bSti =
    g_bTog =
    g_bFil =
    UpdateAccKeys();
    // 卸载钩子
    UnhookWindowsHookEx(g_hKeyboardHook);
}
DWORD GetDllVersion(LPCTSTR lpszDllName)
{
    HINSTANCE hinstDll;
    DWORD dwVersion = 0;
    /* For security purposes, LoadLibrary should be provided with a
fully-qualified path to the DLL. The lpszDllName variable should be
tested to ensure that it is a fully qualified path before it is used. */
    hinstDll = LoadLibrary(lpszDllName);
    {
        DLLGETVERSIONPROC pDllGetVersion;
        pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll,“DllGetVersion“);
        /* Because some DLLs might not implement this function, you
must test for it explicitly. Depending on the particular
DLL, the lack of a DllGetVersion function can be a useful
indicator of the version. */
        {
            DLLVERSIONINFO dvi;
            HRESULT hr;
            ZeroMemory(&dvi,
            dvi.cbSize =
            hr = (*pDllGetVersion)(&dvi);
            {
                dwVersion = PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion);
            }
        }
        FreeLibrary(hinstDll);
    }
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main dialog window.
//
//
LRESULT CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    {
    case WM_INITDIALOG:
        SetWindowText(hDlg,szTitle);
        SendMessage(hDlg,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_KBFILTER)));
        SendMessage(hDlg,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_KBFILTER)));
        SetDlgItemText(hDlg,IDC_APP,szApp);
        {
            SendMessage(GetDlgItem(hDlg,IDC_AUTOEXIT),BM_SETCHECK,BST_CHECKED,NULL);
        }
        RunApp(hDlg);
    case SWM_TRAYMSG:
        {
        case WM_LBUTTONDOWN:
            {
                ShowWindow(hDlg, SW_HIDE);
            }
            {
                ShowWindow(hDlg, SW_RESTORE);
            }
        case WM_RBUTTONDOWN:
        case WM_CONTEXTMENU:
            ShowContextMenu(hDlg);
        }
    case WM_MEASUREITEM:
        OnMeasureItem(hDlg, (LPMEASUREITEMSTRUCT) lParam);
    case WM_DRAWITEM:
        OnDrawItem(hDlg, (LPDRAWITEMSTRUCT) lParam);
/*
case WM_MENUCHAR:
//TCHAR chKey = LOWORD(wParam);
return MAKELRESULT(1, MNC_EXECUTE);
break;*/
    case WM_COMMAND:
        {
        case IDC_SELECT:
            OnSelectApp(hDlg);
        case IDC_RUNNOW:
            RunApp(hDlg);
        case IDOK:
            // 为了防止特殊情况还要再get一次
            GetDlgItemText(hDlg,IDC_APP,szApp,
            WritePrivateProfileString(_T(“AUTORUN“),_T(“APP“),szApp,szINI);
            {
                g_bAutoExit =
                WritePrivateProfileString(_T(“AUTORUN“),_T(“AUTOEXIT“),_T(“1“),szINI);
            }
            {
                g_bAutoExit =
                WritePrivateProfileString(_T(“AUTORUN“),_T(“AUTOEXIT“),_T(“0“),szINI);
            }
            MessageBox(hDlg,_T(“保存成功!“),_T(“消息“),MB_ICONINFORMATION);
        case IDCANCEL:
            ShowWindow(hDlg,SW_HIDE);
        }
    case WM_SYSCOMMAND:
        {
            ShowWindow(hDlg, SW_HIDE);
        }
    case WM_CLOSE:
        // 关闭设置窗口并不结束程序
        ShowWindow(hDlg,SW_HIDE);
        //DestroyWindow(hDlg);
    case WM_DESTROY:
        stNID.uFlags = 0;
        Shell_NotifyIcon(NIM_DELETE,&stNID);
        PostQuitMessage(0);
    }
}
VOID WINAPI OnMeasureItem(HWND hwnd, LPMEASUREITEMSTRUCT lpmis)
{
    // 根据文字设定DC长宽
    //TCHAR szText[0x10];
    //lstrcpy(szText,(TCHAR*)lpmis->itemData);
    HDC hdc = GetDC(hwnd);
    SIZE size;
    GetTextExtentPoint32(hdc, (TCHAR*)lpmis–>itemData,lstrlen((TCHAR*)lpmis–>itemData),&size);
    //if(lstrcmp(szText,_T(“-“))==0)
    {
        lpmis–>itemHeight = size.cy–2;
        lpmis–>itemWidth = size.cx;
    }
    {
        lpmis–>itemHeight = size.cy+6;
        lpmis–>itemWidth = size.cx+5;
    }
}
VOID WINAPI OnDrawItem(HWND hwnd, LPDRAWITEMSTRUCT lpdis)
{
    // 保存以前的文字前背景色
    COLORREF clrPrevText,clrPrevBkgnd;
    // 处理文字坐标变量
    int x,y;
    // Set the appropriate foreground and background colors.
    {
        // 创建新笔刷,并保存原设置
        HBRUSH hbrush, hbrushOld;
        HPEN hpen, hpenOld;
        // Create a pen.
        hpen = CreatePen(PS_SOLID, 1, RGB(0,110,233));
        // Create a brush.
        hbrush = CreateSolidBrush(RGB(200,221,255));
        // Select the new pen and brush, and then draw.
        hpenOld = (HPEN)SelectObject(lpdis–>hDC, hpen);
        hbrushOld = (HBRUSH)SelectObject(lpdis–>hDC,hbrush);
        // 画出带边框的矩形
        Rectangle(lpdis–>hDC, lpdis–>rcItem.left,lpdis–>rcItem.top,lpdis–>rcItem.right,lpdis–>rcItem.bottom);
        // Do not forget to clean up.
        SelectObject(lpdis–>hDC, hpenOld);
        DeleteObject(hpen);
        SelectObject(lpdis–>hDC, hbrushOld);
        DeleteObject(hbrush);
        // 设置文字前背景色
        clrPrevText = SetTextColor(lpdis–>hDC,RGB(0, 0, 0));
        clrPrevBkgnd = SetBkColor(lpdis–>hDC,RGB(200,221,255));
        //clrPrevText = SetTextColor(lpdis->hDC,GetSysColor(COLOR_MENUTEXT));
        //clrPrevText = SetTextColor(lpdis->hDC,GetSysColor(COLOR_HIGHLIGHTTEXT));
        //clrPrevBkgnd = SetBkColor(lpdis->hDC,GetSysColor(COLOR_HIGHLIGHT));
    }
    {
        // draw the left gray part first
        HBRUSH hbrush, hbrushOld;
        // Create a brush.
        hbrush = CreateSolidBrush(RGB(236,233,217));
        // Select the new pen and brush, and then draw.
        hbrushOld = (HBRUSH)SelectObject(lpdis–>hDC,hbrush);
        __asm
        {
            push esi
            push ebx
            mov esi,
            lea ebx,[esi]lpdis.
            push [ebx]RECT.
            push ebx
        }
        lpdis–>rcItem.right = lpdis–>rcItem.left+GetSystemMetrics(SM_CXMENUCHECK)+9;
        FillRect(lpdis–>hDC,&lpdis–>rcItem,hbrush);
        __asm pop ebx
        __asm pop [ebx]RECT.
        __asm push [ebx]RECT.
        __asm push ebx
        lpdis–>rcItem.left += GetSystemMetrics(SM_CXMENUCHECK)+9;
        FillRect(lpdis–>hDC,&lpdis–>rcItem,(HBRUSH)(COLOR_WINDOW+1));
        __asm
        {
            pop ebx
            pop [ebx]RECT.
            pop ebx
            pop esi
        }
        // Do not forget to clean up.
        SelectObject(lpdis–>hDC, hbrushOld);
        DeleteObject(hbrush);
        clrPrevText = SetTextColor(lpdis–>hDC,GetSysColor(COLOR_MENUTEXT));
        clrPrevBkgnd = SetBkColor(lpdis–>hDC,RGB(255, 255, 255));
        //clrPrevBkgnd = SetBkColor(lpdis->hDC,GetSysColor(COLOR_MENU));
    }
    // Determine where to draw and leave space for a check mark.
    x = lpdis–>rcItem.left;
    y = lpdis–>rcItem.top;
    x += GetSystemMetrics(SM_CXMENUCHECK)+
博主友情提示:
如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。