【问题标题】:Arranging desktop icons with C#用 C# 排列桌面图标
【发布时间】:2014-07-25 22:56:04
【问题描述】:

好的,这就是我想要实现的目标:

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

这是我正在使用的代码:

[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();

【问题讨论】:

  • 我的意思是图标...
  • 你可以检查source.winehq.org/source/include/commctrl.h 的 LVM_* 和 LVA_* 符号的值(我希望你有基本的 C 阅读技能,因为链接会引导你到一个头文件。你也应该能够在与VS一起安装的平台SDK中找到commctrl.h文件...)
  • 用户文档界面:SetCurrentFolderFlags.
  • -1 Raymond 已经告诉你怎么做
  • 能否详细说明...

标签: c# winapi


【解决方案1】:

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

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。

【讨论】:

    猜你喜欢
    • 2018-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-02
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多