Solved

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

Posted on 1998-03-06
10
413 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 133
Downloading email attachments 2 73
LAN or WAN ? 11 91
FMX and jaudiotracker playing memory stream 29 78
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 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