Link to home
Start Free TrialLog in
Avatar of mdlittle
mdlittle

asked on

Toggle the caption (title) bar of a form at run time

How can you toggle the caption bar of the main form at run time? In other words I want to be able to show and hide the caption (title) bar at run time.
Avatar of inter
inter
Flag of Türkiye image

There may be other ways but as far as I know:

To off caption:

  LockWindowUpdate(Handle); // prevent flicker
  Form1.Caption := '';
  Form1.BorderIcons := [];
  Form1.BorderStyle := bsNone;
  LockWindowUpdate(Handle);

To on

  LockWindowUpdate(Handle); //prevent flicker
  Form1.Caption := 'My form caption';
  Form1.BorderIcons :=[biSystemMenu, biMinimize, biMaximize];
  Form1.BorderStyle := bsSizeable;
  LockWindowUpdate(Handle);

Regards
Igor


Avatar of MikeP090797
MikeP090797

I don't know much about Delphi, but you can use the SetWindowLong with GWL_STYLE to set a new style for the window, without the caption. Get the previous one, and remove WS_CAPTION from it
Avatar of mdlittle

ASKER

This kinda works. I really need to keep the sizeable border, though. Here is how I currently remove the caption:

If the form's class declaration:
procedure CreateParams(var Params: TCreateParams); override;

The actual procedure:
procedure TfrmMain.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
    Style := (Style or WS_POPUP) and (not WS_DLGFRAME);
end;

Now, how do I get the title bar back at run time if I want???
ASKER CERTIFIED SOLUTION
Avatar of TheSwine
TheSwine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and try this one too:

procedure ...
begin
  SetWindowLong(Handle,GWL_STYLE,     GetWindowLong(Handle,GWL_STYLE) AND NOT WS_CAPTION);
  ClientHeight := Height;
end;
mdlittle, Which one you use the first or the second one?
I tried the second and (I'm a bit new to Delphi) have not yet figured out how to make the caption reappear. The first one reinitializes my application so I would have to do some heavy recoding to use it. I like the second but have not figured out how to use SetWindowLong to get the caption back. Any suggestion?
var
  FormerHeight, Gap : Integer;
begin
  FormerHeight := Height;
  SetWindowLong(Handle,GWL_STYLE, GetWindowLong(Handle,GWL_STYLE) AND WS_CAPTION);
  ReCreateWnd;
  Gap := Height - FormerHeight;
  Height := Height - Gap;
end;

OK. I made some minor mods to the TForm.show event and now my program does not reinitialize when doing the above. This works great thanks for your help. BTW, am I correct in understanding that ReCreateWnd only recreates the form but leaves your applications memory intact?
Kind of.