Hi,
I am developing a document management system in MS Access (adp on top
of SQL Server). One thing I would like to do in my listview is show the
default icon associated in Windows with that specific file extension
(e.g. show the excel icon when my file has an xls-extension as Windows
Explorer does).
I found some neat VB-code to extract the default icon from the Windows
Registry ( http://www.developerfusion.co.uk/show/2982/) and assign it to
a PictureBox. So, this basically does what I want, except for the fact
that I cannot do this in VBA since it uses a PictureBox's hDC. VBA does
not have a PictureBox and the closest control being an ImageControl has
no hDC.
Did anybody ever try to do the same or know how to tackle this?
Thanks,
Mike 6 4844
Mike I just searched GoogleGroups and back in 2004 I Emailed code to a
poster to convert a handle to an Icon file to a StdPicture object.
Unfortuntately I cannot find the code. I used ExtractIcon to get a handle to
the Icon. Then you use OleCreatePictur eIndirect to convert the hIcon to a
StdPicture object.
--
HTH
Stephen Lebans http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Mike" <mi************ *@hotmail.comwr ote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .
Hi,
I am developing a document management system in MS Access (adp on top
of SQL Server). One thing I would like to do in my listview is show the
default icon associated in Windows with that specific file extension
(e.g. show the excel icon when my file has an xls-extension as Windows
Explorer does).
I found some neat VB-code to extract the default icon from the Windows
Registry (http://www.developerfusion.co.uk/show/2982/) and assign it to
a PictureBox. So, this basically does what I want, except for the fact
that I cannot do this in VBA since it uses a PictureBox's hDC. VBA does
not have a PictureBox and the closest control being an ImageControl has
no hDC.
Did anybody ever try to do the same or know how to tackle this?
Thanks,
Mike
Stephen,
Thanks for the hint. I have been searching a little and came up with
the following.
In a seperate module:
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type uPicDesc
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Declare Function OleCreatePictur eIndirect Lib "olepro32.d ll" _
(PicDesc As uPicDesc, _
RefIID As GUID, _
ByVal fPictureOwnsHan dle As Long, _
IPic As IPicture) As Long
Const CF_BITMAP = 2
Const CF_PALETTE = 9
Const IMAGE_BITMAP = 0
Const LR_COPYRETURNOR G = &H4
Const PICTYPE_BITMAP = 1
Dim strPictureFile As String
Public Function GetIconFromHand le(ByVal Handle As Long) As StdPicture
Dim IID_IDispatch As GUID
Dim uPicinfo As uPicDesc
Dim IPic As IPicture
Dim hPtr As Long
'Create the interface GUID for the picture
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
'Fill uPicInfo with necessary parts.
With uPicinfo
.Size = Len(uPicinfo)
.Type = PICTYPE_BITMAP
.hPic = hPtr
.hPal = 0
End With
'Create the picture object
OleCreatePictur eIndirect uPicinfo, IID_IDispatch, True, IPic
Set GetIconFromHand le = IPic
End Function
Public Function GetIcon(strExte nsion As String) As StdPicture
'Needs additional exception and error handling
Dim strFileType As String
Dim strIconFile As String
Dim lngIconHandle As Long
Dim lngIconNumber As Long
'Search the registry for the file type associated with this extension
(e.g. Word.Document.8 )
strFileType = RegValue(HKEY_C LASSES_ROOT, "." & strExtension,
vbNullString)
'Search the registry for the default icon associated with this file
type (e.g. C:\Windows\...\ wordicon.exe,1)
strIconFile = RegValue(HKEY_C LASSES_ROOT, strType & "\DefaultIc on",
vbNullString)
'Trim the icon number out of this string (e.g. 1)
lngIcoNumber = Trim(Right(strI conFile, Len(strIconFile ) -
InStrRev(strIco nFile, ",")))
'Trim the icon file out of this string (e.g.
C:\Windows\...\ wordicon.exe)
strIconFile = Trim(Left(strIc onFile, Len(strIconFile ) -
InStrRev(strIco nFile, ",")))
'Get a handle to this icon
lngIconHandle = ExtractIcon(Me. hwnd, strIconFile, lngIconNumber)
'Create a picture from this handle and return it
Set GetIcon = GetIconFromHand le(lngIconHandl e)
End Function
In my form, I currently have the following to add a file from a textbox
(txtFile) to an imagelist (lstMain) and show the file in a listview
lvwDocuments:
Private Sub cmdLoadFile_Cli ck()
Dim strTemp As String
strTemp = Right(Me.txtFil e, Len(Me.txtFile) - InStrRev(Me.txt File,
"."))
Me.lstMain.List Images.Add , strTemp, GetIcon(strTemp )
Me.lvwDocuments .ListItems.Add , , Me.txtFile, strTemp
End Sub
What I currently receive in the listview, is a black icon. So,
something is going wrong, but I do not understand where. Would you have
a clue?
Thanks,
Mike
PICTYPE_ICON = 3
--
HTH
Stephen Lebans http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Mike" <mi************ *@hotmail.comwr ote in message
news:11******** *************@m 58g2000cwm.goog legroups.com...
Stephen,
Thanks for the hint. I have been searching a little and came up with
the following.
In a seperate module:
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type uPicDesc
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Declare Function OleCreatePictur eIndirect Lib "olepro32.d ll" _
(PicDesc As uPicDesc, _
RefIID As GUID, _
ByVal fPictureOwnsHan dle As Long, _
IPic As IPicture) As Long
Const CF_BITMAP = 2
Const CF_PALETTE = 9
Const IMAGE_BITMAP = 0
Const LR_COPYRETURNOR G = &H4
Const PICTYPE_BITMAP = 1
Dim strPictureFile As String
Public Function GetIconFromHand le(ByVal Handle As Long) As StdPicture
Dim IID_IDispatch As GUID
Dim uPicinfo As uPicDesc
Dim IPic As IPicture
Dim hPtr As Long
'Create the interface GUID for the picture
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
'Fill uPicInfo with necessary parts.
With uPicinfo
.Size = Len(uPicinfo)
.Type = PICTYPE_BITMAP
.hPic = hPtr
.hPal = 0
End With
'Create the picture object
OleCreatePictur eIndirect uPicinfo, IID_IDispatch, True, IPic
Set GetIconFromHand le = IPic
End Function
Public Function GetIcon(strExte nsion As String) As StdPicture
'Needs additional exception and error handling
Dim strFileType As String
Dim strIconFile As String
Dim lngIconHandle As Long
Dim lngIconNumber As Long
'Search the registry for the file type associated with this extension
(e.g. Word.Document.8 )
strFileType = RegValue(HKEY_C LASSES_ROOT, "." & strExtension,
vbNullString)
'Search the registry for the default icon associated with this file
type (e.g. C:\Windows\...\ wordicon.exe,1)
strIconFile = RegValue(HKEY_C LASSES_ROOT, strType & "\DefaultIc on",
vbNullString)
'Trim the icon number out of this string (e.g. 1)
lngIcoNumber = Trim(Right(strI conFile, Len(strIconFile ) -
InStrRev(strIco nFile, ",")))
'Trim the icon file out of this string (e.g.
C:\Windows\...\ wordicon.exe)
strIconFile = Trim(Left(strIc onFile, Len(strIconFile ) -
InStrRev(strIco nFile, ",")))
'Get a handle to this icon
lngIconHandle = ExtractIcon(Me. hwnd, strIconFile, lngIconNumber)
'Create a picture from this handle and return it
Set GetIcon = GetIconFromHand le(lngIconHandl e)
End Function
In my form, I currently have the following to add a file from a textbox
(txtFile) to an imagelist (lstMain) and show the file in a listview
lvwDocuments:
Private Sub cmdLoadFile_Cli ck()
Dim strTemp As String
strTemp = Right(Me.txtFil e, Len(Me.txtFile) - InStrRev(Me.txt File,
"."))
Me.lstMain.List Images.Add , strTemp, GetIcon(strTemp )
Me.lvwDocuments .ListItems.Add , , Me.txtFile, strTemp
End Sub
What I currently receive in the listview, is a black icon. So,
something is going wrong, but I do not understand where. Would you have
a clue?
Thanks,
Mike
It gives me invalid picture now when trying to load it into the
imagelist.
On 30 jan, 04:50, "Stephen Lebans" <ForEmailGotoMy .WebSite.-
WWWdotlebansdot ...@linvalid.co mwrote:
PICTYPE_ICON = 3
Have you stepped through your code? What are the values of the variables
invlovled in the function calls that fails?
--
HTH
Stephen Lebans http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Mike" <mi************ *@hotmail.comwr ote in message
news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
It gives me invalid picture now when trying to load it into the
imagelist.
On 30 jan, 04:50, "Stephen Lebans" <ForEmailGotoMy .WebSite.-
WWWdotlebansdot ...@linvalid.co mwrote:
>PICTYPE_ICON = 3
Mike,
I am dealing with this same issue, have you resolved this? I have
searched hi and low but it seems that nobody has ever posted a
completed solution.
Thanks for your time,
Scott This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: drum118 |
last post by:
Has anyone experience problems with firewall blocking some icons and not
others.
I am using Zone alarm and have the popup set for medium and it was
blocking some of the icons for some strange reason that I have not seen
before.
Any reason why they are been blocked as well not showing up on view
source as I am at a lost?
|
by: sto |
last post by:
look at this picture
http://upload.cs99.net/e.gif
i use the function SHGetFileInfo to get file icons. but these icons
are not very nice. there are some black things round of the icons.
many applications use system icons for files. how did their
programmers solve this problem in these apps?
|
by: B-Dog |
last post by:
Does anyone know where I can find some professional looking icons that are
the standard windows collection for developers? The ones that came on the
VS cd are pretty lame. Thanks
|
by: Brett |
last post by:
I'd like references on where to find some good (quality) icons to use for
form and application icons (for the EXE). Most of the free stuff isn't that
great looking and there isn't a good selection. A site offering previews of
icons or purchase of a single icon would be nice.
Thanks,
Brett
|
by: quest |
last post by:
I created windows application using C#. I tried to replace the default
application icon by replacing the app.ico file in the project directory but
the application still load the old icon. Can someone helps ? Thanks.
| |
by: SharpCoderMP |
last post by:
i'm trying to embed multiple program icons in my executable. the only
way so far i managed to do that is to embed native win32 resource file
with multiple icons. it works, but... when i create a native win32
resource file with the VS 2005 and put there my icons, VS always
converts some of the 32bit icons into 24bit - so i loose alpha blending
what makes my icons look ugly.
I did an experiment and created a icon file with full range of...
|
by: Pucca |
last post by:
HI, I'm using vs2005. There are very few icons I found in the folder of
vs2005imagelibrary under the install folder of vs2005. Does anyone know
where I can download icons that are typically used in the toolstripmenu?
Icons like exit, copy, back and forward arrow.....
Also, can I use all these icons in my application?
--
Thanks.
|
by: Ronald S. Cook |
last post by:
We're creating an Outlook-style Windows app that will have icons in it. I
was just wondering if there was a Microsoft product that I could use to
create icons. I'm not a graphics person but I have an MSDN subscription so
I can get most Microsoft software. I was going to see how far I could get.
Thanks,
Ron
|
by: John |
last post by:
Is there such a thing as storing icons or bitmaps into a resource
file, and adding more icons or bitmaps into the resource file at
runtime?
I want to store a bunch of icons into a resource file, and at runtime
I want to be able to add more icons as I need to add. I don't want
to use an imagelist because that will be a set number of icons in the
program.
|
by: Sanoski |
last post by:
This might be a dumb question. I don't know. I'm new to all this. How
do you find icons for your programs? All GUI applications have cool
icons that represent various things. For instance, to save is often
represented as a disk, etc. You know, the small little picture
references that give meaning to the phrase 'Graphical User Interface'.
But I'm not a graphics artist! Drawing is simply one talent that
skipped me completely. Where can I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |