Tuesday, February 28, 2006

D2006: How to disable the IDEs gradient toolbars

A newsgroup poster recently asked if he could disable the gradient toolbars for BDS 2006. Unfortunately this is not possible within the IDE but it is possible with a little bit of code.

This post will probably not format too well!

  1. Save the code below in a unit called TBCAddIn.
  2. Create a New Win32 Package
  3. Add the TBCAddIn Unit to the Package
  4. Install the Package into the IDE
  5. Making the change configurable is an exercise left to the reader...

I installed the package and it worked. Restarting the IDE also showed the gradient disabled. Making additional toolbars visible while running the IDE also showed those toolbars with the gradient disabled.


Generated with HyperDelphi




unit TBCAddIn;

interface

type
TTBCConfig = class
public
class procedure SetGradient(const aVisible: Boolean);
end;

procedure Register;

implementation

uses
Classes
, Controls
, ComCtrls
, Windows
, ExtCtrls
;

procedure Register;
begin
// disable the toolbar gradient by default
TTBCConfig.SetGradient(False);
end;

{ TTBCConfig }

const
MAIN_WND_CLASS = 'TAppBuilder';

class procedure TTBCConfig.SetGradient(const aVisible: Boolean);
var
i: Integer;
lWinCtrl: TWinControl;
lWnd: Hwnd;
lCtrlBar: TControlBar;
begin
lWnd := FindWindow(MAIN_WND_CLASS, nil);
lWinCtrl := FindControl(lWnd);
if lWinCtrl <> nil then
begin
lCtrlBar := nil;
// find the control bar on the app builder form
for i := 0 to lWinCtrl.ControlCount - 1 do
begin
if lWinCtrl.Controls[i] is TControlBar then
begin
lCtrlBar := TControlBar(lWinCtrl.Controls[i]);
break;
end;
end;
if lCtrlBar <> nil then
begin
// disable/enable gradient for controlbar depending on parameter
if aVisible then
lCtrlBar.DrawingStyle := ExtCtrls.dsGradient
else
lCtrlBar.DrawingStyle := ExtCtrls.dsNormal;
for i := 0 to lCtrlBar.ControlCount - 1 do
begin
if lCtrlBar.Controls[i] is TToolbar then
begin
// disable/enable gradient for toolbars depending on parameter
if aVisible then
TToolbar(lCtrlBar.Controls[i]).DrawingStyle := ComCtrls.dsGradient
else
TToolbar(lCtrlBar.Controls[i]).DrawingStyle := ComCtrls.dsNormal;
end;
end;
end;
end;
end;

end.

3 Comments:

Blogger iSkomorokh said...

Very useful code example! Thanks!

10:29 PM  
Blogger TOndrej said...

Isn't AppBuilder simply Application.MainForm? ;-)

2:54 PM  
Blogger JED said...

Hi TOndrej,

More than one way to skin a cat :-)

9:17 AM  

Post a Comment

<< Home