Beispiel #1
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));
        }
Beispiel #2
0
        private void PostWindowHookProc(PostWindowHookMessage msg)
        {
            if (msg.nCode != User.Const.HC_ACTION) return;

            if (msg.wm == User.WM.WM_ACTIVATE || msg.wm == User.WM.WM_SYSCOMMAND)
            {
                WindowData window = FindWindow(msg.msg.hwnd);
                string sWindow = "not found";
                if (window != null) sWindow = window.Form.Text;

                short low = msg.msg.wParam.zGetLowValue();

                string swParam = null;
                if (msg.wm == User.WM.WM_ACTIVATE)
                {
                    User.WA wa = Messages.GetWA(low);
                    swParam = wa.ToString();
                    if (wa == User.WA.WA_UNKNOW) swParam += " (" + low.ToString("x") + ")";
                }
                else if (msg.wm == User.WM.WM_SYSCOMMAND)
                {
                    User.SC sc = Messages.GetSC((int)msg.msg.wParam);
                    swParam = sc.ToString();
                    if (sc == User.SC.SC_UNKNOW) swParam += " (" + ((int)msg.msg.wParam).ToString("x") + ")";
                }
                if (gbTrace)
                    pb.Trace.WriteLine("PostWindowHookProc                : {0,-20} {1,-20} window {2,-25} hWnd {3}", msg.wm, swParam, sWindow, (int)msg.msg.hwnd);
            }
        }
Beispiel #3
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.CurrentTrace.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);
        }