
Edit: Actually srod's code below is even better.
Code: Select all
Procedure.s RegistryReadKey(hKey,path$,key$="")
Protected lpData.s{128}, lpcbData = 128, Result${1024}
If RegOpenKeyEx_(hKey,path$,#Null,#KEY_READ,@hKey) = #ERROR_SUCCESS
If RegQueryValueEx_(hKey,key$,#Null,#Null,@lpData,@lpcbData) = #ERROR_SUCCESS
Result$ = PeekS(@lpData,lpcbData)
EndIf
RegCloseKey_(hkey)
EndIf
ProcedureReturn Result$
EndProcedure
Procedure GetDefaultIcon(extension$)
Protected program$, icon$, iconPath$, iconNumber, iconHandle
program$ = RegistryReadKey(#HKEY_CLASSES_ROOT,"."+extension$)
icon$ = RegistryReadKey(#HKEY_CLASSES_ROOT,program$+"\DefaultIcon")
icon$ = RemoveString(icon$,#DQUOTE$)
;Debug program$+" "+icon$
If CountString(icon$,",")
iconPath$ = StringField(icon$,1,",")
iconNumber = Val(StringField(icon$,2,","))
Else
iconPath$ = icon$
iconNumber = 0
EndIf
iconHandle = ExtractIcon_(0,iconPath$,iconNumber)
;ExtractIconEx_(iconPath$,iconNumber,0,@iconHandle,1): iconHandle = PeekL(@iconHandle)
ProcedureReturn iconHandle ;remember to use DestroyIcon_() to clean up
EndProcedure
OpenWindow(0,0,0,100,50,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
icon = GetDefaultIcon("txt")
If icon
StartDrawing(WindowOutput(0))
DrawImage(icon,5,5)
StopDrawing()
DestroyIcon_(icon)
Else
Debug "No icon found for this filetype."
EndIf
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow