Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Changing icons problem (http://www.programmingforums.org/showthread.php?t=8989)

Pedja Mar 22nd, 2006 3:34 PM

Changing icons problem
 
Hi there.
I have a problem. When I change the default icon for some file extension, I need it to happen instantly. For example, I want to change icon for .cdc files. I know how to do it, and that is not a problem, but the problem is that it doesn't happen instantly, but when some kind of system refresh happens. I think it has something to do with shelliconcache.dll or iconcache.db, witch i can't find on my system. I have WXP Professional.
For example, when you start BS Player and assign it to be the default player for some file types, it happens, and all icons change right away.
I need to know what I can do to make this change happening when I want it. What is the thing that BS player and Windows Media Player do when they make a registry change, to make it happen at that exact moment?
The thing is that i am creating an application that should be able to do this, and i have no idea what should be done, and how BS Player does it.
Maybe I need to send some kind of system message to tell the OS to reload icon cache.
Any help would be most appreciated.
Thanks.

The Dark Mar 22nd, 2006 6:26 PM

Google is your friend

Dameon Mar 22nd, 2006 9:14 PM

@The Dark: I'd have to say, that link is far from useful.

I haven't been able to find a good answer. Odd.

nnxion Mar 23rd, 2006 3:17 AM

I know that the tweakUI powertool rebuilds your icons just for that purpose.
I think you need to do the same.

The Dark Mar 23rd, 2006 5:15 AM

@Dameon: Really? The first link off google (the codeproject one) shows a similar problem with changing the icons and shows the exact call needed to get the icon cache to be refreshed.
:

::SendMessage(HWND_BROADCAST ,
        WM_SETTINGCHANGE,SPI_SETNONCLIENTMETRICS,NULL);


I suspect that there is a better SPI_ value for icon changing, but this one (suposedly) does the trick.

Pedja Mar 24th, 2006 3:19 PM

Guys, thank you all for helping, especially The Dark (again).
You got it right, but i still have a problem.
ShellIconChanger really works, and it does what my app needs to do, but i have problems implementing the same in C#.

Here is what happens:
:

[DllImport("user32.dll")]
        public static extern uint SendMessage(IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);

:

RegistryKey k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
k.SetValue("Shell Icon Size", "33");  //this value in my reg is 32
k.Flush(); k.Close();

SendMessage((IntPtr)0xffff, 0x001A, 0x002A, IntPtr.Zero);

k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
k.SetValue("Shell Icon Size", "32");  //back to what it was
k.Flush(); k.Close();

SendMessage((IntPtr)0xffff, 0x001A, 0x002A, IntPtr.Zero);

App always blocks on second call to SendMessage function.
Icons sometimes change immediately, and sometimes don't.
From my app, icons change immediately only when I start it after doing the same thing in ShellIconChanger. Every other time app fails to do this.
What am I missing?

The Dark Mar 24th, 2006 6:23 PM

It may be the fault of another program you are running. If an app doesn't respond to the global SendMessage, it sits there waiting for it for a period of time. I am not sure what you can do about it though.

Dameon Mar 24th, 2006 7:58 PM

Use PostMessage instead?

Sorry about the criticism of the link. I seem to have missed the first result...somehow.

Pedja Mar 25th, 2006 8:03 AM

It works! The SendMessageTimeout function does the trick.
:

private static extern long SendMessageTimeout(
        int hWnd,
        int Msg,
        int wParam,
        string lParam,
        int fuFlags,
        int uTimeout,
        out int lpdwResult
);

:

RegistryKey k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
k.SetValue("Shell Icon Size", "33");
k.Flush(); k.Close();

int res = 0;
SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
k.SetValue("Shell Icon Size", "32");
k.Flush(); k.Close();

SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

This function specifies the timeout period. After 5 seconds (in this case) program returns from the function, and icons are reloaded.
I still don't understand why the program never returned from SendMessage function, but it's not so important.
Thanks a lot.


All times are GMT -5. The time now is 6:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC