-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathExternalHeaderLib.ahk
348 lines (283 loc) · 8.83 KB
/
ExternalHeaderLib.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
Title: ExternalHeaderLib (v0.1 February 5, 2014)
Introduction
------------
'ExternalHeaderLib' enables to read the texts of the column headers from an external
ListView control or from an external Tab control.
It also enables to search for the presence of such control types in any external Window.
Compatibility
-------------
This lib was designed to run on AutoHotkey v1.0.48.04+ (32 and 64-bit)), on Windows 2000+.
Links
-----
Shell Functions
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776426%28v=vs.85%29.aspx
Process and Thread Functions
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684847%28v=vs.85%29.aspx
Memory Management Functions
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684847%28v=vs.85%29.aspx
Debugging Functions
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679303%28v=vs.85%29.aspx
About Messages and Message Queues
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx
Handle and Object Functions
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724461%28v=vs.85%29.aspx
Credit
------
unknown russian (xx-xx-xxxx) http://forum.script-coding.info/viewtopic.php?pid=26126#p26126
YMP (russian) (23-07-2009) http://forum.script-coding.com/viewtopic.php?id=3440
SysTabControl32x Ansi platform
entropic/leef_me (14-11-2009) SysTabControl32x Ansi platform
Lucid_Method (02-08-2011) SysHeader32x Ansi platform
Oldman (03-02-2014) SysTabControl32x and SysHeader32x
Ansi and Unicode (32 & 64-bits) platforms
How to used it
--------------
If you don't know the ClassNN of the control, call the GetExternalHeaderClassNN() function :
GetExternalClassNN(WinTitle),
the function returns an array with all the SysTabControl32x and all the SysHeader32x
classNN.
or
GetExternalClassNN(WinTitle, "SysTabControl32"),
the function returns an array with all the SysTabControl32x ClassNN.
or
GetExternalClassNN(WinTitle, "SysHeader32"),
the function returns an array with all the the SysHeader32x ClassNN.
if you konw the ClassNN of the control, call the GetExternalHeaderText() function :
GetExternalHeaderText(WinTitle),
the function returns an array with the text header of the default classNN (SysHeader321).
or
GetExternalHeaderText(WinTitle, "SysHeader322"),
the function returns an array with the text header of the "SysHeader322" ClassNN.
or
GetExternalHeaderText(WinTitle, "SysTabControl321"),
the function returns an array with the text header of the "SysTabControl321" ClassNN.
or ...
Changes
-------
0.1 11/02/2014 minor change
bugfix on the comparison of the Dll version, the 2nd majorVersion >= 5 -->
majorVersion >= 6.
change in the allocation of the virtual memory (4096 bytes instead of itemLen+MaxLen)
Author
------
JPV alias Oldman
*/
;---------------------------
; Get external header texts
;---------------------------
GetExternalHeaderText(_winTitle, _classNN="SysHeader321", MaxName=100) {
static XXX_GETITEMCOUNT
static XXX_GETITEM
static HDI_TEXT := 0x2
static HDM_GETITEMCOUNT := 0x1200
static HDM_GETITEMA := 0x1203
static HDM_GETITEMW := 0x120B
static TCIF_TEXT := 0x1
static TCM_GETITEMCOUNT := 0x1304
static TCM_GETITEMA := 0x1305
static TCM_GETITEMW := 0x133C
static MEM_COMMIT := 0x1000
static MEM_RESERVE := 0x2000
static MEM_DECOMMIT := 0x4000
static MEM_RELEASE := 0x8000
static PAGE_READWRITE := 0x4
static PROCESS_VM_OPERATION := 0x8
static PROCESS_VM_READ := 0x10
static PROCESS_VM_WRITE := 0x20
enum := []
if (A_OSType = WIN32_WINDOWS)
{
MsgBox, % A_ThisFunc " does not support OS " A_OSVersion ".`nMinimum supported Windows 2000."
return false
}
if ((classNN := SubStr(_classNN, 1, 11)) <> "SysHeader32")
{
if ((classNN := SubStr(_classNN, 1, 15)) <> "SysTabControl32")
{
MsgBox, % A_ThisFunc " does not support ClassNN " _classNN
return false
}
}
ControlGet, hHeader, Hwnd,, %_classNN%, %_winTitle%
if !hHeader
{
MsgBox, % A_ThisFunc " ControlGet Hwnd failed for " _classNN "`n" _winTitle
return false
}
;---------------------------------
; Get comctl32.dll version number
;---------------------------------
Ptr := A_IsUnicode ? "Ptr" : "UInt"
VarSetCapacity(dvi2, 32, 0)
NumPut(32, dvi2, 0, "UInt")
if DllCall("comctl32.dll\DllGetVersion", Ptr, &dvi2, "UInt")
{
MsgBox, % A_ThisFunc " DllGetVersion() failed " ErrorLevel
return false
}
majorVersion := NumGet(dvi2, 4, "UInt")
;-----------------
; Get process pid
;-----------------
WinGet, pid, PID, %_winTitle%
if !pid
{
MsgBox, % A_ThisFunc " WinGet PID failed for " _winTitle
return false
}
;--------------
; Open Process
;--------------
options := PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE
if !hProcess := DllCall("OpenProcess", "UInt", options, "Int", false, "UInt", pid)
{
MsgBox, % A_ThisFunc " OpenProcess() failed for " pid "`n" _winTitle " - " A_LastError
return
}
;----------------------------
; Calculate structure length
;----------------------------
if (classNN = "SysHeader32")
{
; UInt + Int + 2Ptr + 2Int + Ptr
itemLen := 16 + 3 * A_PtrSize
; + 2Int
if (majorVersion >= 3)
itemLen += 8
; + UInt + Ptr
if (majorVersion >= 5)
itemLen += 4 + A_PtrSize
; + UInt
if (majorVersion >= 6)
itemLen += 4
}
else if (classNN = "SysTabControl32")
{
; 3UInt + Ptr + 2Int + Ptr
itemLen := 12 + A_PtrSize + 8 + A_PtrSize
}
;-------------------------
; Allocate virtual memory
;-------------------------
if !pMem := DllCall("VirtualAllocEx", Ptr , hProcess
, Ptr , 0
, "UInt", 4096
, "UInt", MEM_COMMIT
, "UInt", PAGE_READWRITE)
{
MsgBox, % A_ThisFunc " VirtualAllocEx() failed for " _winTitle " - " A_LastError
gosub, CloseHandle
return false
}
;----------------------
; Write virtual memory
;----------------------
MaxLen := MaxName * (A_IsUnicode ? 2 : 1)
VarSetCapacity(buf, MaxLen, 0)
VarSetCapacity(item, itemLen, 0)
if (classNN = "SysHeader32")
{
NumPut(HDI_TEXT, item, 0, "UInt") ; mask
NumPut(pMem+itemLen, item, 8, Ptr) ; pszText
NumPut(MaxName, item, 8+2*A_PtrSize, "Int") ; cchTextMax
}
else if (classNN = "SysTabControl32")
{
NumPut(TCIF_TEXT, item, 0, "UInt") ; mask
NumPut(pMem+itemLen, item, 12, Ptr) ; pszText
NumPut(MaxName, item, 12+A_PtrSize, "Int") ; cchTextMax
}
if !DllCall("WriteProcessMemory", Ptr , hProcess
, Ptr , pMem
, Ptr , &item
, "UInt", itemLen
, "UInt", 0)
{
MsgBox, % A_ThisFunc " WriteProcessMemory() failed for " _winTitle " - " A_LastError
gosub, FreeMemory
gosub, CloseHandle
return false
}
;-----------------------
; Get number of columns
;-----------------------
if (classNN = "SysHeader32")
{
XXX_GETITEMCOUNT := HDM_GETITEMCOUNT
XXX_GETITEM := A_IsUnicode ? HDM_GETITEMW : HDM_GETITEMA
}
else if (classNN = "SysTabControl32")
{
XXX_GETITEMCOUNT := TCM_GETITEMCOUNT
XXX_GETITEM := A_IsUnicode ? TCM_GETITEMW : TCM_GETITEMA
}
SendMessage, XXX_GETITEMCOUNT, 0, 0,, ahk_id %hHeader%
if (ErrorLevel < 0 or ErrorLevel = "FAIL")
{
MsgBox, % A_ThisFunc " SendMessage GETITEMCOUNT(" XXX_GETITEMCOUNT ") failed for " _classNN
gosub, FreeMemory
gosub, CloseHandle
return false
}
nbItem := ErrorLevel
;-------------------------
; Get header column texts
;-------------------------
Loop, % nbItem
{
SendMessage, XXX_GETITEM, A_Index-1, pMem,, ahk_id %hHeader%
if !ErrorLevel
{
MsgBox, % A_ThisFunc " SendMessage GETITEM(" XXX_GETITEM ") failed for " _classNN
gosub, FreeMemory
gosub, CloseHandle
return false
}
if !DllCall("ReadProcessMemory", Ptr , hProcess
, Ptr , pMem+itemLen
, Ptr , &buf
, "UInt", MaxLen
, "UInt", 0)
{
MsgBox, % A_ThisFunc " ReadProcessMemory() failed for " _winTitle " - " A_LastError
gosub, FreeMemory
gosub, CloseHandle
return false
}
VarSetCapacity(buf, -1)
enum[A_Index] := buf
}
gosub, FreeMemory
gosub, CloseHandle
return enum
FreeMemory:
DllCall("VirtualFreeEx", Ptr, hProcess, Ptr, pMem, "UInt", 0, "UInt", MEM_DECOMMIT)
return
CloseHandle:
DllCall("CloseHandle", Ptr, hProcess)
return
}
;----------------------
; Get external ClassNN
;----------------------
GetExternalHeaderClassNN(_winTitle, _sysHeader="")
{
WinGet, ctrlList, ControlList, %_winTitle%
enum := []
i := 0
if _sysHeader
{
Loop, Parse, ctrlList, `n
if InStr(A_LoopField, _sysHeader)
enum[++i] := A_LoopField
}
else
{
Loop, Parse, ctrlList, `n
if InStr(A_LoopField, "SysHeader32")
or InStr(A_LoopField, "SysTabControl32")
enum[++i] := A_LoopField
}
return enum
}