sherrick123
asked on
.net IExtractImage... one more time "Where is the .Net GURU"
Here is my code snipit. of course it does not work (why would I be asking for help.)
All I want to do is get the thumbnail of the file slected from my list box and display it
with my image control. HELP....
Private Sub lstDgnFiles_SelectedIndexC
Try
Dim myCurFile As FileInfo
Dim myShellImg As New IShellFolderEx_TLB.FOLDERS
Dim myNextTry As IExtractImage2Lib.IExtract
Dim myother As IExtractImage2Lib.IUnknown
Dim trythis As VariantType '
Dim ipld As Integer
myCurFile = lstDgnFiles.SelectedItem.F
trythis = myNextTry.GetLocation(myCu
imgPreview.Image = myNextTry.Extract(trythis)
Ooh, there's one of the top .NET gurus right there :))
Bob
Bob
ASKER
Does this only work for Image Files. I want to get the same image as what the Windows Explorer displays.
That is why I am sure I have to use the IExtractImage function.
Hope this explains what I am wanting.
if you want to extract image from executable file, there are plenty of programs like that on the internet. Search google.
ASKER
Nope that is not what I want to do. I want to get the image from ANY file that can display a thumbnail.
in Window Explorer. In my form I am only displaying a certain file. When the user pics that file I want it to display the image of that file. Such as windows explorer does. I am just sure that I have to use IExtractImage BUT there is no .net examples. I don't know C++ and the VB 6 example that I found doesn't work in .net. I have to develope this in .net
try this. It will give you file assosiated icons
Add a listView control, a button control, and an imageList control to the form.
The default names are ListView1, Button1, and ImageList1, respectively.
In the Properties window of Button1, set the button text to Select a File
Imports System.Runtime.InteropServ ices
Public Class Form1
Inherits System.Windows.Forms.Form
Private Structure SHFILEINFO
Public hIcon As IntPtr ' : icon
Public iIcon As Integer ' : icondex
Public dwAttributes As Integer ' : SFGAO_ flags
<MarshalAs(UnmanagedType.B yValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.B yValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
(ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As IntPtr
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1
Private Const SHGFI_LARGEICON = &H0 ' Large icon
Private nIndex = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListView1 As System.Windows.Forms.ListV iew
Friend WithEvents Button1 As System.Windows.Forms.Butto n
Friend WithEvents ImageList1 As System.Windows.Forms.Image List
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Cont ainer
Me.ListView1 = New System.Windows.Forms.ListV iew
Me.Button1 = New System.Windows.Forms.Butto n
Me.ImageList1 = New System.Windows.Forms.Image List(Me.co mponents)
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Location = New System.Drawing.Point(0, 0)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(720, 160)
Me.ListView1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 168)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Select File"
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.TransparentC olor = System.Drawing.Color.Trans parent
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(724, 314)
Me.Controls.Add(Me.Button1 )
Me.Controls.Add(Me.ListVie w1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hImgSmall As IntPtr 'The handle to the system image list.
Dim hImgLarge As IntPtr 'The handle to the system image list.
Dim fName As String 'The file name to get the icon from.
Dim shinfo As SHFILEINFO
shinfo = New SHFILEINFO
Dim openFileDialog1 As OpenFileDialog
openFileDialog1 = New OpenFileDialog
openFileDialog1.InitialDir ectory = "c:\temp\"
openFileDialog1.Filter = "All files (*.*)|*.*"
openFileDialog1.FilterInde x = 2
openFileDialog1.RestoreDir ectory = True
ListView1.SmallImageList = ImageList1
ListView1.LargeImageList = ImageList1
shinfo.szDisplayName = New String(Chr(0), 260)
shinfo.szTypeName = New String(Chr(0), 80)
If (openFileDialog1.ShowDialo g() = DialogResult.OK) Then
fName = openFileDialog1.FileName
'Use this to get the small icon.
hImgSmall = SHGetFileInfo(fName, 0, shinfo, _
Marshal.SizeOf(shinfo), _
SHGFI_ICON Or SHGFI_SMALLICON)
'Use this to get the large icon.
'hImgLarge = SHGetFileInfo(fName, 0,
'ref shinfo, (uint)Marshal.SizeOf(shinf o),
'SHGFI_ICON | SHGFI_LARGEICON);
'The icon is returned in the hIcon member of the
'shinfo struct.
Dim myIcon As System.Drawing.Icon
myIcon = System.Drawing.Icon.FromHa ndle(shinf o.hIcon)
ImageList1.Images.Add(myIc on) 'Add icon to
'imageList.
ListView1.Items.Add(fName, nIndex) 'Add file name and
'icon to listview.
nIndex = nIndex + 1
End If
End Sub
End Class
Add a listView control, a button control, and an imageList control to the form.
The default names are ListView1, Button1, and ImageList1, respectively.
In the Properties window of Button1, set the button text to Select a File
Imports System.Runtime.InteropServ
Public Class Form1
Inherits System.Windows.Forms.Form
Private Structure SHFILEINFO
Public hIcon As IntPtr ' : icon
Public iIcon As Integer ' : icondex
Public dwAttributes As Integer ' : SFGAO_ flags
<MarshalAs(UnmanagedType.B
Public szDisplayName As String
<MarshalAs(UnmanagedType.B
Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
(ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As IntPtr
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1
Private Const SHGFI_LARGEICON = &H0 ' Large icon
Private nIndex = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListView1 As System.Windows.Forms.ListV
Friend WithEvents Button1 As System.Windows.Forms.Butto
Friend WithEvents ImageList1 As System.Windows.Forms.Image
<System.Diagnostics.Debugg
Me.components = New System.ComponentModel.Cont
Me.ListView1 = New System.Windows.Forms.ListV
Me.Button1 = New System.Windows.Forms.Butto
Me.ImageList1 = New System.Windows.Forms.Image
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Location = New System.Drawing.Point(0, 0)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(720, 160)
Me.ListView1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 168)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Select File"
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.TransparentC
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(724, 314)
Me.Controls.Add(Me.Button1
Me.Controls.Add(Me.ListVie
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hImgSmall As IntPtr 'The handle to the system image list.
Dim hImgLarge As IntPtr 'The handle to the system image list.
Dim fName As String 'The file name to get the icon from.
Dim shinfo As SHFILEINFO
shinfo = New SHFILEINFO
Dim openFileDialog1 As OpenFileDialog
openFileDialog1 = New OpenFileDialog
openFileDialog1.InitialDir
openFileDialog1.Filter = "All files (*.*)|*.*"
openFileDialog1.FilterInde
openFileDialog1.RestoreDir
ListView1.SmallImageList = ImageList1
ListView1.LargeImageList = ImageList1
shinfo.szDisplayName = New String(Chr(0), 260)
shinfo.szTypeName = New String(Chr(0), 80)
If (openFileDialog1.ShowDialo
fName = openFileDialog1.FileName
'Use this to get the small icon.
hImgSmall = SHGetFileInfo(fName, 0, shinfo, _
Marshal.SizeOf(shinfo), _
SHGFI_ICON Or SHGFI_SMALLICON)
'Use this to get the large icon.
'hImgLarge = SHGetFileInfo(fName, 0,
'ref shinfo, (uint)Marshal.SizeOf(shinf
'SHGFI_ICON | SHGFI_LARGEICON);
'The icon is returned in the hIcon member of the
'shinfo struct.
Dim myIcon As System.Drawing.Icon
myIcon = System.Drawing.Icon.FromHa
ImageList1.Images.Add(myIc
'imageList.
ListView1.Items.Add(fName,
'icon to listview.
nIndex = nIndex + 1
End If
End Sub
End Class
ASKER
I don't need the Icons. I want the image that is displayed for a file when you select the "thumbnail" view from the windows explorer. If there was more documents on how to use the IExtractImage function this would help.
I think you are talking about something like this
http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/article.asp
http://www.codeproject.com/shell/thumbextract.asp
http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/article.asp
http://www.codeproject.com/shell/thumbextract.asp
This has C# code in the last section. It may help
http://www.codetoad.com/asp.net_thumbnails.asp
http://www.codetoad.com/asp.net_thumbnails.asp
And, there's another guru. Wow, they just keep comin' and comin' :))
the main guru TheLearnedOne is silent and watching :)
He is waiting untill the rest will be exhausted. Then he as usual will come up with his brilliant ideas :)
"A man's gotta know his limitations". Watching and learning :)
Bob
Bob
Only sky is the limit!!!!!!!
come on iboutchkine :) This is all literal things.. There are no limits to human wisdom/knowledge :)
Thanks guys for sharing your thoughts and your knowledge BTW =:)
Bob
Bob
ASKER
Well their were some good examples on extracting a thumbnail image BUT since that is not what I was needing help on I would say this problem is unsolvable. I wanted to see and VB .Net example on using IExtractImage to get ANY file Thumbnail view such as windows XP show in the Folder->View option.
Yes there was some c++ examples but since I don't know c++ that was of no use.
Thanks for everyones help. This must be one tough problem.
Yes there was some c++ examples but since I don't know c++ that was of no use.
Thanks for everyones help. This must be one tough problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents picThumb As System.Windows.Forms.Pictu
Friend WithEvents btnGenerateThumbNail As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.picThumb = New System.Windows.Forms.Pictu
Me.btnGenerateThumbNail = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'picThumb
'
Me.picThumb.Location = New System.Drawing.Point(45, 12)
Me.picThumb.Name = "picThumb"
Me.picThumb.Size = New System.Drawing.Size(166, 128)
Me.picThumb.SizeMode = System.Windows.Forms.Pictu
Me.picThumb.TabIndex = 0
Me.picThumb.TabStop = False
'
'btnGenerateThumbNail
'
Me.btnGenerateThumbNail.Lo
Me.btnGenerateThumbNail.Na
Me.btnGenerateThumbNail.Si
Me.btnGenerateThumbNail.Ta
Me.btnGenerateThumbNail.Te
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(258, 208)
Me.Controls.Add(Me.btnGene
Me.Controls.Add(Me.picThum
Me.FormBorderStyle = System.Windows.Forms.FormB
Me.MaximizeBox = False
Me.Name = "frmMain"
Me.StartPosition = System.Windows.Forms.FormS
Me.Text = "Generate Thumbnail Test"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnGenerateThumbNail_Click
' NOTE*** This code does not use proper error handling.
' Create the variables to hold the origional image and it's thumbnail.
Dim objImage As New Bitmap(Application.Startup
Dim objThumbnail As Bitmap
' Create the thumbnail image and assign it to the objThumbnail variable.
objThumbnail = objImage.GetThumbnailImage
' Display the thumbnail in a picturebox.
Me.picThumb.Image = objThumbnail
' Now lets save the the thumbnail to C:\testthumbnail.jpg
objThumbnail.Save("C:\temp
End Sub
End Class