Desktop topic desktop icon

xiaoxiao2021-03-06  72

After introducing the two concepts over the above, how to implement the problem, of course, I will not explain how you should design your procedure, this is not my own purpose, let alone everyone is in design Very different, this only has the reader to design it. My program is written in C Builder, so I am using C code when analyzing. If you are not C Builder, then I can't help but.

homescreen icon:

There are a few very special icons on the desktop, that is my computer, I have a document, online neighbor, recycle bin, if you are a Win98 user, you find that you can't delete these icons, no matter what you choose it Press the DELETE button and delete it directly, it will get the result that cannot be deleted. Is there a way? Of course, there is, as long as you find the corresponding key value in the registration table, you can easily delete the corresponding key value in the registry, but later Wndows version is a change to the desktop figure, such as I am now In addition to other icons other than the recycle bin, WinXP, you can get the recycle station, you can find the corresponding key value in the registry.

Below is the location of these desktop icons I organized in the registration table, as follows:

The icon name corresponds to the key in the registration table

My computer 20D04FE0-3AEA-1069-A2D8-08002B30309D} // Default

My document CLSID / / {450D8FBA-AD25-11D0-98A8-0800361B1103} // Defaulticon

Online neighbor CLSID / / {208D2C60-3AEA-1069-A2D7-08002B30309D} // defaulticon

Recycle bin CLSID / / {645FF040-5081-101B-9F08-00AA002F954E} // defaulticon

They exist in the registration table

HKEY_CURRENT_USER / SOFTWARE / Microsoft / Windows / CurrentVersion / Explorer / key value

After knowing that they have location in the registry, if you want to change these icons, you will become simple. Here is a paragraph in my program, it is to write the icon in the fmyiconsreg array to the registry, in this way To change the purpose of the registry

//icon

For (int i = 0; i

{

INITHEME-> WRITESTRING (iconRegPosition TmyiconReg [i], ", fmyiconsreg [i]);

} INITHEME-> WRITESTRING (iconRegPosition TmyiconReg [TMYICON_MAX], "FULL", FMYICONSREG [TMYICON_MAX]);

INITHEME-> WRITESTRING (iconRegPosition TmyiconReg [TMYICON_MAX], "EMPTY", FMYICONSREG [TMYICON_MAX 1]);

The value corresponding to the TMYICONREG array is the key value of the registry listed in the above table, and iconRegPosition is the location of the desktop icon in the registration table with a constant value, and their definition is as follows:

//icon

ENUM TMYICON {

MyComputericon, MyDocumenticon,

Myneetworkicon, myrecycleicon, tmyicon_max = myrecycleCleicon};

AnsistringTmyiconReg [] = {

"CLSID / / {20D04FE0-3AEA-1069-A2D8-08002B30309D} // default", // My computer

"CLSID / / {450D8FBA-AD25-11D0-98A8-0800361B1103} // default", // My documentation

"CLSID / / {208D2C60-3AEA-1069-A2D7-08002B30309D} // default", // online neighbors

"CLSID / / {645FF040-5081-101B-9F08-00AA002F954E} // default" // recycle bin

}

Ansistring iconRegposition = "Software // Microsoft // Windows // CurrentVersion // Explorer //";

If you are still not clear enough, I have prepared an example program for you here, please see:

Void __fastcall tform1 :: btnchangeiconclick (TOBJECT * SENDER)

{

Ansistring = "Software // Microsoft // Windows // CurrentVersion // Explorer // CLSID / / {20D04FE0-3AEA-1069-A2D8-08002B30309D} // default";

Ansistring iconpath = getSystemPath () "// shell32.dll, 53";

SetKeyValue (key, ", iconpath, false);

Rebuildiconcache ();

}

How is it very simple, but you don't want to forget, I use the defined function to make the problem simple, getSystemPath () role makes the location of the system directory, its definition is as follows:

Ansistring getSystemPath ()

{

Char buffer [256];

GetSystemDirectory (Buffer, 256);

Return Ansistring (Buffer);

}

The reason why this function is to obtain the system directory is to have different Windows versions that it may be different, avoiding the purpose of achieving a computer icon due to the location of the icon path file, and is there a reason for This code is more concise.

The role of the setKeyValue () function is to set the key value of the registry, and it is defined as follows:

Void setKeyValue (Ansistring Regpath, Ansistring Key, Ansistring Value, Bool Isllusers)

{

// Todo: Add your source code here

Tregistry * registry = new tregistry;

IF (isallusers)

{

Registry-> rootkey = HKEY_LOCAL_MACHINE

}

Else

{

Registry-> rootkey = HKEY_CURRENT_USER;

}

Try

{

Registry-> OpenKey (RegPath, True);

Registry-> WriteString (key, value);

}

__finally

{

Delete registry;

}

}

This avoids the bloated bloated frequent use of the Tregistry object to operate the registry. This function has a parameter is IsllUsers. When it is the purpose, I decide that I use the hkey_local_machine directory value, or the HKEY_CURRENT_USER directory, the key value, these two The difference is that the former is for all users, while the latter is only for the current user. In the short a few lines of code I also use a more important function, although the SetKeyValue function completes the icon changes, but if the user can press the F5 key to refresh to see the result, the purpose of rebuildiconcache () This function is Complete F5 key function, it is forced system reconstruction system icons to cacdute the user can see the result of change. It is defined as follows:

void rebuildiconcache ()

{

INT ICONW;

Iconw = getSystemMetrics (SM_CXICON);

TreginiFile * reg = new Treginifile ("Control Panel // Desktop);

Try

{

/ / Change the size of the system preset icon cache

REG-> Writestring ("WindowMetrics", "Shell icon size", INTOSTR (iconw-1));

SendMessage (HWND_Broadcast, WM_SETTINGCHANGE, 0, 0);

// will restore the system's preset icon cache size

REG-> Writestring ("WindowMetrics", "Shell icon size", INTOSTR (ICONW));

SendMessage (HWND_Broadcast, WM_SETTINGCHANGE, 0, 0);

}

__finally

{

DELETE REG;

}

}

It is such that as long as the program changes the size of the system preset icon cache, then broadcast the WM_SETTINGCHANGE message, the system will rebuild the system icon cache, and we will immediately see the goal after changing the result. You can also download the sample program at http://www.zccfamily.com/zqget/

转载请注明原文地址:https://www.9cbs.com/read-108778.html

New Post(0)