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.
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
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???
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and try this one too:
procedure ...
begin
SetWindowLong(Handle,GWL_S TYLE, GetWindowLong(Handle,GWL_S TYLE) AND NOT WS_CAPTION);
ClientHeight := Height;
end;
procedure ...
begin
SetWindowLong(Handle,GWL_S
ClientHeight := Height;
end;
mdlittle, Which one you use the first or the second one?
ASKER
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_S TYLE, GetWindowLong(Handle,GWL_S TYLE) AND WS_CAPTION);
ReCreateWnd;
Gap := Height - FormerHeight;
Height := Height - Gap;
end;
FormerHeight, Gap : Integer;
begin
FormerHeight := Height;
SetWindowLong(Handle,GWL_S
ReCreateWnd;
Gap := Height - FormerHeight;
Height := Height - Gap;
end;
ASKER
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.
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