Example #1
0
        /// <summary>
        /// 获取窗体句柄的Text信息
        /// </summary>
        /// <param name="handle">窗体句柄</param>
        /// <returns></returns>
        protected string GetHandleText(IntPtr handle)
        {
            StringBuilder sb = new StringBuilder(256);

            WindowsApi.GetWindowText(handle, sb, sb.Capacity);
            return(sb.ToString());
        }
Example #2
0
        /// <summary>
        /// 填充主窗体信息
        /// </summary>
        /// <param name="handle">主窗体句柄</param>
        /// <param name="serverName">当前服务器名称</param>
        /// <param name="loginType">当前登陆类型</param>
        protected virtual void OnPaddingProcess(IntPtr handle, string serverName, LoginType loginType)
        {
            ControlHandle controlHandle = GetControlHandle(handle);

            _activeControlHandle = controlHandle;

            if (!Global.SystemConfig.ServerList.ContainsKey(serverName))
            {
                return;
            }

            ServerInfo serverInfo = Global.SystemConfig.ServerList[serverName];

            if (serverInfo.LoginType != loginType)
            {
                return;
            }

            WindowsApi.SendMessage(controlHandle.UsernameHandle, WindowsApi.WM_SETTEXT, 1024, serverInfo.UserName);
            WindowsApi.SendMessage(controlHandle.PasswordHandle, WindowsApi.WM_SETTEXT, 1024, serverInfo.Password);

            if (controlHandle.LoginType == LoginType.Windows)
            {
                WindowsApi.SendMessage(controlHandle.DomainHandle, WindowsApi.WM_SETTEXT, 1024, serverInfo.Domain);
            }

            if (Global.SystemConfig.IsAutoEnter)
            {
                WindowsApi.PostMessage(controlHandle.OkButtonHandle, WindowsApi.WM_KEYDOWN, 0X0D, 0);
            }
        }
Example #3
0
        public void Start()
        {
            if (!IsStarted)
            {
                AssignHandle(_parentHandle);

                CBTHook.Start();
                MouseLLHook.Start();
                KeyboardLLHook.Start();

                IntPtr    handle    = IntPtr.Zero;
                string    name      = string.Empty;
                LoginType loginType = LoginType.Radmin;
                WindowsApi.EnumChildWindows(IntPtr.Zero, (hwnd, lParam) =>
                {
                    if (IsLoginWindows(hwnd))
                    {
                        handle       = hwnd;
                        string title = GetHandleText(handle);
                        loginType    = GetLoginType(title);
                        name         = RemoveStringPreFlag(title);
                        return(false);
                    }
                    return(true);
                }, IntPtr.Zero);

                if (handle != IntPtr.Zero)
                {
                    OnPaddingProcess(handle, name, loginType);
                }

                IsStarted = true;
            }
        }
Example #4
0
        /// <summary>
        /// 校验当前句柄对应的窗体是否为登陆窗体
        /// </summary>
        /// <param name="handle">窗体句柄</param>
        /// <returns></returns>
        protected bool IsLoginWindows(IntPtr handle)
        {
            StringBuilder sb = new StringBuilder(256);

            WindowsApi.GetWindowText(handle, sb, sb.Capacity);
            string title = sb.ToString();

            return(IsLoginWindows(title));
        }
Example #5
0
        /// <summary>
        /// 提取界面服务器信息
        /// </summary>
        /// <param name="controlHandle">窗体控件句柄数据</param>
        /// <returns></returns>
        protected virtual ServerInfo PickUpServerInfo(ControlHandle controlHandle)
        {
            int defaultCheckValue = (int)WindowsApi.SendMessage(controlHandle.DefaultCheckHandle, WindowsApi.BM_GETCHECK, 0, 0);

            if (defaultCheckValue != WindowsApi.BST_CHECKED)
            {
                return(null);
            }

            ServerInfo serverInfo = new ServerInfo();

            serverInfo.Name      = controlHandle.Title;
            serverInfo.LoginType = controlHandle.LoginType;

            StringBuilder stringBuilder = new StringBuilder(1024);

            WindowsApi.SendMessage(controlHandle.UsernameHandle, WindowsApi.WM_GETTEXT, 1024, stringBuilder);
            serverInfo.UserName = stringBuilder.ToString();


            long dwStyle = WindowsApi.GetWindowLong(controlHandle.PasswordHandle, WindowsApi.GWL_STYLE); //获取密码框原来样式

            WindowsApi.SetWindowWord(controlHandle.PasswordHandle, WindowsApi.GWL_STYLE, 0);             //取消所有样式
            WindowsApi.SetWindowLong(controlHandle.PasswordHandle, WindowsApi.GWL_STYLE,
                                     dwStyle & ~WindowsApi.ES_PASSWORD);                                 //去掉密码属性

            stringBuilder.Remove(0, stringBuilder.Length);
            WindowsApi.SendMessage(controlHandle.PasswordHandle, WindowsApi.WM_GETTEXT, 1024, stringBuilder);
            //没有了ES_PASSWORD属性WM_GETTEXT可以成功

            WindowsApi.SetWindowLong(controlHandle.PasswordHandle, WindowsApi.GWL_STYLE, dwStyle); //还原密码框原来样式

            serverInfo.Password = stringBuilder.ToString();
            if (serverInfo.LoginType == LoginType.Windows)
            {
                stringBuilder.Remove(0, stringBuilder.Length);
                WindowsApi.SendMessage(controlHandle.DomainHandle, WindowsApi.WM_GETTEXT, 1024, stringBuilder);
                serverInfo.Domain = stringBuilder.ToString();
            }

            if (string.IsNullOrEmpty(serverInfo.Password))
            {
                return(null);
            }

            return(serverInfo);
        }
Example #6
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));
                    }
                }
            }
        }
Example #7
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;
            int  tabIndex      = 0;

            WindowsApi.EnumChildWindows(handle, (hwnd, lParam) =>
            {
                #region 旧逻辑(已注释)

                //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");

                #endregion

                if (controlHandle.LoginType == LoginType.Radmin)
                {
                    if (tabIndex == 0) //用户名
                    {
                        controlHandle.UsernameHandle = hwnd;
                    }
                    else if (tabIndex == 2) //密码框
                    {
                        controlHandle.PasswordHandle = hwnd;
                    }
                    else if (tabIndex == 4) //缺省值CheckBox
                    {
                        controlHandle.DefaultCheckHandle = hwnd;
                    }

                    //3.4版Radmin方式登陆的确认按钮Y坐标为111,3.5的为112
                    else if (tabIndex == 5) //确定按钮
                    {
                        controlHandle.OkButtonHandle = hwnd;
                    }
                    else if (tabIndex == 6) //取消按钮
                    {
                        controlHandle.CancelButtonHandle = hwnd;
                    }
                }
                else if (controlHandle.LoginType == LoginType.Windows)
                {
                    if (tabIndex == 0) //用户名
                    {
                        controlHandle.UsernameHandle = hwnd;
                    }
                    else if (tabIndex == 2) //密码框
                    {
                        controlHandle.PasswordHandle = hwnd;
                    }
                    else if (tabIndex == 4) //域名
                    {
                        controlHandle.DomainHandle = hwnd;
                    }

                    // TODO:暂时没找到如何有此连接的主机
                    ////界面存在“主机名称”标签
                    //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 (tabIndex == 6)
                        {
                            controlHandle.DefaultCheckHandle = hwnd;
                        }
                        else if (tabIndex == 7) //确定按钮
                        {
                            controlHandle.OkButtonHandle = hwnd;
                        }
                        else if (tabIndex == 8) //取消按钮
                        {
                            controlHandle.CancelButtonHandle = hwnd;
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException("unknow ProgramFlag");
                }

                tabIndex++;

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

            return(controlHandle);
        }
Example #8
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);
        }