Page 1 of 1

[Windows] Customize the icon of a system folder.

Posted: Thu Jan 25, 2007 5:54 am
by Flype
Code updated for 5.20+

http://msdn2.microsoft.com/en-us/library/aa969337.aspx

Code: Select all

Procedure CustomizeFolder(FolderName.s, IconName.s) ; Customize the icon of the specified folder.
 
  If Right(FolderName, 1) <> "\"
    FolderName + "\"
  EndIf
 
  Protected FileID = CreateFile(#PB_Any, FolderName + "Desktop.ini")
 
  If FileID
    WriteStringN(FileID, "[.ShellClassInfo]")
    WriteStringN(FileID, "IconFile=" + IconName)
    WriteStringN(FileID, "IconIndex=0")
    CloseFile(FileID)
  EndIf
 
  If FileSize(FolderName + "Desktop.ini")
    ProcedureReturn PathMakeSystemFolder_(FolderName)
  EndIf
 
EndProcedure


; Specify here the folder to customize with the desired icon.

If CustomizeFolder(#PB_Compiler_Home, #PB_Compiler_Home + "Examples\Sources - Advanced\MoviePlayer\Icons\MoviePlayer.ico")
  MessageRequester("Information", "OK")
EndIf

Posted: Thu Jan 25, 2007 1:24 pm
by netmaestro
Wonderful tip Flype, thanks for sharing it.

Posted: Thu Jan 25, 2007 1:34 pm
by Kaeru Gaman

Posted: Thu Jan 25, 2007 2:53 pm
by Flype
hrrm what ?

Sorry if it was already posted but i don't understand german at all.

Here is the french-forum link from which i found the response by myself :
http://www.purebasic.fr/french/viewtopic.php?t=6253

Posted: Thu Jan 25, 2007 2:55 pm
by Kaeru Gaman
:lol: :D

so it seems it's a common topic at the moment... 8)

Posted: Thu Jan 25, 2007 3:02 pm
by Flype
yes it's true.

german forum seems very alive and instructive.

Re: [Windows] Customize the icon of a system folder.

Posted: Sat Jan 27, 2007 4:13 am
by PB
> PathMakeSystemFolder_(FolderName)

Is this really needed? Seems to work fine without it, and I also have another
app installed (Adobe Premiere v6.5) which has its folder as a custom icon and
that folder isn't set to System type; so it makes me think it's not necessary?

Posted: Sat Jan 27, 2007 4:44 am
by ts-soft
@PB
Readonly flags works also. Without any flag, it doesn't work

Posted: Sat Jan 27, 2007 5:05 am
by Flype
Well, my own tests reveals that PathMakeSystemFolder is mandatory on my system (XP SP2).
It doesn't work without this API function but maybe that depends of the windows version - i don't know.

Also this is recommended by MSDN :
http://msdn.microsoft.com/library/defau ... custom.asp

maybe i'm wrong...

Posted: Sat Jan 27, 2007 5:15 am
by PB
See my sig... I'm using XP SP2 too. :)

But if MSDN says to make it a System folder, then I shall too.
BTW, thanks for this tip -- it's a good one!