Пример #1
0
        private IntPtr HookProcedure(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(Win32.Functions.CallNextHookEx(hook_id, nCode, wParam, lParam));
            }

            Win32.CWPRETSTRUCT msg = (Win32.CWPRETSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.CWPRETSTRUCT));

            //filter out create window events only
            //if (msg.message == (uint)Win32.Messages.WM_SHOWWINDOW)
            //{
            //    int h = Win32.Functions.GetWindow(msg.hwnd, Win32.Functions.GW_OWNER);
            //    //check if owner is that is specified
            //    if (owner_window == IntPtr.Zero || owner_window == new IntPtr(h))
            //    {
            //        if (process_window != null)
            //            process_window(msg.hwnd);
            //    }
            //}

            if (msg.message == (uint)Win32.Messages.WM_KILLFOCUS)
            {
                Console.WriteLine("Killed focus");
                //Win32.Functions.SendMessage(hook_id, (uint)Win32.Messages.WM_SETFOCUS, 0, 0);
            }
            else if (msg.message == (uint)Win32.Messages.WM_SETFOCUS)
            {
                Console.WriteLine("Gained focus");
            }

            return(Win32.Functions.CallNextHookEx(hook_id, nCode, wParam, lParam));
        }
        static private IntPtr wnd_hook_proc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            lock (static_lock_variable)
            {
                try
                {
                    if (nCode < 0)
                    {
                        return(Win32.Functions.CallNextHookEx(hook_id, nCode, wParam, lParam));
                    }

                    Win32.CWPRETSTRUCT msg = (Win32.CWPRETSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.CWPRETSTRUCT));

                    if (msg.message == (uint)Win32.Messages.WM_SHOWWINDOW)
                    {
                        //check if owner is that was specified
                        IntPtr h = new IntPtr(Win32.Functions.GetWindow(msg.hwnd, Win32.Functions.GW_OWNER));
                        foreach (IntPtr owner_window in owner_windows)
                        {
                            if (owner_window != h)
                            {
                                StringBuilder text2 = new StringBuilder(255);
                                Win32.Functions.GetWindowText(h, text2, 255);
                                if (!text2.ToString().Contains("WindowsFormsParkingWindow"))
                                {
                                    continue;
                                }
                            }

                            StringBuilder text = new StringBuilder(255);
                            Win32.Functions.GetWindowText(msg.hwnd, text, 255);
                            owner_window_logs[owner_window].Write("Intercepted dialog box: " + text.ToString());

                            //short dw = (short)Win32.Functions.SendMessage(msg.hwnd, (uint)Win32.Messages.DM_GETDEFID, 0, 0);
                            //Win32.Functions.EndDialog(msg.hwnd, (IntPtr)dw);
                            Win32.Functions.SendMessage(msg.hwnd, (uint)Win32.Messages.WM_CLOSE, 0, 0);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Main.Exit(e);
                }

                return(Win32.Functions.CallNextHookEx(hook_id, nCode, wParam, lParam));
            }
        }