At the beginning, various search engines , Blog , Data collection , Preparation , The following steps are optimized in the later stage , At the beginning, I recorded all kinds of useful , It's a mess , Code / The finished product can be viewed directly from the back
Via desktop 【 Right click 】—>【 Individualization 】—>【 The theme 】—>【 Desktop icon settings 】—>【 Change icon 】 You can see that the default icon is imageres.dll
, This is a windos Default icon library .
Win 10 Style icon library has :
ddores.dll
dmdskres.dll
imageres.dll
mmres.dll
networkexplorer.dll
pnidui.dll
sensorscpl.dll
setupapi.dll
shell32.dll
wmploc.dll
wpdshext.dll
For more information, please refer to the blog :Windos Icon dll
When I didn't know anything at first , Thinking about , Write a program to automatically replace this dll, Call the website to convert the icon format : transformation ico Then write a program to run ;
The procedure is mainly divided into the following parts :
Call the website to convert the icon format 【 Optional 】, It can also be called by program
Automatically generate new dll【 Is difficult , Optional 】emmmm, It's not very big , You can refer to post (C++)
Modify registry , Update the value of the recycle bin
Desktop icon registry correspondence
Third-party module ( At first I wanted to write GUI, eureka TKInterDesigner, But there are BUG, My computer doesn't work , Put it on hold ):
pythonmagick, You can't pip install, Manual required download , Pay attention to the version and CPU framework ( Check... By command pip debug --verbose, My is cp38-cp38-win_amd64)!cp10 Corresponding python edition 3.10,cp38 Corresponding python edition 3.8
import PythonMagickimg = PythonMagick.Image("logo.png") # Load the image to be converted img.sample('64x64') # Set the generated icon Size img.write("logo.ico") # Generate icon And save
Where the Recycle Bin icon is located :
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon
【 change 】 The location of the recycle bin custom icon : HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon
Items under the directory
empty
、full
The value of corresponds to empty and full recycle bin respectively ( Non empty ) When icon Icon position ;
[HKEY_CURRENT_USER\Software\Classes\CLSID](WIN9X)
or [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID](WIN2000/XP)
The icon or name of a system folder is defined in , It will take precedence over [ HKEY_CLASSES_ROOT\CLSID
]. My computer on the desktop 、 My documents 、 Icons and names such as network places are defined here . The types of values of items are REG_EXPAND_SZ, The data are : ( Default ): %SystemRoot%\System32\imageres.dll,-55
Empty: %SystemRoot%\System32\imageres.dll,-55
Full: %SystemRoot%\System32\imageres.dll,-54
take icons The pictures in the folder are converted to ico File and store it in iocn Under the folder ;
import osimport PythonMagickdef get_files(): filenames = os.listdir(os.path.join(os.getcwd(), 'icons')) for index, item in enumerate(filenames): filenames[index] = './icons/' + item return filenamesdef convert(sava_path): if not os.path.exists(sava_path) or os.path.isfile(sava_path): os.mkdir(sava_path) else: os.mkdir(sava_path) filenames = get_files() for item in filenames: img = PythonMagick.Image(item) # Load the image to be converted img.sample('256x256') # Set the generated icon Size img.write('./icon/' + item[8:len(item) - 3] + 'ico') # Generate icon And save if __name__ == '__main__': convert("icon")
Here I pass VS Create a new DLL project , Then import the... From the previous step ico file , Then generate . You can also directly ico The suffix to dll, In this case, the next step of code related logic also needs to be changed a little .
Add resource file (ico Icon )
Generate dll
From the generated path dll Copy ( Scrapbooking is OK ) One spare .
dll Files need to be stored locally , So I chose to store it in TEMP Under the folder , It can also be stored in other folders , Storage in... Is not recommended system32 Next .
import osimport winregdll_name = "cookie_icon.dll"dll_dir_path = os.path.join(os.getenv("TEMP"), "{645FF040-5081-101B-9F08-00AA002F954E}")dll_file_path = os.path.join(dll_dir_path, dll_name)key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\\Microsoft\\Windows\\CurrentVersion\\" r"Explorer\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}" r"\\DefaultIcon", 0, winreg.KEY_ALL_ACCESS)try: winreg.SetValueEx(key, "empty", 0, winreg.REG_EXPAND_SZ, dll_file_path + ",0") winreg.SetValueEx(key, "full", 0, winreg.REG_EXPAND_SZ, dll_file_path + ",1") print(" Replacement successful ~ Double click the recycle bin to view the effect ") # TODO: Join the refresh mechanism , Refresh the desktop , After implementation, you can see the icon update effect without clicking the recycle bin # At present, most of them are found on the Internet taskkill explorer.exe And then restart , It will cause the desktop to jam temporarily , Generating zombie processes os.system("pause")except WindowsError as e: print("WindowsError: " + e)finally: winreg.CloseKey(key)
results ! My energy !!! Sobbing ~
The relevant code has been packaged as exe 了 , Just run directly ( Limited to Windows),mac Never played , I do not know! , A little . Link fetch ;
Use pyinstaller pack :
pyinstaller -F -i ./popocat_full.ico popocat.py
Generate a single file exe, But there is no way to package external files into exe in , There are self extracting packages that can be packed in , But it can not achieve the desired effect .
So Baidu found Enigma Virtual Box Package software .
After packaging exe Self taking
Although the actual code looks short , But if you really don't understand it, you really can't write it out , First, choose Java, It seems that the bottom layer of the operating system still needs to be found C Language , Switch to C After the language is written , But I have a headache writing about handles , Finally found out winreg This python library , It really works , Put a lot of useless ( Strictly speaking , Is not commonly used ) The parameters of are encapsulated .
If you're okay, you have to do more , Much more trouble , Life is gone .
author : My eyelashes are in my eyes !
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .