Solved

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

Posted on 1998-03-06
10
414 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:mdlittle
10 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1360214
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


0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1360215
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
0
 

Author Comment

by:mdlittle
ID: 1360216
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???
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Accepted Solution

by:
TheSwine earned 100 total points
ID: 1360217
Try this:
in The CreateParams add condition based on some member of the object, Somthing like :

inherited CreateParams....
if CaptionExist then
  with Params do...
else
  ....

and whenever you want to change your state call ReCreateWND.
0
 
LVL 1

Expert Comment

by:TheSwine
ID: 1360218
and try this one too:

procedure ...
begin
  SetWindowLong(Handle,GWL_STYLE,     GetWindowLong(Handle,GWL_STYLE) AND NOT WS_CAPTION);
  ClientHeight := Height;
end;
0
 
LVL 1

Expert Comment

by:TheSwine
ID: 1360219
mdlittle, Which one you use the first or the second one?
0
 

Author Comment

by:mdlittle
ID: 1360220
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?
0
 
LVL 1

Expert Comment

by:TheSwine
ID: 1360221
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;

0
 

Author Comment

by:mdlittle
ID: 1360222
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?
0
 
LVL 1

Expert Comment

by:TheSwine
ID: 1360223
Kind of.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question