AttachThreadInput возвращает 0 при передаче processId (idAttachTo) пограничного браузера - PullRequest
1 голос
/ 03 февраля 2020
static class Win32
        {
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public extern static bool DestroyIcon(IntPtr handle);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr GetForegroundWindow();
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern uint AttachThreadInput(uint thread, uint attachToThread, bool attach);
            [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
            public static extern uint GetCurrentThreadId();
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern uint BringWindowToTop(IntPtr hWnd);
        }

private void MakeMeActive()
        {
            uint activeProcess = Win32.GetWindowThreadProcessId(Win32.GetForegroundWindow(), IntPtr.Zero);
            uint thisThread = Win32.GetCurrentThreadId();
            if ( activeProcess != 0 )
            {
                uint isSuccess = Win32.AttachThreadInput(thisThread, activeProcess, true);
                Window window = Window.GetWindow(this);
                var wih = new WindowInteropHelper(window);
                IntPtr hWnd = wih.Handle;
                Win32.BringWindowToTop(hWnd);
                Win32.AttachThreadInput(thisThread, activeProcess, false);
            }
        }

Для приведенного выше кода uint isSuccess = Win32.AttachThreadInput(thisThread, activeProcess, true);

isSucess имеет значение false, что означает, что активный поток и активные процессы не присоединены. Это происходит только тогда, когда процесс является пограничным браузером и нормально работает для браузера chrome. Кто-нибудь может помочь с этим?

...