如何从句柄获取TForm实例? [英] How to get instance of TForm from a Handle?

查看:73
本文介绍了如何从句柄获取TForm实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些功能转换为与Windows 7功能相关的DLL.我无法通过DLL传递TForm,因此我需要传递其句柄.除外,一旦我在另一侧拥有该句柄,如何将其重新构造回TForm实例?另外,例如,通过Delphi DLL传递句柄(HWND)以兼容C#调用的合适方法是什么?

I'm converting some functions into a DLL which relate to Windows 7 functionality. I can't pass a TForm through DLL, so I need to pass its handle instead. except, once I have that handle on the other side, how do I reconstruct it back into a TForm instance? Also, what's the appropriate way to pass the handle (HWND) through a Delphi DLL to be compatible to call from C# for example?

如果不可能的话,我至少需要知道如何仅使用Windows API来更改窗口的颜色,而无需参考TForm.目的是从此DLL中以某种方式更改Form的颜色.将句柄传递给DLL没问题,但是如何使用该句柄处理该句柄表示的形式?

If not possible, then I at least need to know how to change the color of a window using windows API only, no reference to the TForm. The goal is that from within this DLL, it needs to somehow change the color of a Form. Passing the handle to the DLL is no problem, but how to use that handle to work with the form that the handle represents?

我专门在做的是将一个DLL组合在一起,其中包含使Delphi7应用程序与Windows7兼容所需的所有内容,例如,绘图玻璃,在任务栏中正确显示多种形式(并最小化形式),绿色任务栏图标上的进度,以及可能涉及的其他任何内容.但是,这种类型的工作需要修改表格.我需要能够从DLL中进行这些修改.

What I'm doing specifically is putting together a single DLL that contains everything needed to make a Delphi7 application compatible with Windows7, for example, drawing glass, properly showing multiple forms in the taskbar (and minimizing forms), showing the green progress in the taskbar's icon, and whatever else might be involved. This type of work though requires modifying the form. I need to be able to do those modifications from within the DLL.

推荐答案

您无法从句柄获取 TForm .除非您使用软件包(如David的回答所述),否则您的Delphi应用程序中没有其他东西.

You can't get a TForm from a handle. There's no such thing outside of your Delphi app, unless you're using packages (as David's answer said).

您可以直接在API调用中使用 Handle ( HWND ),但仅 用于API调用.

You can use the Handle (HWND) directly in API calls, but only for API calls.

您可以将该 HWND 直接传递给API调用,例如 DrawThemeText或其他需要Windows DC 的东西.您还可以将其传递给需要 HWND 的其他API调用.

You can pass that HWND directly to API calls like GetDC to get a device context (DC), and then use that DC directly with the DrawTheme related functions like DrawThemeText or anything else that requires a windows DC. You can also pass it to other API calls that require an HWND.

这篇关于如何从句柄获取TForm实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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