[API] Display Associated File ICON.

  • Thread starter Thread starter ALESSANDRO Baraldi
  • Start date Start date
A

ALESSANDRO Baraldi

[POSTED ALSO to :microsoft.public.access.modulesdaovba]

Hi all.
Can i display on my Form the File's associated ICON ...?

I Have single view Form each Record have a Path of my File
and i need to display the associated ICON.

I try to use SHGetFileInfo, and without PictureBox, i try
to use Stephen Lebans PictureBox emulator, but no good
results.....!

I have some difficulties to adapt Metod or Properies of
clsPictureBox to display my ICO associated file.

I don't know if i have some other way to do this with NO
external OCX or DLL....!

I'll be great to any suggest.

Thanks.
 
Is it a StdPicture object that is returned from the SHGetFileInfo API?
If so you can simply use the Render method of the StdPicture object onto
the hDC of the vbPictureBox class. Something like:

hStdPic.Render CLng(hDCvbPictureBoxClass), 0&, 0&, CLng(ImageWidth),
CLng(ImageHeight), _
0&, hStdPic.Height, hStdPic.Width, -hStdPic.Height, vbNull

Alternatively, the LoadJpegGif MDB on my site contains a function named
"StdPictoImageData" which directly converts a StdPicture object to a
format suitable for the PictureData property of an Image control.
http://www.lebans.com/loadjpeggif.htm
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


ALESSANDRO Baraldi said:
[POSTED ALSO to :microsoft.public.access.modulesdaovba]

Hi all.
Can i display on my Form the File's associated ICON ...?

I Have single view Form each Record have a Path of my File
and i need to display the associated ICON.

I try to use SHGetFileInfo, and without PictureBox, i try
to use Stephen Lebans PictureBox emulator, but no good
results.....!

I have some difficulties to adapt Metod or Properies of
clsPictureBox to display my ICO associated file.

I don't know if i have some other way to do this with NO
external OCX or DLL....!

I'll be great to any suggest.

Thanks.

--
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------- -----
http://www.sitocomune.com/
http://www.mantuanet.it/alessandro.baraldi/
----------------------------------------------------------------------
 
Stephen Lebans said:
Is it a StdPicture object that is returned from the SHGetFileInfo API?
If so you can simply use the Render method of the StdPicture object onto
the hDC of the vbPictureBox class. Something like:

hStdPic.Render CLng(hDCvbPictureBoxClass), 0&, 0&, CLng(ImageWidth),
CLng(ImageHeight), _
0&, hStdPic.Height, hStdPic.Width, -hStdPic.Height, vbNull

Alternatively, the LoadJpegGif MDB on my site contains a function named
"StdPictoImageData" which directly converts a StdPicture object to a
format suitable for the PictureData property of an Image control.
http://www.lebans.com/loadjpeggif.htm

Hi Stephen....!
Is it a StdPicture object that is returned from the SHGetFileInfo API?
I don't think so....., reading on API GUIDE i find:

SHGFI_ICON(Parameter passed to api call)
Retrieves the handle of the icon that represents the file and the index of
the icon within the system image list. The handle is copied to the hIcon
member of the structure specified by psfi, and the index is copied to the
iIcon member.
**************************************************************

Now i use this way i get hdc of TextBox in my Form, so
i put hdc to ExtractAssociatedIcon and on my TsxtBox
i Have the ICO image:

'hIcon = ExtractIcon(hInst, Percorso, CLng(0))

Percorso = "D:\FileZilla_2_2_3_setup.exe"
hIcon = ExtractAssociatedIcon(hInst, Percorso, CLng(0))

DrawIcon hdc, 0, 0, hIcon



This way work good, the only truble is that if any object cover
my txtBox(just opening another Form the ICO_Image will be deleted, i need to
repaint Form.)

I have no more idea, i'm not much API_EXPERT.....!

Thanks.

Alessandro.
 
Why can you not simply call DrawIcon with the hDC from my PictureBox
class?

YOu cannot expect success using the hDC from a TextBox control as it is
drawn from a pool of DC's and will change every single time the TextBox
receives the focus.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Stephen Lebans said:
Why can you not simply call DrawIcon with the hDC from my PictureBox
class?

YOu cannot expect success using the hDC from a TextBox control as it is
drawn from a pool of DC's and will change every single time the TextBox
receives the focus.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Absolutly no.... i had some difficulties, for some my mistake
I don't know very well API sistem, and i don't know why but
when i passed hdc of clsPictureBox the icon it is not appeared...!

I use only On_load setting Properties of your DEMO, i add a CmdButton
in which i pass hdc to API, but no ICON...!

Have you some help to give me....?

thanks for the patience

Alessandro.
 
Post your code that gets the Icon, including all API
declarations/constants etc.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Stephen Lebans said:
Post your code that gets the Icon, including all API
declarations/constants etc.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


To test IT i use only your Form, i CLEAN all cmdButton, i store
only Load_Event Code and Unload......!!
I put only ONE cmdButton Comando1(Italian version of Command1)

Thanks in advance.
Alessandro(IT)

This is the code:

Option Compare Database
Option Explicit

Const GWL_HINSTANCE = (-6)

Private Declare Function GetWindowDC Lib "user32" _
(ByVal hWnd As Long) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function DrawIcon Lib "user32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As
Long) As Long

Private Declare Function ExtractIcon Lib "shell32.dll" _
Alias "ExtractIconA" _
(ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long

Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" _
Alias "ExtractAssociatedIconA" _
(ByVal hInst As Long, _
ByVal lpIconPath As String, _
ByRef lpiIcon As Integer) As Long

Private Declare Function GetFocus Lib "user32" _
() As Long

Private Declare Function DestroyIcon Lib "user32" _
(ByVal hIcon As Long) As Long


' Our PictureBox class
Private pb As clsPictureBox

' For scaling function
Private ScaleAmt As Single

Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Form_Load()
DoCmd.MoveSize 0, 0, 10500, 6350
' Realize an instance of our class
Set pb = New clsPictureBox
' You MUST set the ImageControl prop
pb.ImageControl = Me.Image0
' You MUST set the ImageForm prop
pb.ImageForm = Me
' Clear the Image control to FillColor
pb.Clear
' Set Unbound Text control
' Set our module Scale variable
ScaleAmt = 1
' Draw some text
pb.OutputText "TEST"
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set pb = Nothing
End Sub

Sub ApriIconDaDll()

Dim Percorso As String
Dim hInst As Long
Dim hIcon As Long

hInst = GetWindowLong(Application.hWndAccessApp, GWL_HINSTANCE)

Percorso = "D:\FileZilla_2_2_3_setup.exe"
hIcon = ExtractAssociatedIcon(hInst, Percorso, CLng(0))

DrawIcon pb.hdc, 0, 0, hIcon
DestroyIcon hIcon

End Sub

Private Sub Comando1_Click()

ApriIconDaDll

End Sub
 
Your code is fine and works but you simply forgot to tell the
vbPictureBox class to update the display after you render the Icon to
it's DC. Add this line of code after you call DrawIcon:

pb.DIBtoPictureData

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Stephen Lebans said:
Your code is fine and works but you simply forgot to tell the
vbPictureBox class to update the display after you render the Icon to
it's DC. Add this line of code after you call DrawIcon:

pb.DIBtoPictureData

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


It was in my mind that could be one forgetfulness......!!!!!

Good Night and many thanks again like always you are
gentleman....!

Alessandro(IT).
 
Back
Top