Author: Jonas Bilinkevicius
How to hide and show the title bar of a TForm
Answer:
Here is how to hide the titlebar:
1 procedure TYourFormName.HideTitlebar;
2 var3 Save: LongInt;
4 begin5 if BorderStyle = bsNone then6 Exit;
7 Save := GetWindowLong(Handle, GWL_STYLE);
8 if (Save and WS_CAPTION) = WS_CAPTION then9 begin10 case BorderStyle of11 bsSingle, bsSizeable:
12 SetWindowLong(Handle, GWL_STYLE, Save and (not (WS_CAPTION)) or WS_BORDER);
13 bsDialog:
14 SetWindowLong(Handle, GWL_STYLE, Save and (not (WS_CAPTION)) or15 DS_MODALFRAME
16 or WS_DLGFRAME);
17 end;
18 Height := Height - GetSystemMetrics(SM_CYCAPTION);
19 Refresh;
20 end;
21 end;
22 23 //And here is how we show it again:24 25 procedure TYourFormName.ShowTitlebar;
26 var27 Save: LongInt;
28 begin29 if BorderStyle = bsNone then30 Exit;
31 Save := GetWindowLong(Handle, GWL_STYLE);
32 if (Save and WS_CAPTION) <> WS_CAPTION then33 begin34 case BorderStyle of35 bsSingle, bsSizeable:
36 SetWindowLong(Handle, GWL_STYLE, Save or WS_CAPTION or WS_BORDER);
37 bsDialog:
38 SetWindowLong(Handle, GWL_STYLE, Save or WS_CAPTION or DS_MODALFRAME or39 WS_DLGFRAME);
40 end;
41 Height := Height + GetSystemMetrics(SM_CYCAPTION);
42 Refresh;
43 end;
44 end;