API GUITHREADINFO
예제 #1
0
        public void timer_Tick(object sender, EventArgs e)
        {
            timer.Enabled = false;

            IntPtr        hWnd = GetForegroundWindow();
            uint          processId;
            uint          threadid = GetWindowThreadProcessId(hWnd, out processId);
            GUITHREADINFO lpgui    = new GUITHREADINFO();

            lpgui.cbSize = Marshal.SizeOf(lpgui);

            if (GetGUIThreadInfo(threadid, ref lpgui))
            {
                if (lpgui.hwndCaret != 0)
                {
                    this.Opacity = 1;
                    //this.WindowState = WindowState.Normal;
                }
                else
                {
                    this.Opacity = 0;
                    // this.WindowState = WindowState.Minimized;
                }
            }

            timer.Enabled = true;
        }
예제 #2
0
파일: miscInfo.cs 프로젝트: qmgindi/Au
 /// <summary>
 /// Calls API <msdn>GetGUIThreadInfo</msdn>. It gets info about mouse capturing, menu mode, move/size mode, focus, caret, etc.
 /// </summary>
 /// <param name="g">API <msdn>GUITHREADINFO</msdn>.</param>
 /// <param name="idThread">Thread id. If 0 - the foreground (active window) thread. See <see cref="process.thisThreadId"/>, <see cref="wnd.ThreadId"/>.</param>
 public static unsafe bool getGUIThreadInfo(out GUITHREADINFO g, int idThread = 0)
 {
     g = new GUITHREADINFO {
         cbSize = sizeof(GUITHREADINFO)
     };
     return(Api.GetGUIThreadInfo(idThread, ref g));
 }
예제 #3
0
        /// <summary>
        /// Pastes some text via system clipboard using Ctrl+V shortcut on the foreground window.
        /// </summary>
        /// <param name="text">Text to paste.</param>
        public void Paste(string text)
        {
            var mainWin = NativeMethods.GetForegroundWindow();

            if (mainWin != IntPtr.Zero)
            {
                var itsThread  = NativeMethods.GetWindowThreadProcessId(mainWin, out uint _);
                var threadInfo = new GUITHREADINFO();
                threadInfo.cbSize = Marshal.SizeOf(threadInfo);
                NativeMethods.GetGUIThreadInfo(itsThread, ref threadInfo);
                var target = threadInfo.hwndFocus;
                if (target != IntPtr.Zero)
                {
                    var clipboardTextBackup = Clipboard.ContainsText() ? Clipboard.GetText() : null;
                    Clipboard.SetText(text);
                    NativeMethods.PostMessage(target, WM_KEYDOWN, (int)Keys.LControlKey, 1);
                    NativeMethods.PostMessage(target, WM_KEYDOWN, (int)Keys.V, 1);
                    Thread.Sleep(16); // wait 1 frame for the paste command to be processed.
                    if (clipboardTextBackup != null)
                    {
                        Clipboard.SetText(clipboardTextBackup);
                    }
                }
            }
        }
예제 #4
0
        public static bool GetInfo(out GUITHREADINFO lpgui, uint?threadId = null)
        {
            lpgui        = new GUITHREADINFO();
            lpgui.cbSize = Marshal.SizeOf(lpgui);

            return(GetGUIThreadInfo(threadId ?? GetCurrentThreadId(), ref lpgui));
        }
예제 #5
0
        /// <summary>
        /// 現在の入力モードを取得します。
        /// </summary>
        /// <returns>現在の入力モード。</returns>
        public static InputMode GetInputMode()
        {
            var guiThreadInfo = new GUITHREADINFO();

            guiThreadInfo.cbSize = Marshal.SizeOf <GUITHREADINFO>();
            PInvokeFunctions.GetGUIThreadInfo(0, ref guiThreadInfo);
            var imeWnd = PInvokeFunctions.ImmGetDefaultIMEWnd(guiThreadInfo.hwndFocus);

            var value1 = PInvokeFunctions.SendMessage(imeWnd, 0x0283, 0x0001, 0);
            var value2 = PInvokeFunctions.SendMessage(imeWnd, 0x0283, 0x0005, 0);

            if (value1 == 0)
            {
                return(InputMode.Disabled);
            }
            if (value2 == 1)
            {
                return(InputMode.Japanese);
            }
            if (value2 == 0)
            {
                return(InputMode.Direct);
            }
            return(InputMode.Unknown);
        }
예제 #6
0
파일: Native.cs 프로젝트: RossDay/Leap
 /*
 private static int MakeDWord(int LoWord, int HiWord)
 {
     return ((HiWord << 16) | (LoWord & 0xffff));
 }
 */
 private static IntPtr GetActiveWindow()
 {
     var gInfo = new GUITHREADINFO();
     gInfo.cbSize = (uint)Marshal.SizeOf(gInfo);
     GetGUIThreadInfo(0, out gInfo);
     return gInfo.hwndFocus;
 }
예제 #7
0
        // Returns the WindowHandle of the focused window, if that window is in our process.
        public static IntPtr GetFocusedWindowHandle()
        {
            var info = new GUITHREADINFO();

            info.cbSize = Marshal.SizeOf(info);
            if (!GetGUIThreadInfo(0, ref info))
            {
                throw new Win32Exception();
            }

            var focusedWindow = info.hwndFocus;

            if (focusedWindow == IntPtr.Zero)
            {
                return(focusedWindow);
            }

            uint processId;
            uint threadId = GetWindowThreadProcessId(focusedWindow, out processId);

            if (threadId == 0)
            {
                throw new Win32Exception();
            }

            uint currentProcessId = GetCurrentProcessId();

            if (processId == currentProcessId)
            {
                return(focusedWindow);
            }

            return(IntPtr.Zero);
        }
예제 #8
0
파일: Native.cs 프로젝트: Belial2010/Leap
        /*
         * private static int MakeDWord(int LoWord, int HiWord)
         * {
         *  return ((HiWord << 16) | (LoWord & 0xffff));
         * }
         */

        private static IntPtr GetActiveWindow()
        {
            var gInfo = new GUITHREADINFO();

            gInfo.cbSize = (uint)Marshal.SizeOf(gInfo);
            GetGUIThreadInfo(0, out gInfo);
            return(gInfo.hwndFocus);
        }
예제 #9
0
        public static IntPtr GetThreadMoveSizeWindow(int threadId)
        {
            var info = new GUITHREADINFO();

            info.cbSize = Marshal.SizeOf(info);
            GetGUIThreadInfo(threadId, ref info);
            return(info.hwndMoveSize);
        }
예제 #10
0
        public static GUITHREADINFO GetGUIThreadInfo(int tid)
        {
            GUITHREADINFO info = new GUITHREADINFO();

            info.cbSize = Marshal.SizeOf(info);
            WinUserApi.GetGUIThreadInfo(tid, out info);
            return(info);
        }
예제 #11
0
        /// <summary>
        /// Get the caret position
        /// </summary>
        public void GetCaretPosition()
        {
            guiInfo        = new GUITHREADINFO();
            guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);

            // Get GuiThreadInfo into guiInfo
            GetGUIThreadInfo(0, out guiInfo);
        }
예제 #12
0
        static (bool Ok, GUITHREADINFO GUIInfo) GetGUICursorStatus(int processId)
        {
            GUITHREADINFO lpgui = new GUITHREADINFO();

            lpgui.cbSize = Marshal.SizeOf(lpgui);
            bool ok = GetGUIThreadInfo(processId, ref lpgui);

            return(ok, lpgui);
        }
예제 #13
0
        /// <summary>
        /// Retrieves the caret position
        /// </summary>
        public Rectangle GetCaretPosition()
        {
            guiInfo        = new GUITHREADINFO();
            guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);

            GetGUIThreadInfo(0, out guiInfo);
            ClientToScreen(guiInfo.hwndCaret, out guiInfo.rcCaret);

            return(guiInfo.rcCaret);
        }
예제 #14
0
        private static GUITHREADINFO GetThreadInfo()
        {
            GUITHREADINFO guiInfo = new GUITHREADINFO();

            guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);

            // Get GuiThreadInfo into guiInfo
            GetGUIThreadInfo(0, out guiInfo);

            return(guiInfo);
        }
예제 #15
0
        public static IntPtr GetActiveThreadWindow(int threadId)
        {
            GUITHREADINFO threadInfo = new GUITHREADINFO();

            threadInfo.cbSize = Marshal.SizeOf(typeof(GUITHREADINFO));
            if (!GetGUIThreadInfo((uint)threadId, ref threadInfo))
            {
                throw new ApplicationException("Can't get handle. Error:", new Win32Exception(Marshal.GetLastWin32Error()));
            }

            return(threadInfo.hwndActive);
        }
예제 #16
0
        public static Point GetCaretPositionByGUIInfo()
        {
            Point caretPosition = new Point();

            GUITHREADINFO guiInfo = GetThreadInfo();

            caretPosition.X = (int)guiInfo.rcCaret.Left;
            caretPosition.Y = (int)guiInfo.rcCaret.Bottom;

            ClientToScreen(guiInfo.hwndCaret, out caretPosition);

            return(caretPosition);
        }
예제 #17
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // IME状態の取得
            GUITHREADINFO gti = new GUITHREADINFO();

            gti.cbSize = Marshal.SizeOf(gti);
            uint   GUIinfo = GetGUIThreadInfo(0, ref gti);
            IntPtr imwd    = ImmGetDefaultIMEWnd(gti.hwndFocus);

            int imes1 = SendMessage(imwd, 0x0283, 0x0001, 0); // IME状態を取得(有効,無効)

            label1.Text = imes1.ToString();
        }
예제 #18
0
        private static bool IsCaretActive(IntPtr hwnd)
        {
            var threadId = NativeMethods.GetWindowThreadProcessId(hwnd, IntPtr.Zero);

            var info = new GUITHREADINFO
            {
                cbSize = Marshal.SizeOf <GUITHREADINFO>()
            };

            NativeMethods.GetGUIThreadInfo(threadId, ref info);

            return(info.flags != 0 || info.hwndCaret != IntPtr.Zero);
        }
예제 #19
0
    private bool IsCaretActive(HWND hwnd)
    {
        var threadId = PInvoke.GetWindowThreadProcessId(hwnd);

        var info = new GUITHREADINFO
        {
            cbSize = (uint)Marshal.SizeOf <GUITHREADINFO>()
        };

        PInvoke.GetGUIThreadInfo(threadId, ref info);

        return(info.flags != 0 || info.hwndCaret != IntPtr.Zero);
    }
    static void Main(string[] args)
    {
        //create process in focus
        Process.Start("notepad++", "Source.cpp");
        Thread.Sleep(1000);
        GUITHREADINFO threadInfo = new GUITHREADINFO();

        threadInfo.cbSize = Marshal.SizeOf(threadInfo);

        GetGUIThreadInfo(0, ref threadInfo);
        SendMessage(threadInfo.hwndFocus, WM_VSCROLL, SB_LINERIGHT, 0);
        //SetScrollPos not work. Change only scrollbar without scroll window
        //SetScrollPos(threadInfo.hwndFocus, System.Windows.Forms.Orientation.Vertical, 10, true);
    }
예제 #21
0
        public SystemWindow FocusedWindow() //Получение активного контрола
        {
            //@kurumpa http://stackoverflow.com/a/28409126
            IntPtr hwnd = HWnd;
            var    info = new GUITHREADINFO();

            info.cbSize = Marshal.SizeOf(info);
            var success = GetGUIThreadInfo(ThreadId, ref info);

            // target = hwndCaret || hwndFocus || (AttachThreadInput + GetFocus) || hwndActive
            var currentThreadId = GetCurrentThreadId();

            if (currentThreadId != ThreadId)
            {
                AttachThreadInput(ThreadId, currentThreadId, true);
            }
            var focusedHandle = GetFocus();

            if (currentThreadId != ThreadId)
            {
                AttachThreadInput(ThreadId, currentThreadId, false);
            }

            if (success)
            {
                if (info.hwndCaret != IntPtr.Zero)
                {
                    hwnd = info.hwndCaret;
                }
                else if (info.hwndFocus != IntPtr.Zero)
                {
                    hwnd = info.hwndFocus;
                }
                else if (focusedHandle != IntPtr.Zero)
                {
                    hwnd = focusedHandle;
                }
                else if (info.hwndActive != IntPtr.Zero)
                {
                    hwnd = info.hwndActive;
                }
            }
            else
            {
                hwnd = focusedHandle;
            }

            return(new SystemWindow(hwnd, ProcessId, ThreadId));
        }
예제 #22
0
        private void GetIMEMode(GUITHREADINFO info)
        {
            GetGUIThreadInfo(0, ref info);
            IntPtr hIMEWnd = ImmGetDefaultIMEWnd(info.hwndFocus);

            if (IsIMEOn(hIMEWnd))
            {
                Int32 ret = GetIMEMode(hIMEWnd);
                IMEMode.Content = ((ret & 0x10) == 0x0 ? "カナ " : "")
                                  + ((ret & 0xF) == 0x0 ? "A" :
                                     (ret & 0xF) == 0x3 ? "カ" :
                                     (ret & 0xF) == 0x8 ? "A" :
                                     (ret & 0xF) == 0x9 ? "あ" :
                                     (ret & 0xF) == 0xB ? "カ" : "");
#if false
                Int32 ActiveThreadID = GetWindowThreadProcessId(GetForegroundWindow(), out int ActiveProcessID);
                if (AttachThreadInput(GetCurrentThreadId(), ActiveThreadID, true))
                {
                    IntPtr hWndActiveControl = GetFocus();
                    AttachThreadInput(GetCurrentThreadId(), ActiveThreadID, false);
                    GetWindowRect(hWndActiveControl, out RECT rect);
                    var p = new Point((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2);
                    var d = new Point(Control.MousePosition.X - p.X, Control.MousePosition.Y - p.Y);
                    if (d.X >= 0 && d.X <= this.Width && d.Y >= 0 && d.Y <= this.Height)
                    {
                        p.X += this.Width;
                    }
                    this.Left = p.X;
                    this.Top  = p.Y;
                }
#else
                var rect = Screen.PrimaryScreen.Bounds;
                var p    = new Point(rect.Width / 2, rect.Height / 2);
                var d    = new Point(Control.MousePosition.X - p.X, Control.MousePosition.Y - p.Y);
                if (d.X >= 0 && d.X <= this.Width && d.Y >= 0 && d.Y <= this.Height)
                {
                    p.X += this.Width;
                }
                this.Left = p.X;
                this.Top  = p.Y;
#endif
                this.Opacity = 0.5;
            }
            else
            {
                IMEMode.Content = "";
                this.Opacity    = 0.0;
            }
        }
예제 #23
0
        private void getCaretPos(object sender, EventArgs e)
        {
            IntPtr hWnd = GetForegroundWindow();

            if (hWnd != IntPtr.Zero)
            {
                IntPtr target = GetWindowThreadProcessId(hWnd, IntPtr.Zero);

                GUITHREADINFO gti = new GUITHREADINFO();
                gti.cbSize = Marshal.SizeOf(gti);
                if (!GetGUIThreadInfo(target, ref gti))
                {
                    throw new System.ComponentModel.Win32Exception();
                }
                label1.Content = String.Format("l:{0}, t:{1}, w:{2}, h:{3}",
                                               gti.rectCaret.iLeft, gti.rectCaret.iTop,
                                               gti.rectCaret.iRight - gti.rectCaret.iLeft, gti.rectCaret.iBottom - gti.rectCaret.iTop);
                Point p2 = new Point(gti.rectCaret.iLeft, gti.rectCaret.iTop);

                RECT rect1 = new RECT(0, 0, 0, 0);
                GetWindowRect(gti.hwndFocus, out rect1);

                RECT rect2 = new RECT(0, 0, 0, 0);
                GetClientRect(hWnd, out rect2);
                label2.Content = String.Format("WRect l:{0}, t:{1}, r:{2}, b:{3}", rect1.iLeft, rect1.iTop, rect1.iRight, rect1.iBottom);
                label3.Content = String.Format("CRect l:{0}, t:{1}, r:{2}, b:{3}", rect2.iLeft, rect2.iTop, rect2.iRight, rect2.iBottom);

                p2.X = p2.X + rect1.iLeft;
                p2.Y = p2.Y + rect1.iTop;

                this.Left = p2.X - this.Width / 2;
                this.Top  = p2.Y - this.Height / 2;

                // for calibration

                /*
                 * this.Left = 0 - this.Width/2;
                 * this.Top = 0 - this.Height/2;
                 */
                label4.Content = String.Format("Caret x:{0}, y:{1}, w:{2}, h:{3}", p2.X, p2.Y, gti.rectCaret.iRight - gti.rectCaret.iLeft, gti.rectCaret.iBottom - gti.rectCaret.iTop);
            }
            else
            {
                label1.Content = "n/a";
                label2.Content = "n/a";
                label3.Content = "n/a";
                label4.Content = "n/a";
            }
        }
 public GUITHREADINFO?GetGuiThreadInfo(IntPtr hwnd)
 {
     if (hwnd != IntPtr.Zero)
     {
         uint          threadId      = GetWindowThreadProcessId(hwnd, IntPtr.Zero);
         GUITHREADINFO guiThreadInfo = new GUITHREADINFO();
         guiThreadInfo.cbSize = Marshal.SizeOf(guiThreadInfo);
         if (GetGUIThreadInfo(threadId, ref guiThreadInfo) == false)
         {
             return(null);
         }
         return(guiThreadInfo);
     }
     return(null);
 }
예제 #25
0
        public static Point GetCaretPositionByGetCaretPos()
        {
            Point caretPosition = new Point();

            GUITHREADINFO guiInfo = GetThreadInfo();

            RECT activeWindowPosition;

            GetWindowRect(GetForegroundWindow(), out activeWindowPosition);
            GetCaretPos(out caretPosition);

            ClientToScreen(guiInfo.hwndCaret, out caretPosition);

            return(caretPosition);
        }
예제 #26
0
        public static IntPtr ActiveWindow()         //Gets active windows(focused) or foreground
        {
            IntPtr awHandle = IntPtr.Zero;
            var    gui      = new GUITHREADINFO();

            gui.cbSize = Marshal.SizeOf(gui);
            GetGUIThreadInfo(GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero), ref gui);

            awHandle = gui.hwndFocus;
            if (awHandle == IntPtr.Zero)
            {
                awHandle = GetForegroundWindow();
            }
            return(awHandle);
        }
        public static IntPtr getThreadWindowHandle(uint dwThreadId)
        {
            GUITHREADINFO lpgui = default(GUITHREADINFO);

            lpgui.cbSize = Marshal.SizeOf((object)lpgui);
            GetGUIThreadInfo(dwThreadId, ref lpgui);
            IntPtr intPtr = lpgui.hwndFocus;

            if (intPtr == IntPtr.Zero)
            {
                intPtr = lpgui.hwndActive;
            }

            return(intPtr);
        }
예제 #28
0
 private void OnLoad(object sender, RoutedEventArgs e)
 {
     (new Thread(new ThreadStart(() => {
         var aGetIMEMode = new getIMEModeFunc(GetIMEMode);
         var info = new GUITHREADINFO();
         info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
         while (true)
         {
             Thread.Sleep(250);
             Dispatcher.BeginInvoke(aGetIMEMode, info);
         }
     }))
     {
         IsBackground = true
     }).Start();
 }
예제 #29
0
        public static Point getCaretPosition()
        {
            Point caretPos = new Point();

            GUITHREADINFO tempInfo = new GUITHREADINFO();
            tempInfo.cbSize = (uint)Marshal.SizeOf(tempInfo);
            GetGUIThreadInfo(0, out tempInfo);

            if (tempInfo.rcCaret.left != -1)
            {
            caretPos.X = (int)tempInfo.rcCaret.left;
            caretPos.Y = (int)tempInfo.rcCaret.bottom;

            ClientToScreen(tempInfo.hwndCaret, out caretPos);
            }

            return caretPos;
        }
예제 #30
0
        public static Point GetCenterOfActiveScreen()
        {
            Point         caretPosition = new Point();
            GUITHREADINFO guiInfo       = GetThreadInfo();

            Screen screen = GetActiveScreen();

            int top    = (int)screen.WorkingArea.Top;
            int bottom = (int)screen.WorkingArea.Bottom;
            int left   = (int)screen.WorkingArea.Left;
            int right  = (int)screen.WorkingArea.Right;

            caretPosition.X = right - ((right - left) / 2);
            caretPosition.Y = bottom - ((bottom - top) / 2);

            ClientToScreen(guiInfo.hwndCaret, out caretPosition);
            return(caretPosition);
        }
예제 #31
0
        private static void Execute()
        {
            GUITHREADINFO gti = new GUITHREADINFO();

            gti.cbSize = Marshal.SizeOf(gti);

            if (!GetGUIThreadInfo(0, ref gti))
            {
                Console.WriteLine("Failed To Run Rose");
            }
            IntPtr imwd = ImmGetDefaultIMEWnd(gti.hwndFocus);

            bool imeEnabled = (SendMessage(imwd, WM_IME_CONTROL, (IntPtr)IMC_GETOPENSTATUS, IntPtr.Zero) != 0);

            if (imeEnabled)
            {
                SendMessage(imwd, WM_IME_CONTROL, (IntPtr)IMC_SETCONVERSIONMODE, (IntPtr)0);
            }
        }
예제 #32
0
파일: KeyboxFunc.cs 프로젝트: MarkDDi/Frame
        private static GUITHREADINFO?GetGuiThreadInfo(IntPtr hwnd)
        {
            GUITHREADINFO guiThreadInfo = new GUITHREADINFO();

            if (hwnd != IntPtr.Zero)
            {
                //Mbox.Info(GetTitle(hwnd), "O");
                uint threadId = GetWindowThreadProcessId(hwnd, IntPtr.Zero);


                guiThreadInfo.cbSize = Marshal.SizeOf(guiThreadInfo);

                if (GetGUIThreadInfo(threadId, ref guiThreadInfo) == false)
                {
                    return(null);
                }
            }
            return(guiThreadInfo);
        }
예제 #33
0
        // Returns the WindowHandle of the focused window, if that window is in our process.
        public static IntPtr GetFocusedWindowHandle()
        {
            var info = new GUITHREADINFO();
            info.cbSize = Marshal.SizeOf(info);
            if (!GetGUIThreadInfo(0, ref info))
                throw new Win32Exception();

            var focusedWindow = info.hwndFocus;
            if (focusedWindow == IntPtr.Zero)
                return focusedWindow;

            uint processId;
            uint threadId = GetWindowThreadProcessId(focusedWindow, out processId);
            if (threadId == 0)
                throw new Win32Exception();

            uint currentProcessId = GetCurrentProcessId();
            if (processId == currentProcessId)
                return focusedWindow;

            return IntPtr.Zero;
        }
예제 #34
0
파일: Win32.cs 프로젝트: bkbartk/dRemote
 public static extern bool GetGUIThreadInfo(Int32 idThread, GUITHREADINFO lpgui);
예제 #35
0
        /// <summary>
        /// Get the caret position
        /// </summary>
        public void GetCaretPosition()
        {
            guiInfo = new GUITHREADINFO();
            guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);

            // Get GuiThreadInfo into guiInfo
            GetGUIThreadInfo(0, out guiInfo);
        }
예제 #36
0
 public static extern bool GetGUIThreadInfo(uint idThread, out GUITHREADINFO lpgui);
 public static extern bool GetGUIThreadInfo(int idThread, ref GUITHREADINFO guiThreadInfo);
예제 #38
0
 static extern bool GetGUIThreadInfo(uint idThread, ref GUITHREADINFO lpgui);
예제 #39
0
        public void getCaretPosition()
        {
            GUITHREADINFO temp = new GUITHREADINFO();
            temp.cbSize = (uint)Marshal.SizeOf(temp);

            // Get GuiThreadInfo into guiInfo
            GetGUIThreadInfo(0, out temp);

            if(temp.rcCaret.Left != 0)
                guiInfo = temp;
        }
예제 #40
0
 public static extern bool GetGUIThreadInfo(uint tId, out GUITHREADINFO threadInfo);