This repository was archived by the owner on Aug 13, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathWinAPI.vb
More file actions
448 lines (389 loc) · 16.2 KB
/
Copy pathWinAPI.vb
File metadata and controls
448 lines (389 loc) · 16.2 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
'**************************************************
' FILE : WinAPI.vb
' AUTHOR : Paulo.Santos
' CREATION : 2007.10.15
' COPYRIGHT : Copyright © 2007
' PJ on Development
' All Rights Reserved.
'
' Description:
' Public module for Win32API declaration and functions.
'
' Change log:
' 0.1 2007.10.15
' Paulo.Santos
' Created.
'***************************************************
Imports System.Text
Imports System.Runtime.InteropServices
''' <summary>
''' Defines several Win32 API functions.
''' </summary>
Friend Module WinAPI
#Region " Icon Functions "
''' <summary>
''' Enumerates the file attributes for the ShGetFileInfo method.
''' </summary>
Public Enum ShfiFileAttributes As Integer
''' <summary>
''' The file is read only.
''' </summary>
[ReadOnly] = &H1
''' <summary>
''' The file is hidden.
''' </summary>
Hidden = &H2
''' <summary>
''' The file is a system file.
''' </summary>
System = &H4
''' <summary>
''' The file is a directory.
''' </summary>
Directory = &H10
''' <summary>
''' The file is an archive.
''' </summary>
Archive = &H20
''' <summary>
''' The file is a device.
''' </summary>
Device = &H40
''' <summary>
''' The file has no specia attributes.
''' </summary>
Normal = &H80
''' <summary>
''' The file is temporary.
''' </summary>
Temporary = &H100
''' <summary>
''' The file is a sparse file.
''' </summary>
Sparse_File = &H200
Reparse_Point = &H400
''' <summary>
''' The file is compressed.
''' </summary>
Compressed = &H800
''' <summary>
''' The file is offline.
''' </summary>
Offline = &H1000
Not_Content_Indexed = &H2000
''' <summary>
''' The file is encrypted.
''' </summary>
Encrypted = &H4000
End Enum
''' <summary>
''' Enumerates all the flags used by the ShFileInfo structure.
''' </summary>
Public Enum ShgfiFlags As Integer
''' <summary>
''' Get large icon.
''' </summary>
LargeIcon = &H0
''' <summary>
''' Get small icon.
''' </summary>
SmallIcon = &H1
''' <summary>
''' Get open icon.
''' </summary>
OpenIcon = &H2
''' <summary>
''' Get shell size icon.
''' </summary>
''' <remarks></remarks>
ShellIconSize = &H4
''' <summary>
''' pszPath is a PIDL.
''' </summary>
PIDL = &H8
''' <summary>
''' Use passed dwFileAttribute.
''' </summary>
UseFileAttributes = &H10
''' <summary>
''' Apply the appropriate overlays.
''' </summary>
AddOverlays = &H20
''' <summary>
''' Get the index of the overlay in the upper 8 bits of the iIcon.
''' </summary>
OverlayIndex = &H40
''' <summary>
''' Get icon.
''' </summary>
Icon = &H100
''' <summary>
''' Get display name.
''' </summary>
DisplayName = &H200
''' <summary>
''' Get type name.
''' </summary>
TypeName = &H400
''' <summary>
''' Get attributes.
''' </summary>
Attributes = &H800
''' <summary>
''' Get icon location.
''' </summary>
IconLocation = &H1000
''' <summary>
''' Return exe type.
''' </summary>
ExeType = &H2000
''' <summary>
''' Get system icon index.
''' </summary>
SysIconIndex = &H4000
''' <summary>
''' Put a link overlay on icon.
''' </summary>
LinkOverlay = &H8000
''' <summary>
''' Show icon in selected state.
''' </summary>
Selected = &H10000
''' <summary>
''' Get only specified attributes.
''' </summary>
Attr_Specified = &H20000
End Enum
''' <summary>
''' Contains information about a file object.
''' </summary>
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure ShFileInfo
''' <summary>
''' Handle to the icon that represents the file.
''' </summary>
Public hIcon As IntPtr
''' <summary>
''' Index of the icon image within the system image list.
''' </summary>
Public iIcon As Integer
''' <summary>
''' Array of values that indicates the attributes of the file object.
''' </summary>
Public dwAttributes As Integer
''' <summary>
''' String that contains the name of the file as it appears in the
''' Microsoft Windows Shell, or the path and file name of the file
''' that contains the icon representing the file.
''' </summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
''' <summary>
''' String that describes the type of file.
''' </summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
''' <summary>
''' Retrieves information about an object in the file system,
''' such as a file, a folder, a directory, or a drive root.
''' </summary>
''' <param name="pszPath">
''' Pointer to a null-terminated string of maximum length
''' MAX_PATH that contains the path and file name.
''' Both absolute and relative paths are valid.
''' </param>
''' <param name="dwFileAttributes"></param>
''' <param name="psfi"></param>
''' <param name="cbFileInfo"></param>
''' <param name="uFlags"></param>
''' <returns></returns>
''' <remarks></remarks>
<DllImport("shell32.dll", CharSet:=CharSet.Auto)> _
Public Function SHGetFileInfo(ByVal pszPath As String, ByVal dwFileAttributes As ShfiFileAttributes, ByRef psfi As ShFileInfo, ByVal cbFileInfo As Integer, ByVal uFlags As ShgfiFlags) As IntPtr
End Function
''' <summary>
''' Extract an icon from a file.
''' </summary>
''' <param name="szFileName">The name of the file to extract the icon from.</param>
''' <param name="nIconIndex">The index of the icon inside the file.</param>
''' <param name="phiconLarge">
''' Pointer to an array of icon handles that receives handles to
''' the large icons extracted from the file. If this parameter is NULL,
''' no large icons are extracted from the file.</param>
''' <param name="phiconSmall">
''' Pointer to an array of icon handles that receives handles to
''' the small icons extracted from the file. If this parameter is NULL,
''' no small icons are extracted from the file.</param>
''' <param name="nIcons">Specifies the number of icons to extract from the file.</param>
''' <returns>If the <i>nIconIndex</i> parameter is -1, the <i>phiconLarge</i>
''' parameter is NULL, and the <i>phiconSmall</i> parameter is NULL,
''' then the return value is the number of icons contained in the specified file. <br/>
''' Otherwise, the return value is the number of icons successfully extracted from the file.</returns>
<DllImport("shell32.dll", CharSet:=CharSet.Auto)> _
Public Function ExtractIconEx(ByVal szFileName As String, ByVal nIconIndex As Integer, ByVal phiconLarge() As IntPtr, ByVal phiconSmall() As IntPtr, ByVal nIcons As UInteger) As UInteger
End Function
''' <summary>
''' Destroys an icon and frees any memory the icon occupied.
''' </summary>
''' <param name="hIcon">Handle to the icon to be destroyed. The icon must not be in use.</param>
''' <returns>If the function succeeds, returns True.
''' <p/>
''' If the function fails, returns False. To get extended error information, call GetLastError.</returns>
<DllImport("user32.dll", SetLastError:=True)> _
Public Function DestroyIcon(ByVal hIcon As IntPtr) As Boolean
End Function
#End Region
#Region " SendMessage Variants "
'*
'* All the SendMessage variants use
'* System.Int32 in order to prevent
'* possible errors using this code
'* on 64 bits machines.
'*
#Region " Messages Enumerator "
''' <summary>
''' Enumerates possible messages.
''' </summary>
''' <remarks>
''' This list will be increased as the need arises.
''' </remarks>
Public Enum SendMessageList As Int32
''' <summary>
''' Gets the first visible line of multi-line a TextBox or
''' the first visible character of a single-line TextBox.
''' </summary>
EM_GetFirstVisibleLine = &HCE
''' <summary>
''' Forces a TextBox to scroll an specified number of lines.
''' </summary>
''' <remarks>
''' The number of lines to scroll is specified on the lParam
''' and the SendMessage function returns the number of
''' lines actually scrolled.
''' </remarks>
EM_LineScroll = &HB6
End Enum
#End Region
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As HandleRef, _
ByVal Msg As SendMessageList, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As IntPtr
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As HandleRef, _
ByVal Msg As SendMessageList, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As SendMessageList, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As IntPtr
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As SendMessageList, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As HandleRef, _
ByVal Msg As SendMessageList, _
ByVal wParam As IntPtr, _
ByRef lParam As StringBuilder) As IntPtr
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As HandleRef, _
ByVal Msg As SendMessageList, _
ByVal wParam As Int32, _
ByRef lParam As StringBuilder) As Int32
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As SendMessageList, _
ByVal wParam As IntPtr, _
ByRef lParam As StringBuilder) As IntPtr
End Function
''' <summary>
''' Sends the specified message to a window or windows.
''' </summary>
''' <param name="hWnd">Handle to the window whose window procedure will receive the message.</param>
''' <param name="Msg">Specifies the message to be sent.</param>
''' <param name="wParam">Specifies additional message-specific information.</param>
''' <param name="lParam">Specifies additional message-specific information.</param>
''' <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As SendMessageList, _
ByVal wParam As Int32, _
ByRef lParam As StringBuilder) As Int32
End Function
#End Region
End Module