| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1424 人关注过本帖
标题:怎么从一个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
快速回复:怎么从一个handle得到control对象
数据加载中...
 
   



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

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