コード例 #1
0
        void MouseLLHook_MouseUp(object sender, MouseEventArgs e)
        {
            if (_activeControlHandle != null && e.Button == MouseButtons.Left)
            {
                WindowsApi.Point point = new WindowsApi.Point {
                    X = (uint)e.X, Y = (uint)e.Y
                };
                IntPtr handle = WindowsApi.WindowFromPoint(point);

                if (_activeControlHandle.OkButtonHandle == handle)
                {
                    ServerInfo serverInfo = PickUpServerInfo(_activeControlHandle);
                    if (CatchServerInfo != null && serverInfo != null)
                    {
                        CatchServerInfo(this, new ServerInfoEventArgs(serverInfo));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取主窗体中子控件句柄
        /// </summary>
        /// <param name="handle">主窗体句柄</param>
        /// <returns></returns>
        protected ControlHandle GetControlHandle(IntPtr handle)
        {
            ControlHandle controlHandle = new ControlHandle();

            controlHandle.ParentHandle = handle;

            string title = GetHandleText(handle);

            controlHandle.LoginType = GetLoginType(title);
            controlHandle.Title     = RemoveStringPreFlag(title);

            bool existHostName = false;

            WindowsApi.EnumChildWindows(handle, (hwnd, lParam) =>
            {
                WindowsApi.Rect rect = new WindowsApi.Rect();
                WindowsApi.GetWindowRect(hwnd, out rect);
                WindowsApi.Point point = new WindowsApi.Point();
                point.X = rect.Left;
                point.Y = rect.Top;
                WindowsApi.ScreenToClient(handle, ref point);
                if (controlHandle.LoginType == LoginType.Radmin)
                {
                    if (point.X == 83 && point.Y == 20) //用户名
                    {
                        controlHandle.UsernameHandle = hwnd;
                    }
                    else if (point.X == 83 && point.Y == 55) //密码框
                    {
                        controlHandle.PasswordHandle = hwnd;
                    }
                    else if (point.X == 18 && point.Y == 88) //缺省值CheckBox
                    {
                        controlHandle.DefaultCheckHandle = hwnd;
                    }

                    //3.4版Radmin方式登陆的确认按钮Y坐标为111,3.5的为112
                    else if (point.X == 83 && (point.Y == 111 || point.Y == 112)) //确定按钮
                    {
                        controlHandle.OkButtonHandle = hwnd;
                    }
                    else if (point.X == 180 && (point.Y == 111 || point.Y == 112)) //取消按钮
                    {
                        controlHandle.CancelButtonHandle = hwnd;
                    }
                }
                else if (controlHandle.LoginType == LoginType.Windows)
                {
                    if (point.X == 83 && point.Y == 20) //用户名
                    {
                        controlHandle.UsernameHandle = hwnd;
                    }
                    else if (point.X == 83 && point.Y == 55) //密码框
                    {
                        controlHandle.PasswordHandle = hwnd;
                    }
                    else if (point.X == 83 && point.Y == 89) //域名
                    {
                        controlHandle.DomainHandle = hwnd;
                    }

                    //界面存在“主机名称”标签
                    else if (point.X == 18 && point.Y == 91)
                    {
                        existHostName = true;
                    }

                    if (existHostName)
                    {
                        if (point.X == 18 && point.Y == 153)
                        {
                            controlHandle.DefaultCheckHandle = hwnd;
                        }
                        else if (point.X == 83 && point.Y == 176) //确定按钮
                        {
                            controlHandle.OkButtonHandle = hwnd;
                        }
                        else if (point.X == 180 && point.Y == 176) //取消按钮
                        {
                            controlHandle.CancelButtonHandle = hwnd;
                        }
                    }
                    else
                    {
                        if (point.X == 18 && point.Y == 122)
                        {
                            controlHandle.DefaultCheckHandle = hwnd;
                        }
                        else if (point.X == 83 && point.Y == 145) //确定按钮
                        {
                            controlHandle.OkButtonHandle = hwnd;
                        }
                        else if (point.X == 180 && point.Y == 145) //取消按钮
                        {
                            controlHandle.CancelButtonHandle = hwnd;
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException("unknow ProgramFlag");
                }

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

            return(controlHandle);
        }