- 超级版主
- 1228894
- 26809
- 25
- 7919 朵
- 35962 个
- 4579 个
- 421340
- 2012-07-18
|
1#
t
T
发表于 2022-02-24 23:49
|
|只看楼主
帖子说明:今天有人问了如何按下面图片示意1-9顺序获取句柄,然后我进入了深思
- 自带Window插件中Search、SearchEx;大漠EnumWindow命令获取的句柄均为乱序
- 1-9窗口是提问人随意摆的,并程序非打开的对应顺序,也无法通过程序打开的次序及对应PID获取句柄
 思路1:
- 获取窗口左上角图标的所有坐标,这样会返回9个坐标,在通过361窗口插件或大漠插件获取指定坐标的句柄
 
- 结论:可这样一个问题,图片被挡住了怎么办,我进入了牛角尖,然后我想了思路2
思路2:获取所有句柄,然后得到窗口左上角坐标,然后双for进行排序 - HwndEx = Plugin.Window.SearchEx(0,"记事本",0)
- MyArray = Split(HwndEx, "|")
- For i=0 to UBound(MyArray)-1
- sRect = Plugin.Window.GetClientRect(MyArray(i))
- 左上 = Split(sRect, "|")
- 左= Clng(左上(0)): 上 = Clng(左上(1))
- TracePrint "第 " & i + 1 & " 个窗口句柄为:" & MyArray(i) & "x坐标" & 左 & ",y坐标" & 上
- 重组信息=重组信息& MyArray(i)&"-"&左&","&上&"|"
- Next
- 重组信息= "|"&重组信息
- TracePrint 重组信息
- Sub tx()
- TracePrint now()
- TracePrint "1"
- For x = 1 To 1920
- For y = 1 To 1080
- If instr(重组信息,"-"& x & "," & y) > 0 Then
- TracePrint x&","&y
- TracePrint Split(split(重组信息,"-"&x&","&y)(0),"|")(1)
- End If
- Next
- Next
- TracePrint now()
- End Sub
- Call tx()
复制代码 思路3:通过计算谁离左上、中上、右上最近得出1-3,通过计算谁离左中,中中,右中得出4-6. ...调试结果: 源码一览:若有新思路 请跟帖 一起交流 作者QQ:414098315- t1 = Plugin.Sys.GetTime()
- HwndEx = Plugin.Window.SearchEx(0,"记事本",0)
- MyArray = Split(HwndEx, "|")
- For i=0 to UBound(MyArray)-1
- sRect = Plugin.Window.GetClientRect(MyArray(i))
- 左上 = Split(sRect, "|")
- 左 = Clng(左上(0)) : 上 = Clng(左上(1)) :下 = Clng(左上(3))
- 斜边 = (左 ^ 2 + 上 ^ 2) ^ 0.5
- 高度 = 下 - 上
- // TracePrint "第 " & i + 1 & " 个窗口句柄为:" & MyArray(i) & "x坐标" & 左 & ",y坐标" & 上
- If i = UBound(MyArray) - 1 Then
- 句柄信息 = 句柄信息 & MyArray(i)
- 斜边信息 = 斜边信息 & 斜边
- Y信息 = Y信息 & 上
- 窗口高度 = 窗口高度 & 高度
- Else
- 句柄信息 = 句柄信息 & MyArray(i) & "|"
- 斜边信息 = 斜边信息 & 斜边 & "|"
- Y信息 = Y信息 & 上 & "|"
- 窗口高度 = 窗口高度 & 高度 & "|"
- End If
- Next
- TracePrint 句柄排序(斜边信息, Y信息, 句柄信息,窗口高度)
- TracePrint CStr(Plugin.Sys.GetTime() - t1) +"毫秒"
- Function 句柄排序(data, str, hwnd,height)
- Dim 句柄重组
- data = Split(data, "|")
- yData = Split(str, "|")
- hwndData = Split(hwnd, "|")
- heightData = Split(height, "|")
- For i = 0 To UBound(data)-1
- For j = i + 1 To UBound(data)
- If CInt(data(i)) > CInt(data(j)) Then
- temp = data(j)
- data(j) = data(i)
- data(i) = temp
-
- temphwnd = hwndData(j)
- hwndData(j) = hwndData(i)
- hwndData(i) = temphwnd
-
- tempy = yData(j)
- yData(j) = yData(i)
- yData(i) = tempy
- End If
- Next
- Next
-
- For i = 0 To UBound(yData)-1
- For j = i + 1 To UBound(yData)
- If CInt(yData(i)) > CInt(yData(j)) and abs(CInt(yData(i)) - CInt(yData(j))) > CInt(heightData(i)) / 2 Then
- temphwnd = hwndData(j)
- hwndData(j) = hwndData(i)
- hwndData(i) = temphwnd
- End If
- Next
- Next
-
- For i = 0 To UBound(hwndData)
- If i = UBound(hwndData) Then
- 句柄重组 = 句柄重组 & hwndData(i)
- Else
- 句柄重组 = 句柄重组 & hwndData(i) & "|"
- End If
- Next
- 句柄排序 = 句柄重组
- End Function
复制代码
|