Desktop Grid Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xavier
Posts: 6
Joined: 25 May 2022, 18:20

Desktop Grid

Post by xavier » 25 May 2022, 18:27

Hi
Is there a way to get (Sysget?) or calculate the current icon grid of your desktop, something like 25 icons wide x 10 icons high?

braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Desktop Grid

Post by braunbaer » 25 May 2022, 20:40

An idea:

First minimize all open windows
While your mouse is over an icon, the icon borders are displayed in a specific color, I suppose it depends on how you configured the screen colors. Use Window spy to check what color that is.

Move the mouse near the left upper corner of the screen, so that it is over the first icon. Search for the first occurrence of that color first from the left edge toward the right side, then from the top of the screen toward the bottom. Make sure that you are on an icon border by checking that several pixels above and below an assumed vertical line have exactly the same color, and the same to the left and the right of an assumed horizontal line (if that is not the case, the pixel you found is part of the icon and not part of the icon border line). This gives you the width and the height of one icon.
Divide the screen width by the icon width, and the screen height by the icon height, and you're done.

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Desktop Grid

Post by RussF » 26 May 2022, 06:01

@braunbaer, I don't think that will work. If you look at my screenshot, you will see that the size of the highlighted area is determined by whether the icon has a single- or multi-line title and also whether it is selected or not. If the icon has a multi-line title, but is not selected (like the "DisplayFus..." icon below), just hovering over it will show a smaller highlighted area than it does if selected. Additionally, notice the amount of unused vertical space between icons. Just dividing your screen size by the highlighted area will (depending on your resolution and scaling) probably give you more icons than are actually there - even if you round down. I can't give you a solution to this, but I can tell you that your suggestion is somewhat flawed.

Russ
image.png
image.png (84.69 KiB) Viewed 773 times

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Desktop Grid

Post by BoBo » 26 May 2022, 06:25

@RussF - what about to use the checkmark boxes (that are AFAICS at a static position within an icons variable framing) as markers on a virtual grid? :think:

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Desktop Grid

Post by RussF » 26 May 2022, 06:31

@BoBo, that is certainly a possibility, but the user must have "View checkboxes" selected in File Explorer. It would then be a matter of calculating the distance from one checkbox to another. Somehow I feel that display scaling would still be a factor and would have to be taken into account in the calculations.

Russ

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Desktop Grid

Post by BoBo » 26 May 2022, 07:01

Isn't there a chance to extract the currently used desktop icon size info from the system/registry so no visual interference is necessary to get the data for a following calculation?

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Desktop Grid

Post by RussF » 26 May 2022, 07:29

Yes, you can get it from HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics. The keys are IconSpacing and IconVerticalSpacing. The numbers are negative values, the most common default being -1125. You can change these, numbers closer to 0 (less negative) having tighter spacing and higher negative values being farther apart. Unfortunately, I have not yet found a resource that interprets exactly what those numbers represent.

Russ


xavier
Posts: 6
Joined: 25 May 2022, 18:20

Re: Desktop Grid

Post by xavier » 26 May 2022, 10:10

First, I'd like to thank everybody for their contribution.

And I'll add that what I definitely is a autohotkey/windows dll solution not involving manual/visual counting

I'll look into the registry key direction to see if I can find out anything useful.

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

Re: Desktop Grid  Topic is solved

Post by teadrinker » 26 May 2022, 11:39

For one monitor this should work:

Code: Select all

GetWorkArea(workWidth, workHeight)
GetDesktopSpacing(widthSpacing, heightSpacing)
MsgBox, % grid := workWidth//widthSpacing . "x" . workHeight//heightSpacing

GetWorkArea(ByRef width, ByRef height) {
   static SPI_GETWORKAREA := 0x30
   VarSetCapacity(RECT, 16, 0)
   res := DllCall("SystemParametersInfo", "UInt", SPI_GETWORKAREA, "UInt", 0, "Ptr", &RECT, "UInt", 0)
   width := NumGet(RECT, 8, "UInt") - NumGet(RECT, "UInt")
   height := NumGet(RECT, 12, "UInt") - NumGet(RECT, 4, "UInt")
   Return res
}

GetDesktopSpacing(ByRef widthSpacing, ByRef heightSpacing) {
   static SID_STopLevelBrowser := "{4C96BE40-915C-11CF-99D3-00AA004AE837}"
           , IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}"
           , IID_IFolderView   := "{CDE725B0-CCC9-4519-917E-325D72FAB4CE}"
           , 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)
   IFolderView := ComObjQuery(IShellView, IID_IFolderView)

   ; IFolderView::GetSpacing
   hr := DllCall(NumGet(NumGet(IFolderView + 0) + A_PtrSize*12), "Ptr", IFolderView, "Int64P", point)
   ObjRelease(IFolderView), ObjRelease(IShellView), ObjRelease(IShellBrowser)

   widthSpacing := point & 0xFFFFFFFF
   heightSpacing := point >> 32
   Return hr
}

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Desktop Grid

Post by RussF » 26 May 2022, 11:58

Well done @teadrinker !!!

We're not worthy, we're not worthy! :clap:

Russ

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

Re: Desktop Grid

Post by teadrinker » 26 May 2022, 12:42

Haha, I'm not Alice Cooper! :lol:

xavier
Posts: 6
Joined: 25 May 2022, 18:20

Re: Desktop Grid

Post by xavier » 26 May 2022, 13:44

Thanks to @teadrinker for the PERFECT ANSWER :bravo:

It's exactly what I was looking for.

:superhappy:

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

Re: Desktop Grid

Post by teadrinker » 26 May 2022, 15:12

:wave:

Post Reply

Return to “Ask for Help (v1)”