[Windows] Customize the icon of a system folder.

Share your advanced PureBasic knowledge/code with the community.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

[Windows] Customize the icon of a system folder.

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Wonderful tip Flype, thanks for sharing it.
BERESHEIT
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

oh... and have a nice day.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

:lol: :D

so it seems it's a common topic at the moment... 8)
oh... and have a nice day.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

yes it's true.

german forum seems very alive and instructive.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post 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?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@PB
Readonly flags works also. Without any flag, it doesn't work
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply