标题:怎么从一个handle得到control对象
只看楼主
chmj
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-8-13
 问题点数:0 回复次数:1 
怎么从一个handle得到control对象

//How I can get the form object from handle ?
//下面的代码有问题

using System;
using System.Management;
using System.Diagnostics;
using System.Windows.Forms;

public class WindowWrapper : IWin32Window
{
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}

public IntPtr Handle
{
get { return _hwnd; }
}

private IntPtr _hwnd;
}

public class RemoteConnect
{
public static void Main()
{
Process[] procs = Process.GetProcessesByName("Notepad");
if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
}
else
Console.WriteLine("Notepad is not running.");

if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
Control c = Control.FromHandle(hwnd);
if (c != null) //c is null here
{
Console.WriteLine((c as Form).Text);
}
else
{
Console.WriteLine("Null");
}
}

}
}

[此贴子已经被作者于2006-8-13 15:58:05编辑过]

搜索更多相关主题的帖子: handle control 对象 
2006-08-13 15:54
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
得分:0 

intptr iptr=button1.handle
control c=control.fromhandle(iptr);
button bt=(button)c
bt.text=""


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-14 10:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-83744-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.431094 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved