Here we will briefly introduce how to change the file icon of the specified type by modifying the registry.
There is a primary key named HKEY_LOCAL_MACHINE in the registry. Many subkeys starting with the decimal point are displayed under this primary key. These are the file types currently registered by the system, if you look at it again, you will see the familiar ". exe ",". mp3 "and so on. The following uses the exe file type as an example to describe how to modify the icon.
First, locate the subkey ". exe" and click it (do not expand). A default REG_SZ table item is displayed on the right. The default value is exefile. Find this, and then locate the exefile sub-Key (in HKEY_LOCAL_MACHINE). Expand and you will see a sub-key under it, the name is DefaultIcon (if you do not have one, you can create it yourself). This DefaultIcon will also have a default REG_SZ table item. The content of this table item is the icon position, in exefile, the default value is "% 1". You only need to change this value to the path of the icon (for example, "c: \ test. ico ") You can change the icon. Restart the resource manager and you will find that the icon has been replaced with the icon you specified. If you change it back, you just need to change it to "% 1.
The above section describes how to manually modify the Registry to modify the file icon. Next we will use the C language programming.
First, let's briefly introduce several related API functions that operate the registry (the specific parameters and their meanings are not described here. Readers can refer to the relevant information on their own ).
The RegCreateKey function is used to create a registry key. If the key already exists, this key is enabled.
The RegQueryValueEx function queries the content of a specified table item.
The RegSetValueEx function sets the value of a specified table item.
The RegCloseKey function is used to release the handle of the specified registry key.
With these API functions, we can program to modify the file icon.
Step 1: Use RegCreateKey (HKEY_CLASSES_ROOT, lpFileType, &hkey=to open the .exe subkey (lpFileType is a string pointer to the file type, that is, the name of the registration key to be opened, hKey is used to store the handle that opens the registration key ).
Step 2: Use RegQueryValueEx (hKey, NULL, NULL, & dwType, (LPBYTE) tchBuffer, & dwBufLenth) to obtain open information of this type (hKey is the registration key handle, dwType is a variable used to load and retrieve data. tchBuffer is the buffer that stores key values, and dwBufLenth specifies the maximum length to be obtained ).
Step 3: Use RegCloseKey (hKey) to close the registration key handle (this is very important and cannot be ignored !!!!!).
Step 4: Use RegCreateKey (HKEY_CLASSES_ROOT, tchRegPath, & hKey) to open the DefaultIcon sub-key under exefile (tchRegPath is his location, which can be obtained by combining the tchBuffer and DefaultIcon obtained in step 2 ).
Step 4: Use RegSetValueEx (hKey, NULL, NULL, REG_SZ, (LPBYTE) lpIconPath, nIconPathLen) to set the key value (lpIconPath is a pointer to the icon path string, and nIconPathLen is the path length ).
Step 5: Use RegCloseKey (hKey) to close the registration key handle (this is very important and cannot be ignored !!!!!).
So far, the modification is successful.