Rebuild Icon cache

Source: Internet
Author: User
In Windows, the icon may be displayed incorrectly. For example, if the icon is displayed, another file icon is displayed, or the icon is displayed black or blank, this is probably because the Icon cache in Windows is damaged. (For Windows, why do I set the Icon cache? I think it may be due to performance considerations, because it would be too slow to find the icon in each file when the icon is displayed)
If the Windows icon is not displayed properly, you can use some common software such as the "Rebuilding the Icon cache" function of the Windows optimization master to restore the icon to normal. How can this function be programmed?
Delete the C:/Documents and Settings/user name/Local Settings/Application Data/iconcache. DB file. However, this method takes effect only after the system is restarted. In fact, there is a better way to take effect without restarting the system. I found the answer at http://www.codeproject.com/kb/winsdk/nsetfoldericons.aspx. Note the refreshicons () function in this article:

Void cshelliconchangerdlg: refreshicons ()
{
Cstring val;
Hkey;

Long result =: regopenkeyex (HKEY_CURRENT_USER,
"Control Panel // desktop // windowmetrics ",
0, key_read, & hkey );
Byte buff [256];
Zeromemory (buff, 255 );
Dword sz = sizeof Buff;
DWORD typ = REG_SZ;
Regqueryvalueex (hkey, "shell Icon size", 0, & typ, buff, & sz );
Regclosekey (hkey );

Val = Buff;

Int I = atoi (VAL );
I ++;
Val. Format ("% d", I );

Result =: regopenkeyex (HKEY_CURRENT_USER,
"Control Panel // desktop // windowmetrics ",
0, key_write, & hkey );
Regsetvalueex (hkey, "shell Icon size", 0, REG_SZ,
(Const byte *) Val. getbuffer (0), Val. getlength ());
Val. releasebuffer ();
Regclosekey (hkey );

: Sendmessage (hwnd_broadcast,
Wm_settingchange, spi_setnonclientmetrics, null );

I = atoi (VAL );
I --;
Val. Format ("% d", I );

Result =: regopenkeyex (HKEY_CURRENT_USER,
"Control Panel // desktop // windowmetrics ",
0, key_write, & hkey );
Regsetvalueex (hkey, "shell Icon size", 0, REG_SZ,
(Const byte *) Val. getbuffer (0), Val. getlength ());
Val. releasebuffer ();
Regclosekey (hkey );

: Sendmessage (hwnd_broadcast,
Wm_settingchange, spi_setnonclientmetrics, null );
}

It completes the rebuilding Icon cache operation. As for the principle, see the code: first increase the Windows icon display size by 1, then broadcast a wm_settingchange message, and finally change the Icon size back to the original value, broadcasts a wm_settingchange message.

However, the Code is VC ++. I made a small transformation and changed the cstring to wxstring. Now we can compile it with wxdev-C ++, you can also successfully refresh the Icon cache ,. The modified code is as follows:

# Include "windows. H"
# Include "WX. H"

Void refreshicons ()
{
Wxstring val;
Hkey;

Long result =: regopenkeyex (HKEY_CURRENT_USER,
"Control Panel // desktop // windowmetrics ",
0, key_read, & hkey );
Byte buff [256];
Zeromemory (buff, 255 );
Dword sz = sizeof Buff;
DWORD typ = REG_SZ;
Regqueryvalueex (hkey, "shell Icon size", 0, & typ, buff, & sz );
Regclosekey (hkey );

Val = wxstring: Format ("% s", buff );

Long I;
Val. tolong (& I );
I ++;
Val = wxstring: Format ("% d", I );

Result =: regopenkeyex (HKEY_CURRENT_USER,
"Control Panel // desktop // windowmetrics ",
0, key_write, & hkey );

// MessageBox (0, Val. mb_str (), "", mb_ OK );

Regsetvalueex (hkey, "shell Icon size", 0, REG_SZ,
(Const byte *) Val. mb_str (), Val. Length ());

Regclosekey (hkey );

: Sendmessage (hwnd_broadcast,
Wm_settingchange, spi_setnonclientmetrics, null );

Val. tolong (& I );
I --;
Val = wxstring: Format ("% d", I );

Result =: regopenkeyex (HKEY_CURRENT_USER,
"Control Panel // desktop // windowmetrics ",
0, key_write, & hkey );

// MessageBox (0, Val. mb_str (), "", mb_ OK );

Regsetvalueex (hkey, "shell Icon size", 0, REG_SZ,
(Const byte *) Val. mb_str (), Val. Length ());

Regclosekey (hkey );

: Sendmessage (hwnd_broadcast,
Wm_settingchange, spi_setnonclientmetrics, null );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.