高分求助桌面图标自动排列
C# 怎么调用api使桌面图标自动排列,然后撤销自动排列。。。
请高手指点~~~~
------解决方案--------------------#region 导入api
[DllImport( "user32.dll ", EntryPoint = "FindWindow ")]
public static extern int FindWindow(
string lpClassName,
int lpWindowName
);
[DllImport( "user32.dll ", EntryPoint = "ShowWindow ")]
public static extern int ShowWindow(
int hwnd,
int nCmdShow
);
[DllImport( "user32.dll ", EntryPoint = "FindWindowEx ")]
public static extern int FindWindowEx(
int hWnd1,
int hWnd2,
string lpsz1,
int lpsz2
);
[DllImport( "user32.dll ")]
public static extern int SetWindowLong(
IntPtr hwnd,
int nIndex,
int dwNewLong
);
[DllImport( "user32.dll ")]
public static extern int GetWindowLong(IntPtr hWnd,
int nIndex);
#endregion
const int GWL_STYLE = -16;
const int LVS_AUTOARRANGE = 0x0100;
/// <summary>
/// 撤销自动排列
/// </summary>
public void DisableAutoArrange()
{
int hwnd, child;
hwnd = FindWindow( "progman ", 0);
hwnd = FindWindowEx(hwnd, 0, "shelldll_defview ", 0);
child = FindWindowEx(hwnd, 0, "SysListView32 ", 0);
int oldValue = GetWindowLong((IntPtr)child, GWL_STYLE);
SetWindowLong((IntPtr)child, GWL_STYLE, oldValue & ~LVS_AUTOARRANGE);
}
[DllImport( "user32.dll ", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
const int LVM_First = 0x1000;
const int LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_First + 54;
const int LVS_EX_SNAPTOGRID = 0x00080000;
/// <summary>
/// 取消对齐到网格
/// </summary>
public void DisableAlignToGrid()
{
int hwnd, child;
hwnd = FindWindow( "progman ", 0);
hwnd = FindWindowEx(hwnd, 0, "shelldll_defview ", 0);
child = FindWindowEx(hwnd, 0, "SysListView32 ", 0);
SendMessage(new IntPtr(child), LVM_SETEXTENDEDLISTVIEWSTYLE, new IntPtr(LVS_EX_SNAPTOGRID), IntPtr.Zero);
}