gpt4 book ai didi

c# - 用C#排列桌面图标

转载 作者:太空狗 更新时间:2023-10-29 21:57:43 26 4
gpt4 key购买 nike

好的伙计们,这就是我要实现的目标:

我希望所有无序的桌面图标在单击按钮时自行排列到桌面的左上角。

这是我使用的代码:

[DllImport("user32.dll")]

private static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, int lParam);

private void button1_Click(object sender, EventArgs e)
{
IntPtr hwnd = GetDesktopWindow(); //hwnd for desktop
SendMessage(hwnd, LVM_ARRANGE, LVA_ALIGNLEFT, 0);
}

我相信有未分配的整数与 LVM_ARRANGELVA_ALIGNLEFT 相关联,谁能告诉我它们是什么。我不熟悉使用 dll,所以请原谅我问了一个愚蠢的问题。

谢谢!

帮帮我,我正在使用以下代码,但它仍然无法正常工作:

  private void button1_Click(object sender, EventArgs e)
{


IntPtr hanle = GetHandle();
IntPtr done;
done = SendMessage(hanle, LVM_ARRANGE, LVA_ALIGNLEFT, IntPtr.Zero);

}

public IntPtr GetHandle()
{
hShellWnd = GetShellWindow();
hDefView = FindWindowEx(hShellWnd, IntPtr.Zero, "SHELLDLL_DefView", null);
folderView = FindWindowEx(hDefView, IntPtr.Zero,"SysListView32", null);
return folderView;
}


public const int LVM_FIRST = 0x1000;
public const uint LVM_ARRANGE = LVM_FIRST + 22;
//public const IntPtr LVA_SNAPTOGRID = 5;

IntPtr LVA_ALIGNLEFT = new IntPtr(0x0001);

IntPtr hShellWnd;
IntPtr hDefView;
IntPtr folderView;


[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

[DllImport("user32.dll")]
static extern IntPtr GetShellWindow();

最佳答案

我环顾四周,这个示例似乎有效。

private void button1_Click(object sender, System.EventArgs e)
{
SendMessage(GetDesktopWindow(), LVM_ARRANGE, LVA_SNAPTOGRID , 0);
}


public const int LVM_ARRANGE = 4118;
public const int LVA_SNAPTOGRID = 5;


[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll")]
public static extern int SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam );

它来自以下链接:http://www.codeproject.com/Messages/1168661/Auto-Arrange-desktop-icons.aspx

注意从头文件中

#define LVA_DEFAULT             0x0000
#define LVA_ALIGNLEFT 0x0001
#define LVA_ALIGNTOP 0x0002
#define LVA_SNAPTOGRID 0x0005

因此要左对齐,您需要使用 int 1。

关于c# - 用C#排列桌面图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24965672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com