Esempio n. 1
0
        // OnEventSystemCaptureEnd - process an EventSystemCaptureEnd WinEvent.
        private void OnEventSystemCaptureEnd(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
        {
            // Deal only with Combolbox dropdowns...
            if (Accessible.IsComboDropdown(hwnd))
            {
                SafeNativeMethods.GUITHREADINFO guiThreadInfo = new SafeNativeMethods.GUITHREADINFO();

                if (!Misc.GetGUIThreadInfo(0, ref guiThreadInfo))
                {
                    return;
                }

                Accessible acc = Accessible.Create(guiThreadInfo.hwndFocus, UnsafeNativeMethods.OBJID_CLIENT, 0);
                if (acc == null)
                {
                    return;
                }

                HandleFocusChange(hwnd, acc, idObject, idChild, eventTime);
            }
        }
Esempio n. 2
0
        internal static bool GetGUIThreadInfo(int idThread, ref SafeNativeMethods.GUITHREADINFO guiThreadInfo)
        {
            guiThreadInfo.cbSize = Marshal.SizeOf(guiThreadInfo);

            bool result         = SafeNativeMethods.GetGUIThreadInfo(0, ref guiThreadInfo);
            int  lastWin32Error = Marshal.GetLastWin32Error();

            if (!result)
            {
                // If the focused thread is on another [secure] desktop, GetGUIThreadInfo
                // will fail with ERROR_ACCESS_DENIED - don't throw an exception for that case,
                // instead treat as a failure. Callers will treat this as though no window has
                // focus.
                if (lastWin32Error == 5 /*ERROR_ACCESS_DENIED*/)
                {
                    return(false);
                }

                ThrowWin32ExceptionsIfError(lastWin32Error);
            }

            return(result);
        }