Solved

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

Posted on 1998-03-06
10
411 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

22 Experts available now in Live!

Get 1:1 Help Now