• 大小: 245KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: 其他
  • 标签: HOOK  

资源简介

如何HOOK桌面窗口消息. 截获桌面窗口鼠标单击事件,解析所选中的桌面 Item,并将解析后的 item 信息发送给主调程序,并将信息显示在一个窗口上面

资源截图

代码片段和文件信息

#include “CommonDef.h“
#include “DesktopHook.h“
#include “FloatWin.h“

const UINT WM_DESKTOP_CLICKED_ITEM = RegisterWindowMessage(L“WM_DESKTOP_CLICKED_ITEM“);

BOOL g_isCaptured = FALSE;
CFloatWin* g_floatWin = NULL;

INT_PTR WINAPI DlgProc(HWND hwnd UINT uMsg WPARAM wParam LPARAM lParam) ;

int WINAPI _tWinMain(HINSTANCE hinstExe HINSTANCE PTSTR pszCmdLine int)
{
    HWND hwnd = FindWindow(TEXT(“#32770“) TEXT(“DesktopCaptor2“));
    if (IsWindow(hwnd))
    {
        // An instance is already running show a messagebox
        MessageBox(GetForegroundWindow() L“An instance is already running“ L“Error“ MB_IConerror);
    } 
    else 
    {
        DialogBox(hinstExe MAKEINTRESOURCE(IDD_DESKTOP_CAPTOR) NULL DlgProc);
    }
    return(0);
}

INT_PTR CALLBACK DlgProc(HWND hDlg UINT message WPARAM wParam LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        {
            // Set icon for the application
            SendMessage(hDlg WM_SETICON ICON_BIG  (LPARAM) 
                LoadIcon((HINSTANCE) GetWindowLongPtr(hDlg GWLP_HINSTANCE) 
                MAKEINTRESOURCE(IDI_DESKTOPCAPTOR2)));

            // Set dialog‘s position
            int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
            int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
            RECT rect = { 0 };
            GetWindowRect(hDlg &rect);
            SetWindowPos(
                hDlg 
                HWND_TOP 
                nScreenWidth - (rect.right - rect.left) 
                0 
                0 0 
                SWP_NOSIZE);

            g_floatWin = CFloatWin::getInstance();
        }
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        {
            UINT wmId = LOWORD(wParam);
            UINT wmEvent = HIWORD(wParam);

            switch (wmId)
            {
            case IDOK:
            case IDCANCEL:
                EndDialog(hDlg LOWORD(wParam));
                return (INT_PTR)TRUE;
            case IDC_START_CAPTOR:
                if (FALSE == g_isCaptured)
                {
                    g_isCaptured = CreateDesktopEventCaptor(hDlg);
                }
                break;
            case IDC_STOP_CAPTOR:
                if (TRUE == g_isCaptured)
                {
                    CloseDesktopEventCaptor();
                    g_isCaptured = FALSE;
                }
                break;
            default:
                return DefWindowProc(hDlg message wParam lParam);
            }
        }
        break;
    case WM_COPYDATA:
        {
            COPYDATASTRUCT* pCopyData = (COPYDATASTRUCT*)lParam;
            if (pCopyData->dwData == WM_DESKTOP_CLICKED_ITEM)
            {
                DesktopItemData itemData(*(DesktopItemData*)pCopyData->lpData);
                g_floatWin->ShowWindow(TRUE &itemData);
            }
        }
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-07-17 01:57  DesktopCaptor\
     目录           0  2011-07-17 01:57  DesktopCaptor\Debug\
     文件      199168  2011-07-17 01:56  DesktopCaptor\Debug\DesktopCaptor2.exe
     文件       53760  2011-07-17 01:56  DesktopCaptor\Debug\DesktopHook.dll
     文件        1534  2011-07-15 17:13  DesktopCaptor\DesktopCaptor.sln
     文件        8192  2011-07-17 01:57  DesktopCaptor\DesktopCaptor.suo
     目录           0  2011-07-17 01:57  DesktopCaptor\DesktopCaptor2\
     文件        1309  2011-07-11 04:28  DesktopCaptor\DesktopCaptor2\CommonDef.h
     文件        3046  2011-07-15 17:16  DesktopCaptor\DesktopCaptor2\DesktopCaptor2.cpp
     文件      127493  2009-06-23 14:57  DesktopCaptor\DesktopCaptor2\DesktopCaptor2.ico
     文件        2952  2011-07-11 05:28  DesktopCaptor\DesktopCaptor2\DesktopCaptor2.rc
     文件        4399  2011-07-11 05:28  DesktopCaptor\DesktopCaptor2\DesktopCaptor2.vcproj
     文件        3107  2011-07-11 07:38  DesktopCaptor\DesktopCaptor2\FloatWin.cpp
     文件         581  2011-07-11 07:39  DesktopCaptor\DesktopCaptor2\FloatWin.h
     文件         595  2011-07-11 05:22  DesktopCaptor\DesktopCaptor2\resource.h
     目录           0  2011-07-17 01:57  DesktopCaptor\DesktopHook\
     文件        6201  2011-07-17 00:13  DesktopCaptor\DesktopHook\DesktopHook.cpp
     文件         143  2011-07-10 19:49  DesktopCaptor\DesktopHook\DesktopHook.def
     文件        1754  2011-07-15 17:21  DesktopCaptor\DesktopHook\DesktopHook.h
     文件        5324  2011-07-15 18:09  DesktopCaptor\DesktopHook\DesktopHook.vcproj
     文件        2530  2011-07-15 18:09  DesktopCaptor\DesktopHook\DesktopItem.cpp
     文件         978  2011-07-11 02:07  DesktopCaptor\DesktopHook\DesktopItem.h
     文件         464  2011-07-10 20:29  DesktopCaptor\DesktopHook\dllmain.cpp
     文件        1779  2011-07-10 16:51  DesktopCaptor\DesktopHook\ReadMe.txt
     文件         298  2011-07-10 16:51  DesktopCaptor\DesktopHook\stdafx.cpp
     文件         664  2011-07-11 01:32  DesktopCaptor\DesktopHook\stdafx.h
     文件        1428  2011-07-10 16:51  DesktopCaptor\DesktopHook\targetver.h

评论

共有 条评论