Search code examples
delphimdi

Delphi 12 MDI: Change caption color?


Prior to Delphi 12, MDI children were displayed in the Windows 7 Aero design, even with Windows 11.

New to Delphi 12 is that the MDI children have the typical Windows 10/11 design, which is amazing in my opinion!

MDI children

However, I dislike that the caption of every MDI child is white, since white is usually the color of inactive windows. I wonder, can I somehow change the color of the MDI children's border to anything but white?

I have tried the following code, which works on the main form, but does not work on MDI children:

procedure TFormXYZ.CreateWnd;
var
  col: COLORREF;
begin
  inherited;
  col := 0; // black
  DwmSetWindowAttribute(WindowHandle, DWMWA_CAPTION_COLOR, @col, SizeOf(COLORREF));
  DwmSetWindowAttribute(WindowHandle, DWMWA_BORDER_COLOR, @col, SizeOf(COLORREF));
end;    

Thank you for the help.


Solution

  • Since Delphi 12 MDI child forms are no longer drawn by Windows but by the VCL itself, more precisely, the drawing is handled by TChildFormMessageHandler. In this class the border color is taken from a constant cBorderColor, which has the value clWhite.

    Unfortunately this class is private and there is no official way to replace the implementation or somehow tweak it, except by using your own copy of Vcl.Forms.pas.

    Either way I suggest to file a feature request at Quality Portal having different border colors for active and inactive MDI child forms.