Search code examples
windows-xpdesktop-wallpaper

Formula or API for calulating desktop icon spacing on Windows XP


I've built a simple application that applies grid-lines to an image or just simple colors for use as desktop wallpaper. The idea is that the desktop icons can be arranged within the grid. The problem is that depending on more things than I understand the actual spacing in pixels seems to be different from system to system. I've learned that at least these things play a factor:

  • Resolution (duh)
  • Taskbar size and placement
  • Fonts

There has to be more than this. Maybe there's some api call that I don't know about?


Solution

  • there are a 1001 ways to get/set this (but I only know 2) :-D

    Windows Register:

    HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics

    values are IconSpacing and IconVerticalSpacing

    by code:

    using System.Management;

    public string GetWinIconSpace()

    {

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Desktop"); 
    
    foreach (ManagementObject wmi in searcher.Get())
    {
        try
        {
    
            return "Desktop Icon Spacing: " + wmi.GetPropertyValue("IconSpacing").ToString();
    
        }
    
        catch { }
    
    }
    
    return "Desktop Icon Spacing: Unknown";
    

    }

    and the 3rd that I never tried you can find it here