private void GetAllInfoByPrcName(String prcName) { List <WinFormModel> formInfos = new List <WinFormModel>(); try { #region 根据进程名,获取所有对应窗口下的子句柄 List <WindowInfo> list = WindowFormAPI.GetAllDesktopWindows().ToList(); //List<WindowInfo> newwindows = list.Where(c => c.szWindowName.Contains(prcName)).ToList(); List <WindowInfo> curFormList = new List <WindowInfo>(); foreach (WindowInfo item in list) { curFormList.AddRange(WindowFormAPI.GetAllDesktopWindows(item.hWnd)); } //代理设置 List <WindowInfo> newList = new List <WindowInfo>(); foreach (var item in curFormList) { List <WindowInfo> curList = newList.Where(c => { bool retVal = false; if (c.hWnd == item.hWnd && c.ItemId == item.ItemId) { retVal = true; } return(retVal); }).ToList(); if (curList != null && curList.Count <= 0) { newList.Add(item); } } //List<WindowInfo> curEditList = newList.Where(c => !string.IsNullOrEmpty(c.szWindowName) && c.szWindowName.Contains("代理设置")).ToList(); List <WindowInfo> curEditList1 = list.Where(c => !string.IsNullOrEmpty(c.szWindowName) && c.szWindowName.Contains("EasyConnect")).ToList(); List <WindowInfo> curEditList2 = curFormList.Where(c => !string.IsNullOrEmpty(c.szWindowName) && c.szWindowName.Contains("EasyConnect")).ToList(); List <WindowInfo> curEditList3 = list.Where(c => !string.IsNullOrEmpty(c.szWindowName) && c.szWindowName.Contains("EasyConnect")).ToList(); WindowInfo easyConnect = curEditList3.Where(c => { bool retVal = false; List <WindowInfo> allConnect = WindowFormAPI.GetAllDesktopWindows(c.hWnd); List <WindowInfo> existList = allConnect.Where(d => d.ItemId == 1001).ToList(); if (existList.Count > 0) { retVal = true; } return(retVal); }).FirstOrDefault(); List <WindowInfo> curConnectList = WindowFormAPI.GetAllDesktopWindows(easyConnect.hWnd); WindowInfo editHandler = curConnectList.Where(d => d.ItemId == 1001).FirstOrDefault(); StringBuilder s = new StringBuilder(512); //标题 //WindowFormAPI.GetWindowText(editHandler.hWnd, s, s.Capacity); WindowFormAPI.GetDlgItemText(editHandler.hWnd, editHandler.ItemId, s, s.Capacity); editHandler.szWindowName = s.ToString(); //List<WindowInfo> curEditList2 = newList.Where(c => !string.IsNullOrEmpty(c.szClassName) && c.szClassName.Contains("ComboBox")).ToList(); #endregion } catch (Exception ex) { } }
/// <summary> /// pin码登陆 /// </summary> public void DoLogin() { try { CloseProcess(); Process.Start(Config.SangforCSClientPath); Thread.Sleep(15000); List <WindowInfo> list = WindowFormAPI.GetAllDesktopWindows().ToList(); List <WindowInfo> newwindows = list.Where(c => c.szWindowName.Contains("EasyConnect")).ToList(); int i = 0; foreach (var item in newwindows) { i++; IntPtr curtab1 = WindowFormAPI.GetDlgItem(item.hWnd, 1002); IntPtr curtab2 = WindowFormAPI.GetDlgItem(item.hWnd, 1086); IntPtr curtab3 = WindowFormAPI.GetDlgItem(item.hWnd, 1091); if (curtab1 != IntPtr.Zero && curtab2 != IntPtr.Zero && curtab3 != IntPtr.Zero) { WindowFormAPI.SetForegroundWindow(item.hWnd); int tab1 = WindowFormAPI.FindWindowEx(item.hWnd.ToInt32(), 0, "SysTabControl32", null); int tab2 = WindowFormAPI.FindWindowEx(item.hWnd.ToInt32(), 1, "SysTabControl32", null); int tab3 = WindowFormAPI.FindWindowEx(item.hWnd.ToInt32(), 2, "SysTabControl32", null); if (tab1 != 0) { IntPtr sureBtn = WindowFormAPI.GetDlgItem(item.hWnd, 1086); this.SubmitBtnHandler = sureBtn; if (!string.IsNullOrEmpty(Config.VPNUser) && !string.IsNullOrEmpty(Config.VPNPassword)) { #region 解析账号密码 IntPtr fatherInt = new IntPtr(tab1); List <int> childWindowList = WindowFormAPI.GetChildWindows(tab1); foreach (var curitem in childWindowList) { IntPtr curIntPtr = new IntPtr(curitem); int itemId = WindowFormAPI.GetDlgCtrlID(curIntPtr); //用户名 if (itemId == 1009) { WindowFormAPI.SetForegroundWindow(item.hWnd); WindowFormAPI.SendMessage(curIntPtr, WindowFormAPI.WM_SETTEXT, IntPtr.Zero, Config.VPNUser); curEasyConnect = curIntPtr; WindowFormAPI.SetForegroundWindow(curIntPtr); curhWnd = item.hWnd; MoveLeftTopSide(); continue; } //密码 if (itemId == 1010) { WindowFormAPI.SetForegroundWindow(item.hWnd); WindowFormAPI.SendMessage(curIntPtr, WindowFormAPI.WM_SETTEXT, IntPtr.Zero, Config.VPNPassword); MoveLeftTopSide(); continue; } //验证码-输入文本框 if (itemId == 1011) { WindowFormAPI.SetForegroundWindow(item.hWnd); MoveLeftTopSide(); this.imgCodeTextHandler = curIntPtr; continue; } //验证码-图片 if (itemId == 1022) { WindowFormAPI.SetForegroundWindow(item.hWnd); this.imgCodeHandler = curIntPtr; MoveLeftTopSide(); continue; } //验证码切换 if (itemId == 1023) { WindowFormAPI.SetForegroundWindow(item.hWnd); this.changeImgCodeBtnHandler = curIntPtr; MoveLeftTopSide(); continue; } } #endregion } Submit(); } } } } catch (Exception ex) { SetText(ex.Message); } }