dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Get EXTRALARGE or JUMBO icons from the system image list to VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Location
    Stockholm, Sweden
    Posts
    27

    Resolved [RESOLVED] Get EXTRALARGE or JUMBO icons from the system image list to VB6

    I have found several samples on how to do this in C++ and .NET but no code directly for VB6. Has anybody got this done or can help me get it done in VB6?
    The common method to use SHGetFileInfo only is not good enough since it is limited to 16x16 and 32x32 sizes.
    To get the 48x48 or 256x256 icons you need to get the list using SHGetImageList with SHIL_EXTRALARGE or SHILJUMBO parameters. Then get the icon out of that one. The samples I have found include these:
    C++: (and C#)
    http://pogopixels.com/blog/getting-t...le-on-windows/
    Delphi:
    http://stackoverflow.com/questions/1...he-vista-shell

  2. #2
    Frenzied Member gibra's Avatar
    Join Date
    Oct 2009
    Location
    ITALY
    Posts
    1,685

    Re: Get EXTRALARGE or JUMBO icons from the system image list to VB6

    To get all image formats and depth colors you must work with 'resources'.

    see the EnumIconResources project here:
    http://www.vbcorner.net/eng/index.html page

    However VB6 is not compatible with icons 32bit (a.k.a XP icons).
    if you deal with this icons you need to use GDI+ library

    See LaVolpe projects for more info about this.






    http://www.vbcorner.net/eng/index.html

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Location
    Stockholm, Sweden
    Posts
    27

    Re: Get EXTRALARGE or JUMBO icons from the system image list to VB6

    Thanks for your reply gibra. However that is not what I am looking for. My goal is to get the icons associated with files, file types or folders from the system image lists, not ones held by resources or files. I checked your samples and the one dealing with this is called "GetIconAssociated" and it uses the SHGetFileInfo api call to achieve this. However that method is limited to the 16x16 and 32x32 icons. I am also aware of and have browsed LaVolpes excellent samples, but he does not seem to have any sample for this particular issue either.
    What I'm looking for is to get the system associated 48x48 or 256x256 icons directly from the system images lists (without disk access to the actual files).

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,697

    Re: Get EXTRALARGE or JUMBO icons from the system image list to VB6

    The following should do the trick. There are some caveats....

    1) The exported function on XP systems is broken and needs to be called by its ordinal (shown below); dependent on service pack. XP function export bug on MSDN
    2) I'd recommend not calling ordinals on other systems. So, use a version check in your routines: If XP then call by ordinal; if not, then call by Name. Both declarations are provided below. Edited: Tweaked code to prevent this need
    3) I don't know if IID_IImageList2 will ever need to be used for Vista, Win7 or above. But if it must, then I've given you the GUID for that too
    Code:
    Private Declare Function SHGetImageListXP Lib "Shell32.dll" Alias "#727" (ByVal iImageList As Long, ByRef riid As Long, ByRef ppv As Any) As Long
    Private Declare Function SHGetImageList Lib "Shell32.dll" (ByVal iImageList As Long, ByRef riid As Long, ByRef ppv As Any) As Long
    Private Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef lpiid As Any) As Long
    Private Declare Function ImageList_GetIcon Lib "comctl32.dll" (ByVal hIML As Long, ByVal i As Long, ByVal flags As Long) As Long
    Private Const IID_IImageList    As String = "{46EB5926-582E-4017-9FDF-E8998DAA0950}"
    Private Const IID_IImageList2   As String = "{192B9D83-50FC-457B-90A0-2B82A8B5DAE1}"
    Private Const SHIL_SMALL        As Long = 1 ' 16x16
    Private Const SHIL_LARGE        As Long = 0 ' 32x32
    Private Const SHIL_EXTRALARGE   As Long = 2 ' 48x48
    Private Const SHIL_JUMBO        As Long = 4 ' 256x256 (Vista+) & fails on XP or lower
    Private Const E_INVALIDARG      As Long = &H80070057
        
    
    Private Declare Function DrawIconEx Lib "user32.dll" (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.dll" (ByVal hIcon As Long) As Long
    
    Private Sub Command1_Click()
    
        Dim hIML As IUnknown
        Dim GUID(0 To 3) As Long
        Dim lResult As Long
    
        Dim lIconSize As Long
        lIconSize = SHIL_EXTRALARGE
        
        If IIDFromString(StrPtr(IID_IImageList), GUID(0)) = 0 Then
            On Error Resume Next
            lResult = SHGetImageList(lIconSize, GUID(0), ByVal VarPtr(hIML))
            Select Case lResult
            Case 0&
                If Err Then
                    Err.Clear
                    lResult = SHGetImageListXP(lIconSize, GUID(0), ByVal VarPtr(hIML))
                    If Err Then lResult = E_INVALIDARG ' assign any non-zero value; function not exported
                End If
            Case E_INVALIDARG
                ' possibly calling API with SHIL_JUMBO on XP?
            Case Else
                ' some other error
            End Select
            On Error GoTo 0
            If lResult = 0& Then
            
                ' assume you have the icon index you want; here we'll just use 5
                Dim hIcon As Long
                hIcon = ImageList_GetIcon(ObjPtr(hIML), 5, 0)
                If hIcon Then
                    DrawIconEx Me.hdc, 0, 0, hIcon, 0, 0, 0, 0, 3
                    DestroyIcon hIcon
                End If
            End If
        End If
        
    End Sub
    Edited. Modified the code to be 'version' safe. If calling the API by name fails, then it will attempt to call it by ordinal
    Per MSDN. The ordinal for that function "can be counted on to not change across operating system versions"
    Last edited by LaVolpe; Dec 27th, 2011 at 04:11 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Location
    Stockholm, Sweden
    Posts
    27

    Re: Get EXTRALARGE or JUMBO icons from the system image list to VB6

    Thank you LaVolpe, that worked excellent!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width