WinApi:GetParent、SetParent、MoveWindow-获取、指定父窗口和移动窗口
2009-11-1914:22
提示: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;
//举例:
unitUnit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls,ExtCtrls;
type
TForm1=class(TForm)
Edit1:TEdit;
Button1:TButton;
procedureButton1Click(Sender:TObject);
end;
var
Form1:TForm1;
implementation
{$R*.dfm}
procedureTForm1.Button1Click(Sender:TObject);
begin
ifGetParent(Edit1.Handle)=Handlethen
begin
Windows.SetParent(Edit1.Handle,Button1.Handle);
MoveWindow(Edit1.Handle,0,0,Edit1.Width,Edit1.Height,True);//这句可以不要
endelsebegin
Windows.SetParent(Edit1.Handle,Self.Handle);
MoveWindow(Edit1.Handle,0,0,Edit1.Width,Edit1.Height,True);//这句可以不要
end;
end;
end.