/// <summary> /// 获取参数名与控件句柄间的对应关系 /// </summary> /// <param name="container">用于查找本页的保存按钮</param> /// <param name="controlList">控件句柄列表</param> private void GetKeyRelation(IntPtr container, List <IntPtr> controlList) { IntPtr finding = IntPtr.Zero; RECT keyRect, findedRect; StringBuilder className = new StringBuilder(256); for (int keyIndex = 0; keyIndex < _keyRelation.Count; keyIndex++) { finding = (IntPtr)_keyRelation[keyIndex].Value; _keyRelation[keyIndex] = new KeyValuePair <string, object>(_keyRelation[keyIndex].Key, IntPtr.Zero); NativeApi.GetWindowRect(finding, out keyRect); List <IntPtr> list = null; for (int i = 0; i < controlList.Count; i++) { NativeApi.GetWindowRect(controlList[i], out findedRect); if (findedRect.Top <= keyRect.Top && findedRect.Bottom >= keyRect.Bottom) { list = _keyRelation[keyIndex].Value as List <IntPtr>; if (list == null) { list = new List <IntPtr>(); _keyRelation[keyIndex] = new KeyValuePair <string, object>(_keyRelation[keyIndex].Key, list); } list.Add(controlList[i]); controlList.RemoveAt(i); i--; } else { int diffrent = (findedRect.Top + findedRect.Bottom) / 2 - (keyRect.Top + keyRect.Bottom) / 2; if (diffrent <= 8 && diffrent >= -8) { list = _keyRelation[keyIndex].Value as List <IntPtr>; if (list == null) { list = new List <IntPtr>(); _keyRelation[keyIndex] = new KeyValuePair <string, object>(_keyRelation[keyIndex].Key, list); } list.Add(controlList[i]); controlList.RemoveAt(i); i--; } } if (list != null) { ControlSorter.SortControlList(list); // 将与指定参数名称在同一行的控件按从左到右的顺序排列 } } } }
public override void InitHandle() { List <IntPtr> listBoxes = new List <IntPtr>(); StringBuilder className = new StringBuilder(256); NativeApi.EnumChildWindows(base.HWnd, (hwnd, lParam) => { className.Clear(); NativeApi.GetClassName(hwnd, className, 255); string classNameStr = className.ToString(); if (classNameStr.StartsWith(CCCFillManager.LISTBOXClassName)) { listBoxes.Add(hwnd); } else if (classNameStr.StartsWith(CCCFillManager.ComboBoxClassName)) { comboBox = hwnd; } else if (classNameStr.StartsWith(CCCFillManager.ButtonClassName)) { StringBuilder text = className.Clear(); NativeApi.GetWindowText(hwnd, text, 255); if (text.ToString() == "完成") { finish = hwnd; } else if (text.ToString() == "并装") { multiInstall = hwnd; } } return(listBoxes.Count == 0 || finish == IntPtr.Zero || multiInstall == IntPtr.Zero || comboBox == IntPtr.Zero); }, IntPtr.Zero); ControlSorter.SortControlList(listBoxes); listBox = listBoxes[0]; }