转换Windows句柄。可以完成吗? [英] Casting a Windows Handle. Can it be Done?

查看:53
本文介绍了转换Windows句柄。可以完成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,


如果我有一个Windows 32指针和对象(Handle),我知道那是什么

对象是(Button)我可以将一些指针转换为某种类型的

System.Windows.Forms.Button然后使用它的方法和属性吗?


我正在使用C#compact framework 2.0

我已经使用Windows 32 API和PInvoce获得了句柄。

我使用一个dot.net应用程序来控制另一个申请。


谢谢,

墨水

解决方案

ink写道:


>

大家好,


如果我有一个Windows 32指针和对象(句柄)我知道

那个对象是什么(Button)我可以将一些指针转换为一种类型的

System.Windows.Forms.Button然后使用它的方法和属性?


我正在使用C#compact framework 2.0
我已经获得了句柄使用Windows 32 API和PInvoce。

我使用一个dot.net应用程序来控制另一个应用程序。


谢谢,

墨水



不,对不起,在这种情况下你能做的最好的就是发送消息给

另一个控件使用Win32 api。


-

Lasse V?gs?ther Karlsen

mailto:la *** @ vkarlsen。没有


ink写道:


>

大家好,


如果我有一个Windows 32指针和对象(Handle),我知道

那个对象是什么(Button)我可以把一些指针转换为a类型

System.Windows.Forms.Button然后使用它的方法和属性?


我正在使用C#compact framework 2.0

我已经使用Windows 32 API和PInvoce获得了句柄。

我使用一个dot.net应用程序来控制另一个应用程序。


谢谢,

墨水



编号你必须使用interop / pinvoke,你必须致电

Windows API,也包括SendMessage。


ink写道:


如果我有Windows 32指针和对象(Handle)我知道什么

那个对象是什么(Button)我可以将一些指针转换为一种类型的

System.Windows。 Forms.Button然后使用它的方法和属性?



是的。


例如:


Button ButtonFromHandle(IntPtr句柄) )

{

将Control.FromHandle(句柄)作为按钮返回;

}


这个如果句柄有效并且

表示Button控件,则返回Button实例引用;否则返回null。


Pete



Hi all,

If I have a Windows 32 pointer to and object (Handle) and I know what that
object is (Button) can I some how cast that pointer to a type of
System.Windows.Forms.Button and then use its methods and properties?

I am using C# compact framework 2.0
I have obtained the handle using the Windows 32 API and PInvoce.
I am using one dot.net application to control another application.

Thanks,
ink

解决方案

ink wrote:

>
Hi all,

If I have a Windows 32 pointer to and object (Handle) and I know what
that object is (Button) can I some how cast that pointer to a type of
System.Windows.Forms.Button and then use its methods and properties?

I am using C# compact framework 2.0
I have obtained the handle using the Windows 32 API and PInvoce.
I am using one dot.net application to control another application.

Thanks,
ink

No, sorry, the best you can do in this context is to send messages to
the other control using Win32 api.

--
Lasse V?gs?ther Karlsen
mailto:la***@vkarlsen.no


ink wrote:

>
Hi all,

If I have a Windows 32 pointer to and object (Handle) and I know what
that object is (Button) can I some how cast that pointer to a type of
System.Windows.Forms.Button and then use its methods and properties?

I am using C# compact framework 2.0
I have obtained the handle using the Windows 32 API and PInvoce.
I am using one dot.net application to control another application.

Thanks,
ink

No. You will have to use interop/pinvoke, that is you have to call
Windows API, also things like SendMessage.


ink wrote:

If I have a Windows 32 pointer to and object (Handle) and I know what
that object is (Button) can I some how cast that pointer to a type of
System.Windows.Forms.Button and then use its methods and properties?

Yes.

For example:

Button ButtonFromHandle(IntPtr handle)
{
return Control.FromHandle(handle) as Button;
}

This will return a Button instance reference if the handle is valid and
represents a Button control, or null if not.

Pete


这篇关于转换Windows句柄。可以完成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆