This repository has been archived by the owner on Apr 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
FrxItem.cls
148 lines (126 loc) · 3.73 KB
/
FrxItem.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cFrxItem"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'
' Copyright © 1997-1999 Brad Martinez, http://www.mvps.org
'
Private Const MAX_PATH = 260
Private Type SHFILEINFO ' sfi
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * MAX_PATH
szTypeName As String * 80
End Type
' Retrieves information about an object in the file system, such as a file,
' a folder, a directory, or a drive root.
Private Declare Function SHGetFileInfo Lib "shell32" Alias "SHGetFileInfoA" _
(ByVal pszPath As Any, _
ByVal dwFileAttributes As Long, _
psfi As SHFILEINFO, _
ByVal cbFileInfo As Long, _
ByVal uFlags As Long) As Long
' SHGetFileInfo uFlags
Private Const SHGFI_USEFILEATTRIBUTES = &H10 ' pretend pszPath exists, rtns BOOL
Private Const SHGFI_TYPENAME = &H400 ' sfi.szTypeName is filled, rtns BOOL
' ============================================================================
Public Enum PictureTypes
ptNone = 0
ptBMP = 1
ptDIB = 2
ptGIF = 3
ptJPG = 4
ptWMF = 5
ptEMF = 6
ptICO = 7
ptCUR = 8
End Enum
Private m_abItem() As Byte
Private m_dwSizeHdr As Long
Private m_dwFileOffset As Long
Private m_dwSizeImage As Long
Private m_dwPicType As PictureTypes
Private m_sTypeName As String
Private m_sExtension As String
'
Friend Sub Init(abBits() As Byte, dwSizeHdr, dwOffset As Long, dwSizeImage As Long, dwPicType As PictureTypes)
m_abItem = abBits
m_dwSizeHdr = dwSizeHdr
m_dwFileOffset = dwOffset
m_dwSizeImage = dwSizeImage
m_dwPicType = dwPicType
Call FillPictureInfo
End Sub
Public Property Get Bits() As Variant
Bits = m_abItem
End Property
Public Property Get HeaderSize() As Long
HeaderSize = m_dwSizeHdr
End Property
Public Property Get FileOffset() As Long
FileOffset = m_dwFileOffset
End Property
Public Property Get ImageSize() As Long
ImageSize = m_dwSizeImage
End Property
Public Property Get PictureType() As PictureTypes
PictureType = m_dwPicType
End Property
Public Property Get FileTypeName() As String
FileTypeName = m_sTypeName
End Property
Public Property Get FileExtension() As String
FileExtension = m_sExtension
End Property
Public Property Get Picture() As StdPicture
If m_dwPicType Then
Set Picture = PictureFromBits(m_abItem)
End If
End Property
Private Sub FillPictureInfo()
Dim sTypeName As String
Select Case m_dwPicType
Case ptBMP, ptDIB
m_sTypeName = "Bitmap Image"
m_sExtension = "bmp"
Case ptGIF
m_sTypeName = "GIF Image"
m_sExtension = "gif"
Case ptJPG
m_sTypeName = "JPEG Image"
m_sExtension = "jpg"
Case ptWMF
m_sTypeName = "Metatfile"
m_sExtension = "wmf"
Case ptEMF
m_sTypeName = "Enhanced Metatfile"
m_sExtension = "emf"
Case ptICO
m_sTypeName = "Icon File"
m_sExtension = "ico"
Case ptCUR
m_sTypeName = "Cursor File"
m_sExtension = "cur"
Case ptNone
m_sTypeName = "Binary data"
m_sExtension = "txt"
End Select
If m_dwPicType Then
sTypeName = GetFileTypeName("." & m_sExtension)
If Len(sTypeName) Then m_sTypeName = sTypeName
End If
End Sub
' If successful returns the specified file's typename, returns an empty string otherwise.
Private Function GetFileTypeName(sFile As String) As String
Dim sfi As SHFILEINFO
If SHGetFileInfo(sFile, 0, sfi, Len(sfi), SHGFI_TYPENAME Or SHGFI_USEFILEATTRIBUTES) Then
GetFileTypeName = GetStrFromBufferA(sfi.szTypeName)
End If
End Function