1

I am using the new VCL styles system in Delphi XE2 and its work fine but on one Form I want exception. This Form contains number of TBitBtn control and each TBitBtn control has its own Font colour (clRed, clBlue, clLime etc) different from other. Due to Style implementation all TBitBtn control’s Caption is display in black colour instead of set colour. Is there any TStyleHook, which can be register on TBitBtn control, which disabled the Style on TBitBtn Control on that form?

RobertFrank
  • 7,332
  • 11
  • 53
  • 99
  • 2
    Why you are using a `TBitBtn` instead of a `TButton`? I ask because the `TButton` uses a Vcl style hook and can be customizable easily. – RRUZ Aug 30 '12 at 18:08
  • We recently migrated our application from Delphi 4 to Delphi XE2. This TBitBtn button functionality was introduce decade ago and we don't why it was used that time. It is always risky to change a working code so I am little sceptical to change control without giving through thought. If we find a workable solution without too much code change than it is good else have to think differently and introduce new component as you suggested which will required more testing and effort. – Sanjay Gajbhiye Aug 31 '12 at 06:25

1 Answers1

2

The TBitBtn component doesn't use a vcl style hook, this control use the TButtonGlyph class (which is defined and implemented in the implementation part of the Vcl.Buttons unit) to draw the button using the Windows theme or the current vcl style, this class (TButtonGlyph) is not accessible outside of this unit , so you are out of luck here.

The only option which comes to my mind is create a interposer class and intercept the CN_DRAWITEM message for the TBitBtn control and then execute your own code to draw the button.

  TBitBtn = class(Vcl.Buttons.TBitBtn)
  private
   procedure MyDrawItem(const DrawItemStruct: TDrawItemStruct);
  public
   procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
  end;

procedure TBitBtn.CNDrawItem(var Message: TWMDrawItem);
begin
  MyDrawItem(Message.DrawItemStruct^);
end;

procedure TBitBtn.MyDrawItem(const DrawItemStruct: TDrawItemStruct);
begin
  //the new code goes here.
end;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Seems like I'd almost want to just take all the TBitBtn's out and use something else. But if that's out of the question, then this would be the way to go. I really dislike those "implementation section classes". TSpeedButton uses one too. – Warren P Aug 31 '12 at 01:22
  • I don't think this solution is much help as you mention TButtonGlyph is private. It seems I need to change TBitBtn with some other control – Sanjay Gajbhiye Sep 03 '12 at 06:46