Friday, February 15, 2008

Adding CheckBox to a TShellTreeView


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ShellCtrls,
ComCtrls;

type
TCheckBoxShellTreeView = class(TShellTreeView)
public
procedure CreateParams(var Params: TCreateParams); override;
end;

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FShellTreeView: TCheckBoxShellTreeView;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

const
TVS_CHECKBOXES = $00000100;

procedure TCheckBoxShellTreeView.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or TVS_CHECKBOXES;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FShellTreeView := TCheckBoxShellTreeView.Create(Self);
with FShellTreeView do
begin
Name := 'FShellTreeView';
Parent := Self;
Root := 'rfDesktop';
UseShellImages := True;
Align := alClient;
AutoRefresh := False;
BorderStyle := bsNone;
Indent := 19;
ParentColor := False;
RightClickSelect := True;
ShowRoot := False;
TabOrder := 0;
end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FShellTreeView.Free;
end;

end.