1. December 2011 00:06
If you use VCL styles from Delphi XE2 and TRibbon control (or maybe Glass window on Vista +) you can see some drawing problems. But there is a way to modify how can VCL draw element and you can use this.
For me there is a problem with drawing on NonClient (NC) area of form. When style is used, NC area is painted by VCL and not by Windows (maybe this can apply for glass windows too).
Basic of style painting is class TStyleHook from unit Vcl.Themes and it's descendant TFormStyleHook. In base class there is a property OverridePaintNC, or PaintNC(Canvas: TCanvas) method for painting on NC area.
So little class:
VCL.Graphics, VCl.Controls, Vcl.Forms;
procedure PaintNC(Canvas: TCanvas); override;
procedure TMyStyleHookClass.PaintNC(Canvas: TCanvas);
OverridePaintNC := False;
In PaintNC set OverridePaintNC to false (tried in constructor, but this is better).
Remark: in VCL is called in this way:
procedure TStyleHook.WMNCPaint(var Message: TMessage);
if FOverridePaintNC then
Canvas := TCanvas.Create;
Canvas.Handle := GetWindowDC(Control.Handle);
Canvas.Handle := 0;
Handled := True;
And now VCL will use our class instead of original:
TStyleManager.Engine.UnRegisterStyleHook(TCustomForm, TFormStyleHook);//unregister the original style hook
TStyleManager.Engine.RegisterStyleHook(TCustomForm, TMyStyleHookClass); //register the new style hook
Fix: TCustomForm not TForm
So TRibbon and VCL styles can work together.