日期:2014-05-19  浏览次数:20964 次

C#下用API 跨进程控制别的窗体的TreeView节点的展开与点击
如何在C#下用API   跨进程控制别的窗体的TreeView节点的展开与点击.
网上搜索是用SendMessage来实现,可是具体不知道怎样写!

高手帮帮忙啊!!


------解决方案--------------------
帮顶
------解决方案--------------------
up
------解决方案--------------------
偶不懂,帮顶!!!!要是有源码,请给我一份xsp9488278@126.com,谢了~_~
------解决方案--------------------
太高深了……

一边搞个发送命令(带个参数) 一个搞个接收命令 按参数展开??/
------解决方案--------------------
你只要知道那个进程中的TreeView的句柄,且知道是第几个节点,就可以用如下的方法来展开这个节点(方法中只限第一层切点,如果要其它层的可以按索引再修改,这只是个参考):

[DllImport( "user32.dll ", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
private void button4_Click(object sender, EventArgs e)
{
ExpandNode(2);
}
private void ExpandNode(int index)
{
SendMessage(this.treeView1.Handle, 0x1102, 2, this.treeView1.Nodes[index].Handle);
}

------解决方案--------------------
把上面的this.treeView1.Handle换成相应的句柄就可以了。
------解决方案--------------------
学习~
------解决方案--------------------
treeView tree1 = new treeView ( "根节点名 ")
以上是treeView 取得句柄的代码

Var tree = new WebFXTree( " <%=rootname%> ")
以上是WebTree取得句柄的代码

其他的跨进程通信的方法你应该解决了吧
------解决方案--------------------
你可以参考下面的代码(仅仅参考):
private void button1_Click(object sender, EventArgs e)
{
IntPtr ptr = (IntPtr)int.Parse(this.textBox1.Text, System.Globalization.NumberStyles.HexNumber);
POINT pt = new POINT(Control.MousePosition);
int i = ScreenToClient(ptr, pt);
IntPtr handle = GetNodeAt(ptr, pt.X, pt.Y);//按位置获取鼠标下节点
if (handle != null)
{
SendMessage(ptr, 0x1102, 2, handle);//展开节点
}
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class TV_HITTESTINFO
{
public int pt_x;
public int pt_y;
public int flags;
public IntPtr hItem;
public TV_HITTESTINFO()
{
this.hItem = IntPtr.Zero;
}
}
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int X;
public int Y;
public POINT(Point pt)
{
this.X = pt.X;
this.Y = pt.Y;
}
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[DllImport( "user32.dll ", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
[DllImport( "user32.dll ", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, TV_HITTESTINFO lParam);
[DllImport( "user32.dll ", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ScreenToClient(IntPtr hWnd, [In, Out] POINT pt);
public IntPtr GetNodeAt(IntPtr tvwPtr, int x, int y)
{
TV_HITTESTINFO lParam = new TV_HITTESTINFO();
lParam.pt_x = x;
lParam.pt_y = y;
IntPtr handle = SendMessage(tvwPtr, 0x1111, 0, lParam);
return handle;
}
------解决方案--------------------
路过
------解决方案--------------------