| Article | 70000180 |
| Type | Wish |
| Product | Engine |
| Date Added | 11/27/2014 12:00:00 AM |
| Fixed | (11/27/2014 12:00:00 AM) |
| Submitted by | Steven Smith |
Summary
DrawImage method of vdrawI5 vdRender of vdraw ocx to support icons
Solution
Added in 7002.0.5
Example in VB
In the folowing example we get the associated icon handle of a file on the disk and draw it on the screen of VectorDraw.
Const SHGFI_ATTRIBUTES = &H800 ' get attributes
Const SHGFI_DISPLAYNAME = &H200 ' get display name
Const SHGFI_EXETYPE = &H2000 ' return exe type
Const SHGFI_ICON = &H100 ' get icon
Const SHGFI_ICONLOCATION = &H1000 ' get icon location
Const SHGFI_LARGEICON = &H0 ' get large icon
Const SHGFI_LINKOVERLAY = &H8000 ' put a link overlay on icon
Const SHGFI_OPENICON = &H2 ' get open icon
Const SHGFI_PIDL = &H8 ' pszPath is a pidl
Const SHGFI_SELECTED = &H10000 ' show icon in selected state
Const SHGFI_SHELLICONSIZE = &H4 ' get shell size icon
Const SHGFI_SMALLICON = &H1 ' get small icon
Const SHGFI_SYSICONINDEX = &H4000 ' get system icon index
Const SHGFI_TYPENAME = &H400 ' get type name
Const SHGFI_USEFILEATTRIBUTES = &H10 ' use passed dwFileAttribute
Private Type SHFILEINFO
hIcon As Long ' out: icon
iIcon As Long ' out: icon index
dwAttributes As Long ' out: SFGAO_ flags
szDisplayName As String * 260 ' out: display name (or path)
szTypeName As String * 80 ' out: type name
End Type
Private Type PICTDESC
cbSize As Long
pictType As Long
hIcon As Long
hPal As Long
End Type
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lpPictDesc As PICTDESC, riid As Any, ByVal fOwn As Long, ipic As IPicture) As Long
''a variable to keep the selected icon
Dim ipic As IPictureDisp
''convert an Icon Handle into a IPictureDisp (supported by DrawImage method of VectorDraw)
Function IconToPicture(ByVal hIcon As Long) As Picture
Dim pic As PICTDESC
Dim guid(0 To 3) As Long
' initialize the PictDesc structure
pic.cbSize = Len(pic)
pic.pictType = vbPicTypeIcon
pic.hIcon = hIcon
' this is the IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
' we use an array of Long to initialize it faster
guid(0) = &H7BF80980
guid(1) = &H101ABF32
guid(2) = &HAA00BB8B
guid(3) = &HAB0C3000
' create the picture,
' return an object reference right into the function result
OleCreatePictureIndirect pic, guid(0), True, IconToPicture
End Function
''returns an IPictureDisp from an assosiative Icon with an existing file on disk
Function GetIcon(filename As String, icon_size As Long) As IPictureDisp
Dim index As Integer
Dim hIcon As Long
Dim item_num As Long
Dim icon_pic As IPictureDisp
Dim sh_info As SHFILEINFO
SHGetFileInfo filename, 0, sh_info, Len(sh_info), SHGFI_ICON + icon_size
hIcon = sh_info.hIcon
Set icon_pic = IconToPicture(hIcon)
Set GetIcon = icon_pic
End Function
Private Sub Form_Load()
''Set ipic = Empty
''un-freeze the events in order drawafter to be fired.
VDraw1.FreezeDrawEvents 0
End Sub
Private Sub Test_Click()
''get the handle of the large icon of a file type.
Set ipic = GetIcon("D:\VectorDrawDrawings\test.pdf", SHGFI_LARGEICON)
''redraw so the DrawAfter will be fired and the icon will be drawn
VDraw1.Redraw
End Sub
Private Sub VDraw1_DrawAfter(ByVal Render As VDrawI5.vdRender)
Dim pt As VDrawI5.vdxyz
Set pt = VDraw1.CreateInstance(OBJ_XYZ)
pt.x = 0
pt.y = 0
pt.z = 0
''pt is in World coordinate system
Render.DrawImage ipic, pt, 1
End Sub
