Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

kiu Icons manager: quickly change icon files


  • Please log in to reply
11 replies to this topic
kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
This program let you change any icon file in a very simple way.
The program is in a beta stage so use it at your own risk.
I used it and there was no problem
The program make use of toralf's Icon Viewer to browse icons, so many thanks to toralf

Another thing: this example shows how to get an icon for a specified file type without making use of dllcall, but only by reading the registry.
I'm not so familiar with dllcall, but for many functions AHK is here for us

the lines of codes for this purpose are:

;select an extension
ext=ahk
RegRead, from, HKEY_CLASSES_ROOT, .%ext%
RegRead, ico, HKEY_CLASSES_ROOT, %from%\DefaultIcon
;this is for icongroup files	
IfInString, ico, `,
	{
		StringSplit, n, ico, `,
		trim:=StrLen(n2)+1
		StringTrimRight, ico, ico, %trim%
	}
Gui,add,Picture, x+20  Icon%n2% w32 h-1 , %ico%
Gui,show

This is the program: (please send feedback if you are interested in it)
/*
	Author:
		Salvatore Agostino Romeo
		N.B.: this program make use of IconViewer v5 by toralf
	E-Mail:
		[email protected]
	Description:
		Do you know Microangelo?
		This program is an Icon manager. With it you can change any icon for a file 
		type in a very simple way. 
		Folder icon can be changed. You can change the icon for each folder separatly too.
		There is also a support for themes, but differently from other softwares, 
		in this program a theme is a folder containing some icons.
		The name of the icon is the file type to wich the icon will be associated.
		For example an icon named mp3.ico will cause all mp3 files to be shown with 
		that icon.
	Version:
		0.5.2 beta
	License:
		GPL
	Note:
		This is a beta version. Use it at your own risk
	ToDo: 
		1)Drag&Drop support to drop an icon file to the program window
		2)Support for special folders like My computer or Desktop
		3)Support for themes where a theme is a single zip file
		4)Define special names in a theme like "folder.ico" for the folder icon
		5)Documentation
		6)Rebuild icon cache:
			Just refresh the icon cache by deleting the IconCache.db
			file from your profile directory (usually /Documents and
			Settings/Username/Local Settings/Application Data). It 
			will be automatically recreated.
	Bugs:
		?
	History:
		24/04/2006 - added support to restore original icons
		
*/

#SingleInstance force
#NoTrayIcon
SetBatchLines -1
ScanStatus := False

If ( A_OSType = "WIN32_WINDOWS" )  ; Windows 9x
    ScanFolder = %A_WinDir%\system
else
    ScanFolder = %A_WinDir%\system32

Gui, Add, Text, Section , Scan folder
Gui, Add, Edit, ys-3 w245 r1 vScanFolder, %ScanFolder%
Gui, Add, Button, ys-5 gBtnBrowseFolder,&...
Gui, Add, Button, ys-5 w50 vBtnScan gBtnScan, &Scan
Gui, Add, Checkbox, ys vCkbRecursive , Rec&ursive

Gui, Add, ListView, xm r11 w480 -Multi AltSubmit List vLstOfFiles gLstOfFiles ,Icon Nr.1 & File name|Path

Gui, Add, Text, w140 vTxtFilesFound Section, 0000 files found, shown as
Gui, Add, Radio, ys gRadFilesReport ,&Report
Gui, Add, Radio, ys gRadFilesTile , &Tile
Gui, Add, Radio, ys gRadFilesIcons , &Icons
Gui, Add, Radio, ys gRadFilesSmallIcons ,s&mall Icons
Gui, Add, Radio, ys Checked gRadFilesList , &List

Gui, Add, ListView, xm r2 w480 -Multi AltSubmit Icon vLstOfIcons gLstOfIcons,Icon

Gui, Add, Text, w140 vTxtIconsFound Section, 0000 Icons found, shown as
Gui, Add, Radio, ys gRadIconsReport ,Report
Gui, Add, Radio, ys gRadIconsTile ,Til&e
Gui, Add, Radio, ys Checked gRadIconsIcons , Ic&ons
Gui, Add, Radio, ys gRadIconsSmallIcons ,sm&all Icons
Gui, Add, Radio, ys gRadIconsList , List

Gui,add,Text, xm  ys+40 Section, Select a file type
Gui,add,Edit, x+2 ys-3 vext gExtension
Gui,add,Text, x+2 , or:
Gui,add,button,x+20 gBtnASITSF, Apply Selected Icon to a specified Folder
Gui,add,button,x+5 gBtnSpecialIcons, Special Icons

Gui,add,Text, xm , from
Gui,add,Picture, x+20 vActualIcon Icon1 w32 h-1 , %ScanFolder%\shell32.dll
Gui,add,Text, x+20 , to
Gui,add,Picture, x+20 vNewIcon Icon1 w32 h-1 , %ScanFolder%\shell32.dll
Gui,add,Text, x+20 , ...
Gui,add,button,x+20 gBtnSet vBtnSet , Set
Gui,add,Text, x+20 , Original Icon:
Gui,add,Picture, x+20 vfirstIcon Icon1 w32 h-1 , %ScanFolder%\shell32.dll
Gui,add,button,x+20 gBtnRestore vBtnRestore , Restore
Gui, Add, Button, xm vBtnSpecialActions gBtnSpecialActions Section ,Special Action
Gui, Add, Button, ys gBtnClose,&Close
Gui, Show, , Icon Viewer v5
Return
;#############   End of autoexec section   ####################################

BtnSpecialActions:
	Menu,sf,add
	Menu,sf,deleteall
	Menu,sf,add,Set a theme, saction
	Menu,sf,add,Refresh icon cache(beta), saction
	Menu,sf,show
return
saction:
	if(A_ThisMenuItemPos=1)
		{
			FileSelectFolder, fold, , , Select the folder containg all the icons.    N.B.: A theme is a folder containing several icons whose name is the file type for that icon. Ex: "gif.ico" will set gif files
			if(fold="")
				return
			Loop,%fold%\*.ico
				{
					StringTrimRight, ext, A_LoopFileName, 4
					RegRead, from, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%ext%, ProgID
					if(from="")
						RegRead, from, HKEY_CLASSES_ROOT, .%ext%
					RegWrite, REG_SZ, HKEY_CLASSES_ROOT, %from%\DefaultIcon, , %fold%\%ext%.ico
				}
			fold=
		}
	else if(A_ThisMenuItemPos=2)
		{
			SplitPath, A_WinDir, , , , , OutDrive
			file=%OutDrive%/Documents and Settings/%A_UserName%/Local Settings/Application Data/IconCache.db
			FileDelete, %file%
		}
return

BtnASITSF:
	FileSelectFolder, dir, , , Select a folder to apply this icon to it
	n2=0
	IfInString, newIconFile, `,
		{
			StringSplit, n, newIconFile, `,
			trim:=StrLen(n2)+1
			StringTrimRight, newIconFile, newIconFile, %trim%
		}
	FileDelete, %dir%\desktop.ini	
FileAppend, 
(
[.ShellClassInfo]
IconFile=%newIconFile%
IconIndex=%n2%
)`n, %dir%\Desktop.ini
	Sleep,100
	FileSetAttrib, +ASH, %dir%\Desktop.ini
	FileSetAttrib, +S, %dir%
return

BtnSpecialIcons:
	Menu,sf,add
	Menu,sf,deleteall
	Menu,sf,add,Folder Icon, sicons
	Menu,sf,add,My computer Icon, sicons
	Menu,sf,add,Empty Recycle Bin Icon, sicons
	Menu,sf,add,Full Recycle Bin Icon, sicons
	Menu,sf,add,Desktop Icon, sicons
	Menu,sf,show
return
sicons:
	if(A_ThisMenuItemPos=1)
			{
				from=Folder
				RegRead, ico, HKEY_CLASSES_ROOT, %from%\DefaultIcon
			}
	else
		msgbox,not yet implemented
	if (A_ThisMenuItemPos=2)
		{
			from={20D04FE0-3AEA-1069-A2D8-08002B30309D}
			RegRead, ico, HKEY_LOCAL_MACHINE, SOFTWARE\Classes\CLSID\%from%\DefaultIcon
		}
	else if (A_ThisMenuItemPos=3)
		{
			from={645FF040-5081-101B-9F08-00AA002F954E}
			RegRead, ico, HKEY_LOCAL_MACHINE, SOFTWARE\Classes\CLSID\%from%\DefaultIcon
		}	
	else if (A_ThisMenuItemPos=4)
		{
			from={645FF040-5081-101B-9F08-00AA002F954E}
			RegRead, ico, HKEY_LOCAL_MACHINE, SOFTWARE\Classes\CLSID\%from%\DefaultIcon,Full
		}
	IfInString, ico, `,
	{
		StringSplit, n, ico, `,
		n2++
		trim:=StrLen(n2)+1
		StringTrimRight, ico, ico, %trim%
	}
	GuiControl,,actualIcon,  *icon%n2% *w32 *h-1 %ico%	
return

Extension:
	Gui, Submit, nohide
	IniRead, orIcon, conf.ini, originalIcons, %ext%
	RegRead, from, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%ext%, ProgID
	if(from="")
		RegRead, from, HKEY_CLASSES_ROOT, .%ext%
	RegRead, ico, HKEY_CLASSES_ROOT, %from%\DefaultIcon
	if(orIcon="")
		orIcon=%ico%
	originalIcon=%ico%
	IfInString, ico, `,
	{
		StringSplit, n, ico, `,
		trim:=StrLen(n2)+1
		StringTrimRight, ico, ico, %trim%
	}
	IfInString, orIcon, `,
	{
		StringSplit, on, orIcon, `,
		trim:=StrLen(on2)+1
		StringTrimRight, orIcon, orIcon, %trim%
	}
	GuiControl,,firstIcon,  *icon%on2% *w32 *h-1 %orIcon%
	GuiControl,,actualIcon,  *icon%n2% *w32 *h-1 %ico%
return
BtnSet:
	if(newIconFile="")
		return
	IniWrite, %originalIcon%, conf.ini, originalIcons, %ext%
	RegWrite, REG_SZ, HKEY_CLASSES_ROOT, %from%\DefaultIcon, , %newIconFile%
return

BtnRestore:
	Gui, Submit, nohide
	RegRead, from, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%ext%, ProgID
	if(from="")
		RegRead, from, HKEY_CLASSES_ROOT, .%ext%
	RegWrite, REG_SZ, HKEY_CLASSES_ROOT, %from%\DefaultIcon, , %orIcon%
return



;#############   Browse to the folder from where the serach should start   ####
BtnBrowseFolder:
  Gui, +OwnDialogs
  FileSelectFolder, SelectedDir, *%ScanFolder%, 2, Select folder to start searching for icons
  If SelectedDir
    {
      ;remove "\" if folder is a root drive, e.g. "C:\"
      StringRight, LastChar, SelectedDir, 1
      If LastChar = \
          StringTrimRight, SelectedDir, SelectedDir, 1

      GuiControl, ,ScanFolder, %SelectedDir%
    }
  Gosub, BtnScan
Return

;#############   Start or stop scanning for files   ###########################
BtnScan:
  If ScanStatus
      ;break scan loop
      ScanStatus := False
  Else
      ;start a new thread for scaning
      SetTimer, Scan, 20
return

;#############   Scan the folder for files with icons   #######################
Scan:
  SetTimer, Scan, Off

  ScanStatus := True

  Gui, Submit, NoHide

  ;change lable and make default button: scan/stop
  GuiControl, , BtnScan, &STOP
  GuiControl, +Default, BtnScan
     
  ;disable redraw for speed
  GuiControl, -Redraw, LstOfFiles

  ;set list of files as default
  Gui, ListView, LstOfFiles

  ;clear list of files
  LV_Delete()

  ;create new list of small images and replace and delete old one
  IListIDFilesSmall := IL_Create(100, 100, False)
  ListID := LV_SetImageList(IListIDFilesSmall)
  If ListID
      IL_Destroy(ListID)

  ;create new list of large images and replace and delete old one
  IListIDFilesLarge := IL_Create(100, 100, True)
  ListID := LV_SetImageList(IListIDFilesLarge)
  If ListID
      IL_Destroy(ListID)

  ;Search all files
  i = 0
  Loop, %ScanFolder%\*, 0, %CkbRecursive%
    {
      ;If their extention is exe,dll,ico,ani,cpl ...
      If A_LoopFileExt Contains exe,dll,ico,ani,cpl
        {
          ;... get first icon (small) ...
          ID := IL_Add(IListIDFilesSmall, A_LoopFileFullPath, 1)

          ;... And If they have a first Icon ...
          If ID > 0
            {
              ;get large icon
              IL_Add(IListIDFilesLarge, A_LoopFileFullPath, 1)

              ;count this file
              i++

              ;add file to ListView
              LV_Add("Icon" . i, A_LoopFileName, A_LoopFileDir)

              GuiControl,,TxtFilesFound,%i% files found, shown as
            }
        }
      ;break loop if user pushes STOP button
      If not ScanStatus
          break
    }

  ScanStatus := False

  ;Enable redraw for speed
  GuiControl, +Redraw, LstOfFiles

  ;Adjust width
  LV_ModifyCol()

  ;rename button to scan again
  GuiControl, , BtnScan, &Scan
Return

;#############   A file got selelected in list   ##############################
LstOfFiles:
  ;file is selected with mouse or by keyboard
  If ( A_GuiEvent = "I" )
    {
      ;set list of files as default
      Gui, ListView, LstOfFiles

      ;get selected file
      RowNumber := LV_GetNext()
      LV_GetText(IV_File, RowNumber, 1)
      LV_GetText(IV_Path, RowNumber, 2)


      ;set list of icons as default
      Gui, ListView, LstOfIcons

      ;diable redraw for speed
      GuiControl, -Redraw, LstOfIcons

      ;clear list
      LV_Delete()

      ;create new list of small images and replace and delete old one
      IListIDIconsSmall := IL_Create(10, 10, False)
      ListID := LV_SetImageList(IListIDIconsSmall)
      If ListID
          IL_Destroy(ListID)

      ;create new list of large images and replace and delete old one
      IListIDIconsLarge := IL_Create(10, 10, True)
      ListID := LV_SetImageList(IListIDIconsLarge)
      If ListID
          IL_Destroy(ListID)

      i = 0
      ;Search for 9999 icons in the selected file
      Loop, 9999
        {
          ;get small icon
          ID := IL_Add(IListIDIconsSmall, IV_Path . "\" . IV_File , A_Index)

          ;if small icon exist
          If ID > 0
            {
              ;get large icon
              IL_Add(IListIDIconsLarge, IV_Path . "\" . IV_File , A_Index)

              i++
             
              ;add icon to list
              LV_Add("Icon" . A_Index, A_Index)

              GuiControl,,TxtIconsFound,%i% icons found, shown as
            }
          Else
              Break
        }
      ;enable redraw for speed
      GuiControl, +Redraw, LstOfIcons

      ;clear edit field
      GuiControl,,AHKCommand,
    }
Return

;#############   Change of view mode for file list   ##########################
RadFilesReport:
  GuiControl, +Report, LstOfFiles
  Gui, ListView, LstOfFiles
  LV_ModifyCol()
Return

RadFilesTile:
  GuiControl, +Tile, LstOfFiles
Return

RadFilesIcons:
  GuiControl, +Icon, LstOfFiles
Return

RadFilesSmallIcons:
  GuiControl, +IconSmall, LstOfFiles
Return

RadFilesList:
  GuiControl, +List, LstOfFiles
Return

;#############   A icon got selected in list   ################################
LstOfIcons:
  ;icon is selected with mouse or by keyboard
  If ( A_GuiEvent = "I" )
      GoSub, RadAHKCommand
return

;#############   AHK command got changed   ####################################
RadAHKCommand:
  ;set list of icons as default
  Gui, ListView, LstOfIcons

  ;get selected
  RowNumber := LV_GetNext()

  ;If something is selected (might not be true if RadAHKCommand is calling)
  If RowNumber
    {
      ;get Icon number
      LV_GetText(IV_IconID, RowNumber, 1)

      ;get AHKCommand
      Gui, Submit, NoHide

      GuiControl,, newIcon, *icon%IV_IconID% *w32 *h-1 %IV_Path%\%IV_File%
      ;GuiControl,,AHKCommand,  icon%IV_IconID% , 
			newIconFile=%IV_Path%\%IV_File%
			icgroup=exe,dll
			SplitPath, newIconFile, , , OutExtension
			IfInString, icgroup, %OutExtension%
			{
				IV_IconID--
				newIconFile=%newIconFile%,%IV_IconID%
			}
    }
Return

;#############   Change of view mode for icon list   ##########################
RadIconsReport:
  GuiControl, +Report, LstOfIcons
  Gui, ListView, LstOfIcons
  LV_ModifyCol()
Return

RadIconsTile:
  GuiControl, +Tile, LstOfIcons
Return

RadIconsIcons:
  GuiControl, +Icon, LstOfIcons
Return

RadIconsSmallIcons:
  GuiControl, +IconSmall, LstOfIcons
Return

RadIconsList:
  GuiControl, +List, LstOfIcons
Return


;#############   Close window   ###############################################
BtnClose:
GuiClose:
GuiEscape:
  ExitApp
Return
;#############   End of File   ################################################


____________________
______________________
kiu - www.romeosa.com

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
I think I understood the program correctly, that it allows you to display a different icon for different file extensions, e.g. txt files? But if I type in txt in the "Select a file type" box (or any other extension), only a generic icon is displayed on the left hand side of the 2 icons, the same as when the script starts up. (Using WinXP)

EDIT: It did update the icon correctly even though it showed the wrong one in the script (it now shows the new icon for txt files) but seems like Windows probably needs restarting to get it to refresh its icon cache or something. Is there a quicker way to get Windows to refresh its icons? I seem to recall TweakUI or similar programs can rebuild the icon cache.

I would like to suggest exporting the reg key as a backup or making a copy of the original data somewhere so that the user can easily revert to the original icons - or perhaps even switch between sets of icons (such as original and customized - this would be great for "highlighting" certain file types when working on certain jobs).

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Iseems like Windows probably needs restarting to get it to refresh its icon cache or something. Is there a quicker way to get Windows to refresh its icons? I seem to recall TweakUI or similar programs can rebuild the icon cache.

Yes, that's TweakUI. Perhaps just logging out and in may be enough too. I don't know how TweakUI does its magic, so I cannot reproduce its method.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
new version on first post:
1)added support to restore original icon (thanks evl for the suggestion)
2)added support to refresh icon cache(press special actions button)

Let me know
____________________
______________________
kiu - www.romeosa.com

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
For people didn't know how to refresh icon cache, the script does it by deleting the file IconCache.db in Application Data folder. Now in new version there are 2 new variables, A_AppData and A_AppDataCommon, so I will update the script accordingly to support OS indipendently from language
____________________
______________________
kiu - www.romeosa.com

dinkosta
  • Members
  • 39 posts
  • Last active: Dec 19 2008 07:25 PM
  • Joined: 28 Sep 2005
Great script, kiu.
I have one problem, though. When I type into the "Select a file type" field some letter the message "File Error. Windows cannot find ERROR" pops up. If a click "Close" I can type the next letter, but the same message pops up again. Do you know what might be the reason for this (Win 98SE here)?

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005

Great script, kiu.
I have one problem, though. When I type into the "Select a file type" field some letter the message "File Error. Windows cannot find ERROR" pops up. If a click "Close" I can type the next letter, but the same message pops up again. Do you know what might be the reason for this (Win 98SE here)?


Please try this: type "z" then "i"; you should get the error and press CLOSE two times. Then type "p". This third time do you still get the error?
____________________
______________________
kiu - www.romeosa.com

dinkosta
  • Members
  • 39 posts
  • Last active: Dec 19 2008 07:25 PM
  • Joined: 28 Sep 2005
Yes, whenever I type something into that field I get that error message. The same with z, i, p.
Am I the only one with this error message?

kiu
  • Members
  • 234 posts
  • Last active: Oct 10 2010 07:30 PM
  • Joined: 18 Dec 2005
But when you select to change the icon, the script changes it?
____________________
______________________
kiu - www.romeosa.com

dinkosta
  • Members
  • 39 posts
  • Last active: Dec 19 2008 07:25 PM
  • Joined: 28 Sep 2005
Yes, everything works OK, it's just this annoying white message box.

TucknDar
  • Members
  • 47 posts
  • Last active: Jun 08 2011 04:48 PM
  • Joined: 07 Jan 2006
only just discovered this gem of a script! Wow, great work!

is it still being developed, I'd like the todo-items to be implemented ;)

unknown
  • Guests
  • Last active:
  • Joined: --
Is there any way, you could transform gif and jpg images to icons (*.ico)?