示例#1
0
        private int _HookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && (HookEvent != null || gbTrace))
            {
                User.Struct.MSG msg = (User.Struct.MSG)Marshal.PtrToStructure(lParam, typeof(User.Struct.MSG));
                User.WM         wm  = Messages.GetWindowMessage((int)msg.message);

                if (gbTrace)
                {
                    string sMessage = wm.ToString();
                    if (wm == User.WM.WM_UNKNOW)
                    {
                        sMessage += " (" + msg.message.ToString("x") + ")";
                    }
                    string sCode; if (nCode == User.Const.HC_ACTION)
                    {
                        sCode = "HC_ACTION";
                    }
                    else
                    {
                        sCode = nCode.ToString();
                    }
                    pb.Trace.WriteLine("GetMessageWindowHook                           : {0,-20} {1,-11} wParam {2,-8:x} wParam {3,-8:x} lParam {4,-8:x} hwnd {5:x}", sMessage, sCode, (int)wParam, (int)msg.wParam, (int)msg.lParam, (int)msg.hwnd);
                }

                if (HookEvent != null)
                {
                    GetMessageWindowHookMessage msg2 = new GetMessageWindowHookMessage()
                    {
                        nCode = nCode, wParam = wParam, lParam = lParam, msg = msg, wm = wm
                    };
                    HookEvent(msg2);
                    if (msg2.RemoveMessage)
                    {
                        return(0);
                    }
                }
            }
            return(User.CallNextHookEx(gHookHandle, nCode, wParam, lParam));
        }
示例#2
0
        private int _HookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && (HookEvent != null || gbTrace))
            {
                User.Struct.CWPRETSTRUCT cwp = (User.Struct.CWPRETSTRUCT)Marshal.PtrToStructure(lParam, typeof(User.Struct.CWPRETSTRUCT));
                User.WM message = Messages.GetWindowMessage(cwp.message);

                if (gbTrace)
                {
                    string sMessage = message.ToString();
                    if (message == User.WM.WM_UNKNOW)
                    {
                        sMessage += " (" + cwp.message.ToString("x") + ")";
                    }
                    string sCode; if (nCode == User.Const.HC_ACTION)
                    {
                        sCode = "HC_ACTION";
                    }
                    else
                    {
                        sCode = nCode.ToString();
                    }
                    pb.Trace.WriteLine("PostWindowHook                                 : {0,-20} {1,-11} wParam {2,-8:x} wParam {3,-8:x} lParam {4,-8:x} lResult {5,-8:x} hwnd {6:x}", sMessage, sCode, (int)wParam, (int)cwp.wParam, (int)cwp.lParam, (int)cwp.lResult, (int)cwp.hwnd);
                }

                if (HookEvent != null)
                {
                    PostWindowHookMessage msg = new PostWindowHookMessage()
                    {
                        nCode = nCode, wParam = wParam, lParam = lParam, msg = cwp, wm = message
                    };
                    HookEvent(msg);
                    //if (msg.RemoveMessage) return 1;
                }
            }
            return(User.CallNextHookEx(gHookHandle, nCode, wParam, lParam));
        }