views:

114

answers:

2

I'd like to get and set the desktop icons sizes in Windows Vista and 7 - now the desktop allows to resize the icons dinamically with Ctrl-MouseWheel and I'd like to do it using C#. Yes, I can send the WM_MOUSEWHEEL message to the desktop listview handle, but that has two disadvantages:

  • I don't have the current size, so I must send the message many times, until I reach a known state (maximum or minimum size) then send the message again to resize to the desired size
  • The above procedure is slow (I must send many messages to reach the desired size, that can't be done in one step) and it sometimes flickers when it reaches the known state.

I'd like to know if there is any way to get the current icon size and set it to another size programatically

A: 

I know you can get the size of the icons fairly easily using the SystemInformation class. It seems there is no setter, so you may have to dig deeper and use the system's SystemParameterInfo() function. See the SPI_GETICONMETRICS and SPI_SETICONMETRICS parameters.

André Caron
The SystemInformation class uses the same information as the registry key "HKEY_CURRENT_USER\Control Panel\desktop\WindowMetrics\Shell Icon Size" and it doesn't reflect the real size. For example, resize your desktop icons with Ctrl-MouseWheel and then read SystemInformation.IconSize. You will always get 32x32
Bruno Sonnino
A: 

It seems the only way to this is through the registry. See towards the middle of this page ("When in Windows").

Update:

Ok, I see what you are saying now. You need to use the desktop's IFolderView (CurrentViewMode) or IFolderView2 (ViewModeAndIconSize).

Luke
Using the "HKEY_CURRENT_USER\Control Panel\desktop\WindowMetrics\Shell Icon Size" requires resetting Explorer (by logoff, restart or killing it), and it is not used by the Ctrl-MouseWheel feature - reading this key doesn't get the real icon size, and setting it doesn't do an immediate change
Bruno Sonnino
I think the IFolderView2 is the right direction, but do you have any example of getting this interface from the desktop?
Bruno Sonnino
Unfortunately (or perhaps fortunately) it seems like Explorer does not expose the *View interfaces for the desktop folder.
Luke
Too bad. I will try some more time to get the interface - I've seen that IFolderView2 works fine resizing icons (there is a sample in the WindowsAPICodePack that allows resizing the icons in an ExplorerBrowser in the application, but in that case it's easy to get the IExplorerBrowser and the IFolderView2 interface), now I just need a way to get the IExplorerBrowser or the IFolderView2 interface for the desktop.
Bruno Sonnino