-
Notifications
You must be signed in to change notification settings - Fork 71
/
ShellLinkA.ahk
317 lines (259 loc) · 7.96 KB
/
ShellLinkA.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
/*
class: ShellLinkA
wraps the *IShellLinkA* interface and exposes methods that create, modify, and resolve Shell links.
Authors:
- maul.esel (https://github.com/maul-esel)
License:
- *LGPL* (http://www.gnu.org/licenses/lgpl-2.1.txt)
Documentation:
- *class documentation* (http://maul-esel.github.com/COM-Classes/master/ShellLinkA)
- *msdn* (http://msdn.microsoft.com/en-us/library/windows/desktop/bb774950)
Requirements:
AutoHotkey - AHK v2 alpha
OS - Windows XP / Windows 2000 Server or higher
Base classes - _CCF_Error_Handler_, Unknown
Constant classes - SLGP, SLR, SW
Structure classes - WIN32_FIND_DATA
*/
class ShellLinkA extends Unknown
{
/*
Field: CLSID
This is CLSID_ShellLink. It is required to create an instance.
*/
static CLSID := "{00021401-0000-0000-C000-000000000046}"
/*
Field: IID
This is IID_IShellLinkW. It is required to create an instance.
*/
static IID := "{000214F9-0000-0000-C000-000000000046}"
/*
Method: GetPath
Gets the path and file name of a Shell link object.
Parameters:
byRef STR path - receives the path and file name of the Shell link object.
UINT flags - a combination of flags that specify the type of path information to retrieve. You can use the fields of the SLGP class for convenience.
[opt] byRef WIN32_FIND_DATA data - receives a WIN32_FIND_DATA instance that contains information about the Shell link object.
Returns:
BOOL success - true on success, false otherwise
*/
GetPath(byRef path, flags, byRef data := 0)
{
local struct, bool
static MAX_PATH := 260, data_size := WIN32_FIND_DATA.GetRequiredSize()
struct := CCFramework.AllocateMemory(data_size), VarSetCapacity(path, MAX_PATH * 2, 0)
bool := this._Error(DllCall(NumGet(this.vt+03*A_PtrSize), "ptr", this.ptr, "str", path, "int", MAX_PATH, "ptr", struct, "uint", flags))
data := WIN32_FIND_DATA.FromStructPtr(struct)
return bool
}
/*
Method: GetIDList
Remarks:
Not implemented
*/
GetIDList(ByRef idlist)
{
;return DllCall(NumGet(this.vt+04*A_PtrSize), "Ptr", this.ptr, "Ptr", idlist)
}
/*
Method: SetIDList
Remarks:
Not implemented
*/
SetIDList(idlist)
{
;return DllCall(NumGet(this.vt+05*A_PtrSize), "Ptr", this.ptr, "Ptr", idlist)
}
/*
Method: GetDescription
Gets the description string for a Shell link object.
Parameters:
[opt] INT maxChars - the maximum number of characters to retrieve. By default 300.
Returns:
STR description - the description string.
*/
GetDescription(maxChars := 300)
{
local descr
VarSetCapacity(descr, maxChars * 2, 0)
this._Error(DllCall(NumGet(this.vt+06*A_PtrSize), "ptr", this.ptr, "str", descr, "int", maxChars))
return descr
}
/*
Method: SetDescription
Sets the description for a Shell link object. The description can be any application-defined string.
Parameters:
STR description - the new description string
Returns:
BOOL success - true on success, false otherwise
*/
SetDescription(description)
{
return this._Error(DllCall(NumGet(this.vt+07*A_PtrSize), "Ptr", this.ptr, "str", description))
}
/*
Method: GetWorkingDirectory
Gets the name of the working directory for a Shell link object.
Returns:
STR dir - the working directory
*/
GetWorkingDirectory()
{
local dir
static MAX_PATH := 260
VarSetCapacity(dir, MAX_PATH * 2, 0)
this._Error(DllCall(NumGet(this.vt+08*A_PtrSize), "Ptr", this.ptr, "str", dir, "Int", MAX_PATH))
return dir
}
/*
Method: SetWorkingDirectory
Sets the name of the working directory for a Shell link object.
Parameters:
STR dir - the name of the new working directory
Returns:
BOOL success - true on success, false otherwise
*/
SetWorkingDirectory(dir)
{
return this._Error(DllCall(NumGet(this.vt+09*A_PtrSize), "Ptr", this.ptr, "str", dir))
}
/*
Method: GetArguments
Gets the command-line arguments associated with a Shell link object.
Parameters:
[opt] INT maxChars - the maximum number of characters to retrieve. By default 300.
Returns:
STR args - the arguments
*/
GetArguments(maxChars := 300)
{
local args
VarSetCapacity(args, maxChars * 2, 0)
this._Error(DllCall(NumGet(this.vt+10*A_PtrSize), "Ptr", this.ptr, "str", args, "Int", maxChars))
return args
}
/*
Method: SetArguments
Sets the command-line arguments for a Shell link object.
Parameters:
STR args - the new command-line arguments
Returns:
BOOL success - true on success, false otherwise
*/
SetArguments(args)
{
return this._Error(DllCall(NumGet(this.vt+11*A_PtrSize), "Ptr", this.ptr, "str", args))
}
/*
Method: GetHotkey
Gets the keyboard shortcut (hot key) for a Shell link object.
Remarks:
Not implemented
*/
GetHotkey()
{
local hotkey
this._Error(DllCall(NumGet(this.vt+12*A_PtrSize), "Ptr", this.ptr, "short*", hotkey))
return hotkey
}
/*
Method: SetHotkey
Sets a keyboard shortcut (hot key) for a Shell link object.
Remarks:
Not implemented
*/
SetHotkey(hotkey)
{
return this._Error(DllCall(NumGet(this.vt+13*A_PtrSize), "Ptr", this.ptr, "short", hotkey))
}
/*
Method: GetShowCmd
Gets the show command for a Shell link object.
Returns:
INT cmd - an integer describing the show command. You can compare this to the fields of the SW class for convenience.
Supported commands include: SW.SHOWNORMAL, SW.SHOWMAXIMIZED, SW.SHOWMINNOACTIVE
*/
GetShowCmd()
{
local cmd
this._Error(DllCall(NumGet(this.vt+14*A_PtrSize), "Ptr", this.ptr, "int*", cmd))
return cmd
}
/*
Method: SetShowCmd
Sets the show command for a Shell link object. The show command sets the initial show state of the window.
Parameters:
INT cmd - an integer describing the show command. This must be one of the values listed under <GetShowCmd>.
Returns:
BOOL success - true on success, false otherwise
*/
SetShowCmd(cmd)
{
return this._Error(DllCall(NumGet(this.vt+15*A_PtrSize), "Ptr", this.ptr, "int", cmd))
}
/*
Method: GetIconLocation
Gets the location (path and index) of the icon for a Shell link object.
Parameters:
byRef STR path - receives the path of the file containing the icon
byRef INT index - receives the index of the icon
Returns:
BOOL success - true on success, false otherwise
*/
GetIconLocation(ByRef path, ByRef index)
{
static MAX_PATH := 260
VarSetCapacity(path, MAX_PATH * 2, 0)
return this._Error(DllCall(NumGet(this.vt+16*A_PtrSize), "Ptr", this.ptr, "str", path, "int", MAX_PATH, "int*", index))
}
/*
Method: SetIconLocation
Sets the location (path and index) of the icon for a Shell link object.
Parameters:
STR path - the path of the file containing the icon
INT index - the index of the icon
Returns:
BOOL success - true on success, false otherwise
*/
SetIconLocation(path, index)
{
return this._Error(DllCall(NumGet(this.vt+17*A_PtrSize), "Ptr", this.ptr, "str", path, "int", index))
}
/*
Method: SetRelativePath
Sets the relative path to the Shell link object.
Parameters:
STR path - the new relative path. It should be a file name, not a folder name.
Returns:
BOOL success - true on success, false otherwise
*/
SetRelativePath(path)
{
return this._Error(DllCall(NumGet(this.vt+18*A_PtrSize), "Ptr", this.ptr, "str", path, "uint", 0)) ; msdn: param 2 is reserved
}
/*
Method: Resolve
Attempts to find the target of a Shell link, even if it has been moved or renamed.
Parameters:
HWND hwnd - A handle to the window that the Shell will use as the parent for a dialog box. The Shell displays the dialog box if it needs to prompt the user for more information while resolving a Shell link.
UINT flags - action flags. You can use the fields of the SLR class for convenience.
Returns:
BOOL success - true on success, false otherwise
*/
Resolve(hwnd, flags)
{
return this._Error(DllCall(NumGet(this.vt+19*A_PtrSize), "ptr", this.ptr, "uptr", hwnd, "uint", flags))
}
/*
Method: SetPath
Sets the path and file name of a Shell link object.
Parameters:
STR path - the new path
Returns:
BOOL success - true on success, false otherwise
*/
SetPath(path)
{
return this._Error(DllCall(NumGet(this.vt+20*A_PtrSize), "Ptr", this.ptr, "str", path))
}
}