频道分类

Delphi WinAPI: GetParent - 获取指定窗口的父窗口句柄

作者:admin 来源: 日期:2020/10/15 23:05:39 人气: 标签:

 
WinAPI: GetParent - 获取指定窗口的父窗口句柄
//声明:
GetParent(
  hWnd: HWND {窗口句柄}
): HWND;     {返回父窗口句柄}


//举例:
procedure TForm1.Button1Click(Sender: TObject);
var
  h1,h2: HWND;
begin
  h1 := GetParent(Button1.Handle);
  h2 := Panel1.Handle;
  ShowMessage(IntToStr(h1)); {590862}
  ShowMessage(IntToStr(h2)); {590862}

  h1 := GetParent(Panel1.Handle);
  h2 := Self.Handle;
  ShowMessage(IntToStr(h1)); {459824}
  ShowMessage(IntToStr(h2)); {459824}

  ShowMessage(IntToStr(GetParent(Handle))); {0}
end;