fsAlwaysontop,setwindowpos(...hwnd_topmost) 均无效果

「已注销」 2013-04-27 11:14:05
将窗口的formstyle属性设置为fsAlwaysontop,无法将窗口置顶
用setwindowpaos api也不行

有谁遇到过这种情况?
...全文
217 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2013-05-03
  • 打赏
  • 举报
回复
自己搞定了。但是原因不清楚
feiba7288 2013-04-27
  • 打赏
  • 举报
回复
如果是在游戏开启的全屏下可能不行。

function BringWindowToTopEx(hWnd: HWND): Boolean;
begin
  if IsIconic(hWnd) then //最小化
    ShowWindow(hWnd, SW_RESTORE);
  if GetForegroundWindow <> hWnd then
    SetForegroundWindow(hWnd);//enabled
    //BringWindowToTop(hWnd);//not enabled
    //ForceForegroundWindow(hWnd);//enabled
    {SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
    SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);//enabled}
    //SwitchToThisWindow(hWnd, True);//enabled
  Result := GetForegroundWindow = hWnd;
end;

function BringWindowToTopMost(hWnd: HWND; bTopMost: Boolean): Boolean;
begin
  if IsIconic(hWnd) then //最小化
    ShowWindow(hWnd, SW_RESTORE);
  if bTopMost then
    SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
  else
    SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;

function BringWindowToTopXY(hWnd: HWND; X, Y: Integer;
  hWndInsertAfter: HWND): Boolean;
begin
  Result := BringWindowToTopEx(hWnd);
  Result := SetWindowPos(hWnd, hWndInsertAfter, X, Y, 0, 0, SWP_NOSIZE)
    and Result;
end;
sololie 2013-04-27
  • 打赏
  • 举报
回复
重写CreateParams怎样?

procedure CreateParams(var params: TCreateParams); override;

procedure TForm1.CreateParams(var params: TCreateParams);
begin
  inherited;
  params.ExStyle:=  params.ExStyle or WS_EX_TOPMOST;
end;
simonhehe 2013-04-27
  • 打赏
  • 举报
回复
你建个新程序, 设formstyle 为 fsAlwaysontop试试

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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