How can I resize Win 11 Desktop Icons? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
grosner
Posts: 10
Joined: 11 Sep 2016, 13:08

How can I resize Win 11 Desktop Icons?

Post by grosner » 20 Oct 2022, 16:15

I would like to resize the Windows 11 Desktop Icons from AHK, but NOT with a controlsend or send of keys (because this was very unreliable for me).

I know I can ctrl-mouse wheel up/down or right click->view and select Small, Medium, or Large icons but I would like to do this programmatically using a reliable method where I can both check the current size and reset the icon size. I want to do this because increasing the dpi scaling makes my icons tool large to fit nicely on the desktop.

Any suggestions or script samples would be greatly appreciated!

grosner
Posts: 10
Joined: 11 Sep 2016, 13:08

Re: How can I resize Win 11 Desktop Icons?

Post by grosner » 21 Oct 2022, 12:09

The closest I have come to setting the Win 11 Desktop Icon Size is the following code to send keys to the windows desktop. While the same keystrokes work interactively, they do not work form AHK. Perhaps I am missing something.

Code: Select all

winGet, hID, ID, ahk_class SysListView32
ControlSend,,{Ctrl down}{Shift down}2{Ctrl up}{Shift up}, ahk_id %hID%
I did find there is the possibility of using Winapi DLL calls for GetViewModeAndIConSize and SetViewModeAndIconSize. However, I could not find any sample AHK scripts to accomplish this.

Any suggestions?

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: How can I resize Win 11 Desktop Icons?  Topic is solved

Post by teadrinker » 21 Oct 2022, 12:57

Try this:

Code: Select all

if SetDesktopIconSize(42, prevSize)
   MsgBox, success`, previous icon size: %prevSize%

SetDesktopIconSize(newDesktopIconSize, ByRef prevSize := 0) {
   static SID_STopLevelBrowser := "{4C96BE40-915C-11CF-99D3-00AA004AE837}"
           , IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}"
           , IID_IFolderView2  := "{1AF3A467-214F-4298-908E-06B03E0B39F9}"
           , VT_UI4 := 0x13, SWC_DESKTOP := 0x8

   shellWindows := ComObjCreate("Shell.Application").Windows
   desktop := shellWindows.Item( ComObject(VT_UI4, SWC_DESKTOP) )
   IShellBrowser := ComObjQuery(desktop, SID_STopLevelBrowser, IID_IShellBrowser)

   ; IShellBrowser::QueryActiveShellView
   DllCall(NumGet(NumGet(IShellBrowser + 0) + A_PtrSize*15), "Ptr", IShellBrowser, "PtrP", IShellView)
   IFolderView2 := ComObjQuery(IShellView, IID_IFolderView2)
   
   ; IFolderView2::GetViewModeAndIconSize
   DllCall(NumGet(NumGet(IFolderView2 + 0) + A_PtrSize*36), "Ptr", IFolderView2, "IntP", FOLDERVIEWMODE, "IntP", prevSize)
   
   ; IFolderView2::SetViewModeAndIconSize
   hr := DllCall(NumGet(NumGet(IFolderView2 + 0) + A_PtrSize*35), "Ptr", IFolderView2, "Int", FOLDERVIEWMODE, "Int", newDesktopIconSize)
   ObjRelease(IFolderView2), ObjRelease(IShellView), ObjRelease(IShellBrowser)
   Return hr = 0
}
Last edited by teadrinker on 22 Oct 2022, 05:15, edited 1 time in total.

grosner
Posts: 10
Joined: 11 Sep 2016, 13:08

Re: How can I resize Win 11 Desktop Icons?

Post by grosner » 21 Oct 2022, 13:29

Works Perfectly!
Thank you very much for your kind and swift response!
I truly appreciate your help!


Post Reply

Return to “Ask for Help (v1)”