Board index » delphi » TreeView & State Images Question

TreeView & State Images Question

Delphi 4.01 Pro
Platform Win NT 4.0 SP3

I basically want to implement a TreeView control that uses state pictures
which look like:
1) Blank checkbox
2) Checked checkbox
3) Grayed checked checkbox

I want it to emulate the Windows 95/98 Backup program with the checkboxing
of folders and what not.

My problem: how can you (programmatically) tell when the state picture (i.e.
the checkbox picture) in the TreeView control was clicked?

If you cannot tell this, exactly what are the state pictures really good
for?

I'm sure somebody must have implemented something like this.  Anybody help
me out?

Thanks,
Brian Simmons
bsimm...@centrasoft.com
http://www.centrasoft.com

 

Re:TreeView & State Images Question


You can use the OnMouseDown event, and then check whether the X and Y values
correspond to the coordinates of the state picture. This is a little long
winded, but it works. You have to use a method like ItemAtPos to find the
item that is at the Y coordinate, and then by checking it's nesting level,
you should be able to determine, the X position of the State Image.

                Hope this helps
                            David

Quote
Brian Simmons wrote in message <7168d0$s0...@juliana.sprynet.com>...
>Delphi 4.01 Pro
>Platform Win NT 4.0 SP3

>I basically want to implement a TreeView control that uses state pictures
>which look like:
>1) Blank checkbox
>2) Checked checkbox
>3) Grayed checked checkbox

>I want it to emulate the Windows 95/98 Backup program with the checkboxing
>of folders and what not.

>My problem: how can you (programmatically) tell when the state picture
(i.e.
>the checkbox picture) in the TreeView control was clicked?

Re:TreeView & State Images Question


In article <7168d0$s0...@juliana.sprynet.com>,
  "Brian Simmons" <bsimm...@sprynet.com> wrote:

Quote
> I basically want to implement a TreeView control that uses state pictures
> which look like:
> 1) Blank checkbox
> 2) Checked checkbox
> 3) Grayed checked checkbox
> My problem: how can you (programmatically) tell when the state picture (i.e.
> the checkbox picture) in the TreeView control was clicked?

You may use the following functions to get/set the State of the checkboxes:

function  GetItemState(Item: TTreeNode; var State: TCheckBoxState): Bool;
var
  TVItem:   TTVItemA;
begin
  // ermittelt, ob angegebenens (Selectiertes) Gew?hlt ist
  result := false;
  if Item = nil then Item := Selected;
  if Item <> nil then begin
    FillChar(TVItem, SizeOf(TVItem), 0);
    TVItem.mask           := TVIF_STATE or TVIF_HANDLE;
    TVItem.hItem          := Item.ItemId;
    TVItem.stateMask      := TVIS_STATEIMAGEMASK;

  result := Bool(SendMessage(Item.Handle, TVM_GETITEM, 0, Longint(@TVItem)));
 case TVItem.state and $3000 of  $0000: State := cbUnChecked; // no Checkbox
?  $1000: State := cbUnChecked;  $2000: State := cbChecked;  $3000: State :=
cbGrayed;  end;  end; end;

function  SetItemState(Item: TTreeNode; State: TCheckBoxState): Bool; var
TVItem:  TTVItemA; begin  result := false;  if Item = nil then Item :=
Selected;  if Item <> nil then begin  FillChar(TVItem, SizeOf(TVItem), 0);
TVItem.mask  := TVIF_STATE or TVIF_HANDLE;  TVItem.hItem  := Item.ItemId;
TVItem.state  := (Integer(State)+1) shl 12;  TVItem.stateMask  :=
TVIS_STATEIMAGEMASK;  //TreeView_SetItem(Item.Handle, TVItem);  result :=
Bool(SendMessage(Item.Handle, TVM_SETITEM, 0, Longint(@TVItem)));  end; end;

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Other Threads