Solved

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

Posted on 1998-03-06
10
410 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Accepted Solution

by:
TheSwine earned 100 total points
Comment Utility
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
Comment Utility
and try this one too:

procedure ...
begin
  SetWindowLong(Handle,GWL_STYLE,     GetWindowLong(Handle,GWL_STYLE) AND NOT WS_CAPTION);
  ClientHeight := Height;
end;
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:TheSwine
Comment Utility
mdlittle, Which one you use the first or the second one?
0
 

Author Comment

by:mdlittle
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Kind of.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now