CJC Delphi 技巧馆's Archiver

cjc Posted at 2013-7-12 15:35

Delphi XE2, how to keep form ON TOP after changing VCL styles

Delphi XE2, how to keep form ON TOP after changing VCL styles

I'm using HWND_TOPMOST with SetWindowPos to set my form on top, but if I switch VCL styles at runtime, the window isn't topmost anymore, and unsetting/re-setting it doesn't fix it either.

Any way to fix this?





Your problem is that the form is being recreated because of a style change and loosing its top most style since the VCL have no knowledge of this. Either use:

FormStyle := fsStayOnTop;
or override CreateWindowHandle so that SetWindowPos is called each time the form is recreated:

type
  TForm1 = class(TForm)
    ..
  protected
    procedure CreateWindowHandle(const Params: TCreateParams); override;
  ..

procedure TForm1.CreateWindowHandle(const Params: TCreateParams);
begin
  inherited;
  SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
end;

BTW, I couldn't duplicate "unsetting/re-setting doesn't fix it". With my tests, calling SetWindowPos again fixed it.

Page: [1]
CJC好玩背单词最新版本 - 是目前最好的背单词软件,游戏好玩,功能强大,词库众多,还有真人语音,免费下载,免费试用 !

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.