うまく移動させることができません。
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace test
{
public class ListViewEx : ListView
{
public ListViewEx()
{
this.AutoArrange = false;
}
[DefaultValue(false)]
public new bool AutoArrange
{
get
{
return base.AutoArrange;
}
set
{
base.AutoArrange = value;
}
}
[StructLayout(LayoutKind.Sequential)]
private struct tagPOINT
{
int x;
int y;
public tagPOINT(int x, int y)
{
this.x = x;
this.y = y;
}
}
[DllImport("user32.dll")]
private extern static int SendMessage
(IntPtr hWnd, uint message, int index, ref tagPOINT p);
private const uint LVM_FIRST = 0x1000;
private const uint LVM_SETITEMPOSITION32 = LVM_FIRST + 49;
public void SetItemPosition(IntPtr hwnd,int index, Point point)
{
//if (index < 0 || this.Items.Count <= index)
// throw new ArgumentOutOfRangeException("index");
tagPOINT p = new tagPOINT(point.X, point.Y);
Console.WriteLine("移動します");
SendMessage(hwnd, LVM_SETITEMPOSITION32, index, ref p);
}
}
class TestClass
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string strclassName, string strWindowName);
[DllImport("user32", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
static void Main(string[] args)
{
IntPtr hWnd;
hWnd = FindWindow("Progman", "Program Manager");
hWnd = FindWindowEx(hWnd, IntPtr.Zero, "SHELLDLL_DefView", null);
hWnd = FindWindowEx(hWnd, IntPtr.Zero, "SysListView32", null); //デスクトップ
ListViewEx p = new ListViewEx();
p.SetItemPosition(hWnd,1, new Point(60,60));
Console.WriteLine("終わりました");
Console.ReadKey();
}
}
}
上のコードを実行して見るとデスクトップから指定のアイコンが消えてなくなっていたり、
エクスプローラを再起動しますなどのメッセージが出てきて止まってしまいます。
これらのエラーはどうしたら治るのかご教授お願いいたします。
OS :windows7