コード例 #1
0
        // ウィンドウハンドルを渡すと、ウィンドウテキスト(ラベルなど)、クラス、スタイルを取得してWindowsクラスに格納して返す
        private static WindowData GetWindow(IntPtr hWnd)
        {
            var    textLen    = Win32Controller.GetWindowTextLength(hWnd);
            string windowText = null;

            if (textLen > 0)
            {
                //ウィンドウのタイトルを取得する
                var windowTextBuffer = new StringBuilder(textLen + 1);
                Win32Controller.GetWindowText(hWnd, windowTextBuffer, windowTextBuffer.Capacity);
                windowText = windowTextBuffer.ToString();
            }

            //ウィンドウのクラス名を取得する
            var classNameBuffer = new StringBuilder(256);

            Win32Controller.GetClassName(hWnd, classNameBuffer, classNameBuffer.Capacity);

            // スタイルを取得する
            var style = Win32Controller.GetWindowLong(hWnd, Win32Controller.GwlStyle);

            return(new WindowData()
            {
                HWnd = hWnd, Title = windowText, ClassName = classNameBuffer.ToString(), Style = style
            });
        }
コード例 #2
0
        private static bool PostEnterKeyCharToProcess(IntPtr processHandle, int waitTime)
        {
            System.Threading.Thread.Sleep(waitTime);

            // 0xD:Enter
            return(Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x0000000D, 0x001C0001) != 0);
        }
コード例 #3
0
        // 与えた親ウィンドウの直下にある子ウィンドウを列挙する(孫ウィンドウは見つけてくれない)
        private static IEnumerable <WindowData> EnumChildWindows(IntPtr hParentWindow)
        {
            var hWnd = IntPtr.Zero;

            while ((hWnd = Win32Controller.FindWindowEx(hParentWindow, hWnd, null, null)) != IntPtr.Zero)
            {
                yield return(GetWindow(hWnd));
            }
        }
コード例 #4
0
        public static bool ActivateUplay()
        {
            var psh = GetUplayProcessHandle();

            if (psh == IntPtr.Zero)
            {
                return(false);
            }

            return(!Win32Controller.IsIconic(psh) || Win32Controller.ShowWindow(psh, 1));
        }
コード例 #5
0
        private static bool PostSpaceKeyInputToProcess(IntPtr processHandle, int waitTime)
        {
            System.Threading.Thread.Sleep(waitTime);

            // 0x20:Space
            if (Win32Controller.PostMessage(processHandle, Win32Controller.WmKeyDown, 0x00000020, 0x00390001) != 0)
            {
                System.Threading.Thread.Sleep(waitTime);
                return(Win32Controller.PostMessage(processHandle, Win32Controller.WmKeyUp, 0x00000020, 0xC0390001) != 0);
            }

            return(false);
        }
コード例 #6
0
        private static bool PostEnterKeyInputToProcess(IntPtr processHandle, int waitTime)
        {
            System.Threading.Thread.Sleep(waitTime);

            // 0xD:Enter
            if (Win32Controller.PostMessage(processHandle, Win32Controller.WmKeyDown, 0x0000000D, 0x001C0001) != 0)
            {
                System.Threading.Thread.Sleep(waitTime);
                return(Win32Controller.PostMessage(processHandle, Win32Controller.WmKeyUp, 0x0000000D, 0xC01C0001) != 0);
            }

            return(false);
        }
コード例 #7
0
        /// <summary>
        /// 与えられたプロセスに対し、約waitTime[ms]後にクライアント座標(x,y)の位置にマウスクリックイベントを起こす
        /// </summary>
        /// <param name="processHandle">
        /// The process Handle.
        /// </param>
        /// <param name="waitTime">
        /// The wait Time.
        /// </param>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private static bool PostMlbClickToProcess(IntPtr processHandle, int waitTime, ushort x, ushort y)
        {
            // wait
            System.Threading.Thread.Sleep(waitTime);

            // マウスクリックダウン
            if (Win32Controller.PostMessage(
                    processHandle,
                    Win32Controller.WmLButtonDown,
                    Win32Controller.MkLBotton,
                    Win32Controller.MakeLParam(x, y)) == 0)
            {
                return(false);
            }

            System.Threading.Thread.Sleep(waitTime);

            // マウスクリックアップ
            return(Win32Controller.PostMessage(
                       processHandle,
                       Win32Controller.WmLButtonUp,
                       0x00000000,
                       Win32Controller.MakeLParam(x, y)) != 0);
        }
コード例 #8
0
        private static bool PostKeyCharToProcess(IntPtr processHandle, string keys, int intervalTime)
        {
            foreach (var item in keys)
            {
                System.Threading.Thread.Sleep(intervalTime);

                // 0x20:Space
                if (Regex.IsMatch(item.ToString(), @"^ $"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x00000020, 0x001E0001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x2E:Dot
                if (Regex.IsMatch(item.ToString(), @"^\.$"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x0000002E, 0x001E0001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x40:@
                if (Regex.IsMatch(item.ToString(), @"^@$"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x00000040, 0x001E0001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x5F:_
                if (Regex.IsMatch(item.ToString(), @"^_$"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x0000005F, 0x00730001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x2D:-
                if (Regex.IsMatch(item.ToString(), @"^-$"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x0000002D, 0x000C0001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x21:!
                if (Regex.IsMatch(item.ToString(), @"^!$"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x00000021, 0x00020001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x3F:?
                if (Regex.IsMatch(item.ToString(), @"^\?$"))
                {
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, 0x0000003F, 0x00350001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x30:0
                if (Regex.IsMatch(item.ToString(), @"^[0-9]$"))
                {
                    uint wparam = 0x00000030 + (uint)(item - '0');
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, wparam, 0x001E0001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x41:A
                if (Regex.IsMatch(item.ToString(), @"^[A-Z]$"))
                {
                    uint wparam = 0x00000041 + (uint)(item - 'A');
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, wparam, 0x001E0001) == 0)
                    {
                        return(false);
                    }

                    continue;
                }

                // 0x61:a
                if (Regex.IsMatch(item.ToString(), @"^[a-z]$"))
                {
                    uint wparam = 0x00000061 + (uint)(item - 'a');
                    if (Win32Controller.PostMessage(processHandle, Win32Controller.WmChar, wparam, 0x001E0001) == 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }