Jun 1
Update to ArrangeByImage
As I attempted to anoy those around me with ArrangeByImage today I realized one major flaw. The original (now updated) code did nothing about the align to grid option on the desktop. I fiddled a bit and found the style that sets that on the desktop and I am now removing “Align To Grid” when you run the program. And in the interest of saving others the effort to find out how this is done here is a code snippet in c# / Win32API. Note this will actually work for any listview which is technically what the desktop is.
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
const uint LVM_SETEXTENDEDLISTVIEWSTYLE = 4150;
const uint LVM_GETEXTENDEDLISTVIEWSTYLE = 4151;
const uint LVS_EX_SNAPTOGRID = 524288;
private void turnOffSnapToGrid()
{
IntPtr programmanagerWindow = FindWindow(null, "Program Manager");
IntPtr desktopWindow = FindWindowEx(programmanagerWindow, IntPtr.Zero, "SHELLDLL_DefView", null);
IntPtr listviewWindow = FindWindowEx(desktopWindow, IntPtr.Zero, "SysListView32", null);
HandleRef desktopReference = new HandleRef(null, listviewWindow);
int CurrentSettings = (int) SendMessage(desktopReference, LVM_GETEXTENDEDLISTVIEWSTYLE, IntPtr.Zero, IntPtr.Zero);
IntPtr ptr = new IntPtr(CurrentSettings & ~LVS_EX_SNAPTOGRID);
SendMessage(desktopReference, LVM_SETEXTENDEDLISTVIEWSTYLE, IntPtr.Zero, ptr);
}
No comments
No Comments
Leave a comment