TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
TForm2 = class(TForm)
private
FAppWindow: Boolean;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
property AppWindow: Boolean read FAppWindow write FAppWindow;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form2 := TForm2.Create(Self);
Form2.AppWindow := True;
Form2.Show;
end;
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited;
if FAppWindow then begin
Params.Style := Params.Style or WS_EX_APPWINDOW;
Params.WndParent := 0;
end;
end;
This doesn't work, because the window handle is created during the constructor of TForm, so CreateParams is run too early and FAppWindow is always False.
Writing a custom constructor also doesn't work since you have to eventually call the inherited constructor which creates the handle before you can save any data to the instance:
constructor TForm2.CreateAppWindow(AOwner: TComponent);
begin
inherited Create(AOwner);
FAppWindow := True;
end;
Is there a way to:
- Delay the creation of the window handle?
- Alter the window style after creation of the window handle?
- Recreate the window handle after the constructor has run?
- Some other option I haven't thought of, yet?
How can I change the style of a form from the "outside" of the class?
RecreateWnd. - TLamaChangeAppWindowinternal procedure does. It sets the style bySetWindowLonginside a pair ofShowWindowcalls (SW_HIDEandSW_SHOWorSW_MINIMIZEpair). I would prefer re-creation here. - TLama