Delphi WinApi: GetParent、SetParent、MoveWindow - 获取、指定父窗口和移动窗口


本文整理自网络,侵删。

 
提示: SetParent 应该 Windows.SetParent, 因为 TForm 的父类有同名方法.
//声明:

{获取父窗口句柄}
GetParent(hWnd: HWND): HWND;

{指定父窗口}
SetParent(
  hWndChild: HWND;    {子句柄}
  hWndNewParent: HWND {父句柄}
): HWND;              {成功返回原父窗口句柄; 失败返回 0}

{移动窗口}
MoveWindow(
  hWnd: HWND;               {窗口句柄}
  X, Y: Integer;            {位置}
  nWidth, nHeight: Integer; {大小}
  bRepaint: BOOL            {True 表示刷新; False 表示不刷新}
): BOOL;


//举例:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if GetParent(Edit1.Handle)=Handle then
  begin
    Windows.SetParent(Edit1.Handle, Button1.Handle);
    MoveWindow(Edit1.Handle, 0,0, Edit1.Width, Edit1.Height, True);
  end else begin
    Windows.SetParent(Edit1.Handle, Self.Handle);
    MoveWindow(Edit1.Handle, 0,0, Edit1.Width, Edit1.Height, True);
  end;
end;

end.


相关阅读 >>

Delphi idhttp使用代理ip

Delphi 链接获取主站地址

Delphi用api设置定时器

Delphi 获取窗体坐标

Delphi 2009 泛型容器单元(generics.collections)[5]: tobject...<t> 系列

winapi 字符及字符串函数(8): ischarupper - 是否是个大写字母

Delphi wm_copydata的应用

Delphi 2009 查看所有 unicode 字符

Delphi 验证ip地址

Delphi 利用windows api判断文件共享锁定状态

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...