Page 1 of 1

Get All FileType Icons (Registery Style)

Posted: Sun Jul 27, 2003 9:35 am
by Inner
Code updated for 5.20+

Code: Select all

#DEWINDOW=0
#DEGAD_COLUM=1

Structure SHELLICONLIST
  hLarge.l
  hSmall.l
  szTypeName.s
EndStructure

NewList silist.SHELLICONLIST()

If OpenWindow(#DEWINDOW, 0, 0,640,400,"SPACK", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  ListIconGadget(#DEGAD_COLUM,0,0,640,400,"Name",160,#LVS_AUTOARRANGE )       
  
  hKey.l
  If(RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Internet Explorer",0,#KEY_ALL_ACCESS,@hKey)=#ERROR_SUCCESS)
    buffer.s=Space(64)
    bufferlen.l=64               
    RegQueryValueEx_(hKey, "Version",#Null,#Null,@buffer.s,@bufferlen)
  EndIf
  RegCloseKey_(hKey);
  
  If(Mid(buffer,0,4)="6.0.")
    ;// Tries to manually grab the icon and information for ".cdf" by checking to
    ;// see if it is a registered file type then by finding the dll which the icon
    ;// is stored at   
    If(RegOpenKeyEx_(#HKEY_CLASSES_ROOT,"CLSID\{f39a0dc0-9cc8-11d0-a599-00c04fd64433}\InProcServer32",0,#KEY_ALL_ACCESS,@hKey)=#ERROR_SUCCESS)
      dwSize.l=256
      szValue.s=Space(256)
      If(RegQueryValue_(hKey,"",@szValue,@dwSize)=ERROR_SUCCESS)
        AddElement(silist())
        ExtractIconEx_(szValue,2,@silist()\hLarge,@silist()\hSmall,1)
        silist()\szTypeName=".cdf"            
      EndIf   
    EndIf
    RegCloseKey_(hKey);
  EndIf
  
  If(RegOpenKeyEx_(#HKEY_CLASSES_ROOT,"",0,#KEY_ENUMERATE_SUB_KEYS,@hKey)=#ERROR_SUCCESS)
    szName.s=Space(#MAX_PATH)
    dwBuf.l=#MAX_PATH
    shInfo.SHFILEINFO
    While(RegEnumKey_(hKey,dwIndex,@szName,@dwBuf)=0)
      dwIndex+1
      If(Mid(szName,0,1)=".")
        If(szName<>".cdf")
          SHGetFileInfo_(szName,FILE_ATTRIBUTE_NORMAL,@shInfo,SizeOf(SHFILEINFO),#SHGFI_USEFILEATTRIBUTES|#SHGFI_ICON|#SHGFI_SMALLICON)
          AddElement(silist())
          silist()\hSmall=shInfo\hIcon
          silist()\szTypeName=szName
          AddGadgetItem(#DEGAD_COLUM,-1,silist()\szTypeName,shInfo\hIcon)
        EndIf
      EndIf
    Wend       
  EndIf
  
  RegCloseKey_(hKey);
  
  Repeat
    EventID=WaitWindowEvent()
    
    If EventID = #PB_Event_SizeWindow
      If EventWindow() = 0
        ResizeGadget(#DEGAD_COLUM, -1, -1, WindowWidth(0), WindowHeight(0))
      EndIf
    EndIf
    
  Until EventID=#PB_Event_CloseWindow
  
  ResetList(silist())
  While NextElement(silist())
    If((silist()\hLarge)<>0)
      DestroyIcon_(silist()\hLarge)
    EndIf
    If((silist()\hSmall)<>0)
      DestroyIcon_(silist()\hSmall)
    EndIf
  Wend
  
EndIf

End

Posted: Sun Jul 27, 2003 11:10 am
by freak
Hmm, it doesn't find the *.pb extension, but that is obviously a registered
filetype on my system.

I think there are more than one places in registry where you can register
a filetype. Look at the editor source, to see where the *.pb extension
is stored at.

Timo

Posted: Sun Jul 27, 2003 11:14 am
by Inner
Would if I knew where the lastest source was for it :)

Posted: Sun Jul 27, 2003 11:18 am
by freak
http://cvs.purebasic.com/ (in Sources/Editor/)

or here:
http://www.reelmediaproductions.com/pb/ ... source.zip
...which is 3.70 Editor, but the filetype part hasn't changed anyway.

Look in 'PureBasic IDE.pb' a little after the 'Editor start' mark.

Timo

Posted: Sun Jul 27, 2003 11:22 am
by Inner
Thanks :)

Posted: Sun Jul 27, 2003 11:30 am
by GPI
btw:
Does your example only runs on WinXP/2000-Systems?

and i think, japbe use also a total diffrent methode to set his icons.

GPI

Posted: Sun Jul 27, 2003 11:37 am
by Inner
It's not for setting anything, it's for obtaining the icon data, for a filetype, so that they can be used in for example, a custom made file list.

I had to find a better method that my orginal code, which well :oops: lets say .. had a folder, that contained _many_ .extname.ico

Freak as always, thank you.. I was wondering how I was going to download all those files ;)

Posted: Sun Jul 27, 2003 1:35 pm
by Tranquil
works fine here on windows 2000 latest SP.