コード例 #1
0
        public ResultItem Execute()
        {
            IntPtr currentHandle = instance.GetCurrentHandle();

            if (currentHandle == IntPtr.Zero)
            {
                throw new InvalidCurrentHandleException();
            }
            StructComponent.RECT rect = new StructComponent.RECT();
            Win32.GetClientRect(currentHandle, out rect);// 取得窗口内控件的坐标
#if DEBUG
            Console.WriteLine("获取到指定句柄变换前的矩形: " + rect.ToString());
#endif
            StructComponent.POINT point = new StructComponent.POINT
            {
                X = rect.Left,
                Y = rect.Bottom
            };
            Win32.ClientToScreen(currentHandle, ref point);// 取得该控件位置对应的桌面坐标
            rect.Left   = point.X;
            rect.Bottom = point.Y;
            point.X     = rect.Right;
            point.Y     = rect.Top;
            Win32.ClientToScreen(currentHandle, ref point);// 取得该控件位置对应的桌面坐标
            rect.Right = point.X;
            rect.Top   = point.Y;
            TargetRectangle targetRectangle = TargetRectangle.GetInstance();
            targetRectangle.SetRectangle(rect.Left, rect.Top, rect.Right, rect.Bottom);
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("获取到指定句柄的矩形: " + rect.ToString());
#if DEBUG
            Console.WriteLine(sb.ToString());
#endif
            return(new ResultItem(ResultItem.States.OK, sb.ToString()));
        }
コード例 #2
0
        static void Main()
        {
            WindowHandle      handle    = WindowHandle.GetInstance();
            SettingComponent  settings  = SettingComponent.GetInstance();
            TargetRectangle   rectangle = TargetRectangle.GetInstance();
            ExportPointMatrix matrix    = ExportPointMatrix.GetInstance();

            if (RunningInstance() == null)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm(handle, rectangle, settings, matrix));
            }
            else
            {
                MessageBox.Show("有一个和本程序相同的应用程序已经在运行, 请不要同时运行多个本程序.\n\n这个程序即将退出。",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }