Page 1 of 1

Change folder icon

Posted: Sun Jan 30, 2022 6:23 pm
by AZJIO
Download: yadi.sk + ico.dll

Code: Select all

EnableExplicit

Global Path$
Global IcoPath$ = "C:\Windows\System32\Shell32.dll"

Procedure Seticon()
	Protected idxIcon, PathMem$, PathDesktop$, flgINI
	IcoPath$ = OpenFileRequester("Open file", IcoPath$, "exe, dll|*.exe;*.dll", 0)
	If Asc(IcoPath$)
		PathMem$ = Space(260)
		PokeS(@PathMem$, IcoPath$)
		If PickIconDlg_(0, @PathMem$, 260, @idxIcon)
			PathDesktop$ = Path$ + "desktop.ini"
			If FileSize(PathDesktop$) > 0
				SetFileAttributes(PathDesktop$, 0)
				flgINI = OpenPreferences(PathDesktop$, #PB_Preference_NoSpace)
			Else
				flgINI = CreatePreferences(PathDesktop$, #PB_Preference_NoSpace)
			EndIf
			If flgINI
				PreferenceGroup(".ShellClassInfo")
				WritePreferenceString("IconFile", PathMem$)
				WritePreferenceInteger("IconIndex", idxIcon)
				ClosePreferences()
				SetFileAttributes(PathDesktop$, #PB_FileSystem_ReadOnly | #PB_FileSystem_Hidden)
				SetFileAttributes(Path$, #PB_FileSystem_System)
			EndIf
		EndIf
	EndIf
EndProcedure

Path$ = ProgramParameter()
If Not FileSize(Path$) = -2
	Path$ = PathRequester("Open", GetHomeDirectory())
	If Not Asc(Path$)
		End
	EndIf
EndIf

If Right(Path$, 1) <> #PS$
	Path$ + #PS$
EndIf

Seticon()

Re: Change folder icon

Posted: Sun Jan 30, 2022 8:08 pm
by AZJIO
I managed to make the icon change instantly.

Code: Select all

EnableExplicit

#Library = 0
Global SHFCS2

Prototype.i ProtoSHFCS(*SHFCS, *Path, Flags.i = 2)

If OpenLibrary(#Library, "Shell32.dll")
	SHFCS2.ProtoSHFCS = GetFunction(#Library, "SHGetSetFolderCustomSettings")
EndIf

If Not SHFCS2
	End
EndIf

Structure SHFOLDERCUSTOMSETTINGS
	dwSize.l
	dwMask.l
	*pvid
	*pszWebViewTemplate
	cchWebViewTemplate.l
	*pszWebViewTemplateVersion
	*pszInfoTip
	cchInfoTip.l
	*pclsid
	dwFlags.l
	*pszIconFile
	cchIconFile.l
	iIconIndex.l
	*pszLogo
	cchLogo.l
EndStructure

; #FCS_READ = 1
#FCS_FORCEWRITE = 2
#FCSM_ICONFILE = $10
Global SHFCS.SHFOLDERCUSTOMSETTINGS

Global Path$ = "C:\folder"

With SHFCS
	\dwSize = SizeOf(SHFOLDERCUSTOMSETTINGS)
	\dwMask = #FCSM_ICONFILE
	\cchIconFile = 0
	\iIconIndex = 14
	\pszIconFile = @"C:\Windows\System32\Shell32.dll"
EndWith

SHFCS2(SHFCS, @Path$, #FCS_FORCEWRITE)