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