Windows-Delphi 窗口置顶

露从今夜白,月是故乡明。

1.Delphi将窗口置顶

 if topHwnd <> 0 then
    begin
      SetWindowPos(topHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
      tmr1.Enabled := True;
    end;

其中topHwnd是目标窗口的句柄。

2.窗口取消置顶

if topHwnd <> 0 then
    begin
      SetWindowPos(topHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
        SWP_NOSIZE);
      tmr1.Enabled := True;
    end;

将 HWND_TOPMOST 改成 HWND_NOTOPMOST 即可。

3.获取窗口祖句柄

function GetTopLevelWindowHandle(HWND: HWND): HWND;
begin
  Result := HWND;
  while (Result <> 0) and (GetParent(Result) <> 0) do
    Result := GetParent(Result);
end;

一般设置祖窗口句柄,不然可能不会生效。

你可能感兴趣的:(Delphi,Windows,windows,Delphi,pascal)