Exemple #1
0
 private void OnNewWin32Msg(IntPtr hIEWnd, Win32HookMsgEventArgs.HookMsgType type)
 {
     if (Win32HookMsg != null)
     {
         Win32HookMsg(this, new Win32HookMsgEventArgs(hIEWnd, type));
     }
 }
Exemple #2
0
        private int GetMsgHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
            else
            {
                GetMsgHookStruct msgStruct = (GetMsgHookStruct)Marshal.PtrToStructure(lParam, typeof(GetMsgHookStruct));

                switch (msgStruct.message)
                {
                case Win32Api.WM_LBUTTONUP:
                case Win32Api.WM_LBUTTONDOWN:
                case Win32Api.WM_RBUTTONDOWN:
                {
                    // With WH_GETMESSAGE hooks, it's very important to check for WPARAM equal to PM_REMOVE
                    // because otherwise you may end up processing the event twice. Windows calls your WH_GETMESSAGE
                    // hook whenever the app calls ::GetMessage or ::PeekMessage. Many apps call ::PeekMessage to check
                    // for messages before fetching them, in order to do idle processing between messages. When the
                    // app calls ::PeekMessage, Windows calls your hook with WPARAM set to PM_NOREMOVE.
                    if (wParam.ToInt32() == Win32Api.PM_REMOVE)
                    {
                        if (Win32Api.IsIEServerOrChild(msgStruct.hwnd))
                        {
                            //System.Diagnostics.Trace.WriteLine("OnNewWin32Msg event rised for " + msgStruct.message + " on " + msgStruct.hwnd);
                            Win32HookMsgEventArgs.HookMsgType msgType = GetMsgType(msgStruct.message);
                            OnNewWin32Msg(msgStruct.hwnd, msgType);
                        }
                    }

                    break;
                }

                case Win32Api.WM_KEYDOWN:
                {
                    if (wParam.ToInt32() == Win32Api.PM_REMOVE)
                    {
                        if (Win32Api.IsIEServerOrChild(msgStruct.hwnd))
                        {
                            OnNewWin32Msg(msgStruct.hwnd, Win32HookMsgEventArgs.HookMsgType.KEY_PRESSED_MSG);
                        }
                    }

                    break;
                }
                }

                return(Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam));
            }
        }