ExplorerListGadget & Large Icons [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

ExplorerListGadget & Large Icons [Windows]

Post by RASHAD »

Sharp & crisp 16 to 256 icons
Feel free to adapt

Code: Select all

Interface IImageList2 Extends IImageList
  DiscardImages(iFirstImage,iLastImage,dwFlags)
  ForceImagePresent(iImage,dwFlags)
  GetCallback(riid,*ppv) ;**ppv
  GetOriginalSize(iImage,dwFlags,*pcx,*pcy)
  GetStatistics(*pils)
  Initialize(cx,cy,flags,cInitial,cGrow)
  PreloadImages(*pimldp)
  Replace2(i,hbmImage,hbmMask,*punk,dwFlags)
  ReplaceFromImageList(i,*pil,iSrc,*punk,dwFlags)
  Resize(cxNewIconSize,cyNewIconSize)
  SetCallback(*punk)
  SetOriginalSize(iImage,cx,cy)  
EndInterface

Procedure NewListIcon(nSize)
  lib = OpenLibrary(#PB_Any, "Shell32.dll")
  If lib
    *Guid = ?IID_IImageList2
    CallFunction(lib, "SHGetImageList", #SHIL_JUMBO, *Guid, @ImageList.IImageList2)
    ImageList\GetImageCount(@count)
    iiList = ImageList_Create_(nSize,nSize,#ILC_COLOR32 |#ILC_MASK, 0, count)
    SendMessage_(GadgetID(1),#LVM_SETIMAGELIST,#LVSIL_NORMAL, iiList)
    For index = 0 To count
      ImageList\GetIcon(index, #ILD_TRANSPARENT, @icon)
      icon2 = CopyImage_(icon,#IMAGE_ICON	,nSize,nSize,0)
      ImageList_AddIcon_(iiList,icon2)    
      DestroyIcon_(icon)    
      DestroyIcon_(icon2)
    Next
  EndIf
  CloseLibrary(lib)
  SendMessage_(GadgetID(1), #LVM_SETIMAGELIST, #LVSIL_SMALL, iiList)
EndProcedure

Procedure Resizewindow_EX()
  ResizeGadget(10,#PB_Ignore,#PB_Ignore,WindowWidth(0)-20,WindowHeight(0)-50) 
  ResizeGadget(2,#PB_Ignore,#PB_Ignore,WindowWidth(0) - 38,WindowHeight(0)-68)
  ResizeGadget(3,#PB_Ignore,WindowHeight(0)-30,#PB_Ignore,#PB_Ignore)
EndProcedure

LoadFont(0,"Consolas",12)
ilsize = 256

If OpenWindow(0,0,0,600,400,"ExplorerListGadget & Large Imagelist",#PB_Window_SystemMenu| #PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered| #PB_Window_SizeGadget )
  SetWindowColor(0,$AAAAAB)
  ContainerGadget(10, 10, 10, 580, 350, #PB_Container_Raised)
    ExplorerTreeGadget(0, 0,0,0,0, "*.*",#PB_Explorer_NoFiles)
    ExplorerListGadget(1, 0,0,0,0, "",#PB_Explorer_NoFolders|#PB_Explorer_NoParentFolder)
    SplitterGadget(2, 5, 5, 562, 332, 0,1, #PB_Splitter_Vertical|#PB_Splitter_Separator)
    SetGadgetState(2,160)
  CloseGadgetList()
  HideGadget(10,1)    
  
  SetGadgetFont(0,FontID(0))
  SendMessage_(GadgetID(1),#LVM_SETVIEW,#LV_VIEW_ICON,0)
  
  iList = SendMessage_(GadgetID(1),#LVM_GETIMAGELIST,#LVSIL_NORMAL, 0)

  ButtonGadget(3,10,370,80,22,"Change IL")
  
  SetGadgetColor(0, #PB_Gadget_BackColor, $D2D2D2)
    
  lib = OpenLibrary(#PB_Any, "Shell32.dll")
  If lib
    *Guid = ?IID_IImageList2
    CallFunction(lib, "SHGetImageList", #SHIL_JUMBO, *Guid, @ImageList.IImageList2)
    ImageList\GetImageCount(@count)
    niList = ImageList_Create_(ilsize,ilsize,#ILC_COLOR32 |#ILC_MASK, 0, count)
    SendMessage_(GadgetID(1),#LVM_SETIMAGELIST,#LVSIL_NORMAL, niList)
    For index = 0 To count
      ImageList\GetIcon(index, #ILD_TRANSPARENT, @icon)
      icon2 = CopyImage_(icon,#IMAGE_ICON	,ilsize,ilsize,0)
      ImageList_AddIcon_(niList,icon2)    
      DestroyIcon_(icon)    
      DestroyIcon_(icon2)
    Next
  EndIf
  CloseLibrary(lib)

;SendMessage_(GadgetID(1), #LVM_SETIMAGELIST, #LVSIL_SMALL, niList)
HideGadget(10,0)    
BindEvent(#PB_Event_SizeWindow,@Resizewindow_EX()) 
Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      ImageList_Destroy_(niList) 
      Quit = 1
            
    Case #PB_Event_Gadget 
      Select EventGadget() 
        Case 0
          Select EventType()
             Case #PB_EventType_Change
               SetGadgetText(1,GetGadgetText(0))                                   
          EndSelect 
          
        Case 1
          Select EventType()
            Case #PB_EventType_LeftDoubleClick 
              ShellExecute_(0,"open",GetGadgetText(1)+GetGadgetItemText(1, GetGadgetState(1) ,0),0,0,1) 
            EndSelect 
                    
          Case 3
            Run ! 1
            If Run = 1
              ;NewListIcon(128)
              SendMessage_(GadgetID(1),#LVM_SETIMAGELIST,#LVSIL_NORMAL,iList)
            Else
              SendMessage_(GadgetID(1),#LVM_SETIMAGELIST,#LVSIL_NORMAL,niList)
            EndIf   
    EndSelect 
  EndSelect
Until Quit = 1 
EndIf 
  
DataSection
; IID_IImageList:
;   Data.l $46EB5926
;   Data.w $582E,$4017
;   Data.b $9F,$DF,$E8,$99,$8D,$AA,$09,$50
  
IID_IImageList2:
  Data.l $192B9D83
  Data.w $50FC,$457B
  Data.b $90,$A0,$2B,$82,$A8,$B5,$DA,$E1
EndDataSection
Egypt my love
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: ExplorerListGadget & Large Icons [Windows]

Post by RSBasic »

Very good. Image

But it only displays small icons for archive files:
Image
Image
Image
Post Reply