function TitleBarHeight (Form: TForm) : Integer;
var ws : TWindowState;
oldheight : integer;
count : integer = 0;
begin
ws := Form.WindowState;
if ws <> wsMaximized then
begin
oldHeight := Form.Height;
Form.WindowState := wsMaximized;
repeat
Application.ProcessMessages; // let Form expand
// but one ProcessMessages may be not enough!
inc (Count);
until (Form.Height<>oldHeight) or (count >= 10);
end;
result := Form.Monitor.WorkAreaRect.Height -Form.Height;
if ws <> wsMaximized then
begin
Form.WindowState := ws; // and back again
Application.ProcessMessages;
end;
end;