如何获得控件的父窗体的句柄?

zhangsss 2007-06-22 09:30:39
如体,我在窗口上拉了一个Component类型的不可视控件
我想得到它所在的窗体的句柄,从而对它的父窗体进行操作
如何得到它父窗体的句柄呢?用什么函数实现?
各位快帮帮忙,有例子更好!
谢谢了!
...全文
234 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
constantine 2007-06-22
  • 打赏
  • 举报
回复
如果设计期那么很明显,如果运行期又不知道你有什么用。
i_love_pc 2007-06-22
  • 打赏
  • 举报
回复
不可视控件一般没有parent属性,有一个owner属性可以试一下。
zhangsss 2007-06-22
  • 打赏
  • 举报
回复
看不太懂,用中文讲吧,谢谢了
LuoGD 2007-06-22
  • 打赏
  • 举报
回复
Component->Parent

Indicates the interface of the component抯 parent, if any.

typedef System::DelphiInterface< IComponent > _di_IComponent;
__property _di_IComponent Parent = {read=GetParent};

Description

The parent of a component is responsible for writing the control to a stream when the form is saved. If the component represents a control, the parent is a windowed control that visually contains the component. Not all components have parents.

Note: Don't confuse the Parent property with the Owner property. The component is always a constituent part of its parent (such as a tool button on a tool bar), while the owner is responsible for freeing the component.
shadowstar 2007-06-22
  • 打赏
  • 举报
回复
TComponent - 组件,没有句柄,有同为 TComponent 类的 Owner 属性,即创建时输入的参数 AOwner。

TControl - 控件,派生自TComponent,有句柄Handle,有同为 TControl 类的Parent(可能为NULL)。

==================
回复人:constantine(飘遥的安吉儿) ( 四星(高级)) 信誉:136 2007-6-22 11:45:29 得分:0
?

如果设计期那么很明显,如果运行期又不知道你有什么用。


楼主没明白?就是说设计期你已经知道是哪一个窗体了,还要费劲得它的句柄有何用?
zhangsss 2007-06-22
  • 打赏
  • 举报
回复
如果设计期那么很明显,如果运行期又不知道你有什么用。
---------------------------------------------------
上面这个大哥的话我不太明白,您能帮帮我么?
TComponent类型的控件的句柄如何得到啊?它所在的父窗体的句柄是通过GetParent(Handle)得到的,所以我必须要知道这个控件的句柄
我看网上有些人说的是,好象要先在构造函数里用AllocateHWnd创建1个句柄,然后在析构函数里释放掉这个句柄.是这样的么?
请高手快来解答.

(老妖)大哥在么?快来帮帮我

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧