Have a look at:
http://forums.vb-world.net/showthrea...threadid=19278
Printable View
Have a look at:
http://forums.vb-world.net/showthrea...threadid=19278
Thanks a lot Kedaman, I'm going to work with it.
Regards.
If you want to display Icons for ALL file types, then use the ExtractAssociatedIcon() API, i.e.Code:Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Sub Command1_Click()
Dim lIcon As Long
On Error GoTo User_Cancelled
With CommonDialog1
.CancelError = True
.DialogTitle = "Select a File..."
.Filter = "All Files (*.*)|*.*"
.ShowOpen
Picture1 = LoadPicture()
Picture1.AutoRedraw = True
lIcon = ExtractAssociatedIcon(App.hInstance, .FileName, -1)
Call DrawIconEx(Picture1.hdc, 0, 0, lIcon, 32, 32, 0, 0, 3)
Picture1 = Picture1.Image
DestroyIcon lIcon
End With
User_Cancelled:
End Sub
That's great, Aaron, youre always providing code!
but i have a qwestion, what's the point with this:
Picture1 = LoadPicture()
In my code I'm making the Icon I draw onto the Picturebox Persistent so you can't clear it using the Cls Method, using LoadPicture() loads an empty image into the Picturebox, effectively clearing it.
Ok i see, i just wondered why you would need it to be persistent? Doesn't it drain more performance?
That depends on the size of the Image and what it's going to be used for.
In my example I'm just displaying a single Icon in a Picturebox, so it's not hogging resources.
Making it persistent is just something I've gotten into the habit of doing, as usually with these examples I get asked,
"How can I stop the picture being erased when the Form/Picturebox is Repainted?".
But won't just using autoredraw solve that problem?
Hi Aaron:
It works perfectly, thanks a lot to both.
Best regards ! ! !