Ejemplo n.º 1
0
 public static void UnLockWindowUpdate(Control c)
 {
     if (c.IsHandleCreated)
     {
         User32PI.LockWindowUpdate(0);
     }
 }
Ejemplo n.º 2
0
 public static void LockWindowUpdate(Control c)
 {
     if (c.IsHandleCreated)
     {
         User32PI.LockWindowUpdate(c.Handle.ToInt64());
     }
 }
Ejemplo n.º 3
0
        public static string GetWindowText(IntPtr handle)
        {
            var bufSize = 2048;
            var buf     = new StringBuilder(bufSize);

            User32PI.GetWindowText(handle, buf, buf.Capacity);
            return(buf.ToString());
        }
Ejemplo n.º 4
0
        public static void ResetMouseHover(IntPtr windowTrackingMouseHandle, int hoverTime)
        {
            // Set up the parameter collection for the API call so that the appropriate
            // control fires the event
            TRACKMOUSEEVENT parameterBag = new TRACKMOUSEEVENT(windowTrackingMouseHandle, hoverTime);

            // The actual API call
            User32PI.TrackMouseEvent(ref parameterBag);
        }
Ejemplo n.º 5
0
        public static IntPtr GetNextWindow(IntPtr handle, Predicate <IntPtr> pred)
        {
            var ret = handle;

            do
            {
                ret = User32PI.GetNextWindow(ret, GetNextWindowCommand.Next);
            } while (!pred(ret) && ret != IntPtr.Zero);
            return(ret);
        }
Ejemplo n.º 6
0
        public static void ActivateWindow(IntPtr handle)
        {
            var pid    = default(int);
            var fore   = User32PI.GetWindowThreadProcessId(User32PI.GetForegroundWindow(), out pid);
            var target = User32PI.GetWindowThreadProcessId(handle, out pid);

            User32PI.AttachThreadInput(target, fore, true);
            User32PI.SetForegroundWindow(handle);
            User32PI.AttachThreadInput(target, fore, false);
            User32PI.SetActiveWindow(handle);
        }
Ejemplo n.º 7
0
        // ========================================
        // field
        // ========================================

        // ========================================
        // constructor
        // ========================================

        // ========================================
        // property
        // ========================================

        // ========================================
        // method
        // ========================================
        /// <summary>
        /// windowをアクティブにする.
        /// windowClassName,windowTitleは前方一致,moduleFileNameは後方一致.
        /// nullを渡すとそれぞれ常に適合.
        /// </summary>
        public static void ActivateWindow(string windowClassName, string windowTitle, string moduleFileName)
        {
            var targetHWnd = IntPtr.Zero;

            User32PI.EnumWindows(
                (hWnd, lParam) => {
                var bufSize = 2048;
                var buf     = new StringBuilder(bufSize);

                User32PI.GetClassName(hWnd, buf, buf.Capacity);
                var className = buf.ToString();

                User32PI.GetWindowText(hWnd, buf, buf.Capacity);
                var title = buf.ToString();

                var validClassName =
                    string.IsNullOrEmpty(windowClassName) ||
                    (!string.IsNullOrEmpty(className) && className.StartsWith(windowClassName));
                var validTitle =
                    string.IsNullOrEmpty(windowTitle) ||
                    (!string.IsNullOrEmpty(title) && title.StartsWith(windowTitle));
                if (validClassName && validTitle)
                {
                    if (string.IsNullOrEmpty(moduleFileName))
                    {
                        targetHWnd = hWnd;
                        return(false);
                    }
                    else
                    {
                        var pid = default(int);
                        User32PI.GetWindowThreadProcessId(hWnd, out pid);
                        var process  = Process.GetProcessById(pid);
                        var fileName = process.MainModule.FileName;

                        if (!string.IsNullOrEmpty(fileName) && fileName.EndsWith(moduleFileName))
                        {
                            targetHWnd = hWnd;
                            return(false);
                        }
                    }
                }

                return(true);
            },
                IntPtr.Zero
                );

            if (targetHWnd != IntPtr.Zero)
            {
                RestoreWindow(targetHWnd);
            }
        }
Ejemplo n.º 8
0
 public static void RestoreWindow(IntPtr hWnd)
 {
     if (hWnd != IntPtr.Zero)
     {
         if (User32PI.IsIconic(hWnd))
         {
             User32PI.ShowWindowAsync(hWnd, WindowShowStyle.Restore);
         }
         User32PI.SetForegroundWindow(hWnd);
         //ActivateWindow(hWnd);
     }
 }
Ejemplo n.º 9
0
        //var dummy = 0;
        //var foreThread = User32PI.GetWindowThreadProcessId(User32PI.GetForegroundWindow(), out dummy);
        //var thisThread = Kernel32PI.GetCurrentThreadId();

        //if (User32PI.AttachThreadInput(thisThread, foreThread, true)) {
        //    var hwnd = User32PI.GetFocus();
        //User32Util.SendCopy(hwnd);
        //    User32PI.AttachThreadInput(thisThread, foreThread, false);
        //}

        //public static void SendCopy(IntPtr targetHandle) {
        //    User32PI.SendMessage(targetHandle, (int) WindowMessages.COPY, IntPtr.Zero, IntPtr.Zero);
        //}


        public static void SendCtrlC(string hotKeyStr)
        {
            var inputs = new List <INPUT>();

            var vks = GetKeyCodes(hotKeyStr);

            inputs.AddRange(vks.Select(vk => GetUpInput(vk)));

            inputs.Add(GetDownInput(Win32Consts.VK_CONTROL));
            inputs.Add(GetDownInput(Win32Consts.VK_C));
            inputs.Add(GetUpInput(Win32Consts.VK_C));
            inputs.Add(GetUpInput(Win32Consts.VK_CONTROL));

            User32PI.SendInput(inputs.Count, inputs.ToArray(), Marshal.SizeOf(typeof(INPUT)));
        }
Ejemplo n.º 10
0
        public static string GetActiveWindowText()
        {
            var hwnd = User32PI.GetForegroundWindow();

            if (hwnd == IntPtr.Zero)
            {
                return(null);
            }
            else
            {
                var buf = new StringBuilder(2048);
                User32PI.GetWindowText(hwnd, buf, buf.Capacity);
                return(buf.ToString());
            }
        }
Ejemplo n.º 11
0
 public static void GetWindows()
 {
     User32PI.EnumWindows(
         (hWnd, lParam) => {
         if (User32PI.IsWindowVisible(hWnd))
         {
             var className = GetWindowClassName(hWnd);
             var title     = GetWindowText(hWnd);
             //Console.WriteLine(title + "," + className);
         }
         return(true);
     },
         IntPtr.Zero
         );
 }
Ejemplo n.º 12
0
 public static bool IsOwnedWindow(IntPtr handle)
 {
     return(User32PI.GetWindow(handle, GetWindowCmd.GW_OWNER) != IntPtr.Zero);
 }