标题:帮忙看看这段代码 为什么进不去钩子回调函数??
只看楼主
奥丁
Rank: 1
等 级:新手上路
帖 子:327
专家分:0
注 册:2006-10-18
结帖率:100%
 问题点数:0 回复次数:0 
帮忙看看这段代码 为什么进不去钩子回调函数??
程序代码:
#include <windows.h>
#include <stdio.h>
#pragma comment <lib, "User32.lib">
#include <winuser.h>

    WNDPROC g_orgProc;
LRESULT CALLBACK NewWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_COMMAND:
        if ((wParam == 0x06) && (HIWORD(wParam) == BN_CLICKED) )
        { 
            /*Add your own procedure*/
            return 0;
        } 
        break; 
    default:
        break;
    }
    return CallWindowProc(g_orgProc, hWnd, uMsg, wParam, lParam);
}

LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    WCHAR szText[256];
    WCHAR szWindowText[32];
    HWND hWnd, g_hWnd;
    bool bSetWindowLong;


    memset(szWindowText, NULL, sizeof(szWindowText));
    wcscpy(szWindowText, L"任务管理器警告");

    switch(nCode)
    {
    case HCBT_ACTIVATE:
        hWnd = (HWND)wParam;
        GetWindowText(hWnd,szText,256);
        if(wcscmp (szText, szWindowText) == 0)
        {
            if(!bSetWindowLong)
            {
                g_hWnd = hWnd;
                g_orgProc=(WNDPROC)SetWindowLong(hWnd,GWL_WNDPROC,(LONG)NewWndProc);
                bSetWindowLong = TRUE;
            }
        }
        break;
    case HCBT_DESTROYWND: 
        hWnd = (HWND)wParam;
        GetWindowText(hWnd,szText,256);
        if(wcscmp (szText, szWindowText) == 0)
        {
            SetWindowLong(g_hWnd,GWL_WNDPROC,(LONG)g_orgProc);
            g_hWnd = NULL;
            bSetWindowLong = false;
        }
        break;
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}//End of the hook procedure





int main()
{
    HWND g_hInstance = ::FindWindow(NULL,  L"Windows 任务管理器");

    HHOOK g_cbtHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, NULL, NULL);


}
搜索更多相关主题的帖子: 回调 函数 钩子 代码 
2008-08-22 13:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-229424-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012940 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved