Board index » delphi » HELP: What does MFC's SetItemState() do?

HELP: What does MFC's SetItemState() do?

I am trying to port the TreeView's multi select example found at
codeguru.com to the Delphi version. This example calls setItemState
and getItemState quite heavily. An example would be:

SetItemState( hClickedItem, TVIS_SELECTED, TVIS_SELECTED );

What does this SetItemState do? Is it a wrapper for the TVM_SETITEM
or TVM_SELECTITEM or what?

Can someone help me, please?

Regards,
Nasir (nn...@cris.com)

 

Re:HELP: What does MFC's SetItemState() do?


In article <6dhn6k$...@examiner.concentric.net>, NNOOR <Nn...@cris.com>
writes

Quote

>I am trying to port the TreeView's multi select example found at
>codeguru.com to the Delphi version. This example calls setItemState
>and getItemState quite heavily. An example would be:

>SetItemState( hClickedItem, TVIS_SELECTED, TVIS_SELECTED );

>What does this SetItemState do? Is it a wrapper for the TVM_SETITEM
>or TVM_SELECTITEM or what?

The class function is declared thus:

CTreeCtrl::SetItemState
BOOL SetItemState( HTREEITEM hItem, UINT nState, UINT nStateMask );

hItem   Handle of the item whose state is to be set.
nState   Specifies new states for the item.
nStateMask   Specifies which states are to be changed.

Sets the state of the item specified by hItem.

The following are *very* awkward and can be accomplished much
more neatly with Delphi's TTreeView properties:

The states are:
TVIS_CUT   The item is selected as part of a cut and paste operation.
TVIS_DISABLED   The item is disabled and is drawn using the standard
disabled style and color.
TVIS_DROPHILITED   The item is selected as a drag-and-drop target.
TVIS_EXPANDED   The items list of child items is currently expanded;
that is, the child items are visible. This value applies only to parent
items.
TVIS_EXPANDEDONCE   The items list of child items has been expanded
at least once. The TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification
messages are not sent for parent items that have specified this value.
This value applies only to parent items.
TVIS_FOCUSED   The item has the focus and is surrounded by a standard
focus rectangle. Although more than one item may be selected, only one
item can have the focus.
TVIS_OVERLAYMASK   The items overlay image is included when the item
is drawn. The index of the overlay image must be specified in the state
member of the TV_ITEM structure by using the Win32 INDEXTOOVERLAYMASK
macro. The overlay image must be added to the tree views image list by
using the CImageList::SetOverlayImage function. This value should not be
combined with any other value.
TVIS_SELECTED   The item is selected. The appearance of a selected
item depends on whether it has the focus and on whether the system
colors are used for selection.
TVIS_STATEIMAGEMASK   The items state image is included when the item
is drawn. The index of the state image must be specified in the state
member of the TV_ITEM structure by using the Win32 INDEXTOSTATEIMAGEMASK
macro. This value should not be combined with any other value.

Maybe you could write your own SetItemState and GetItemState
functions that take a TTreeNode and a set of constants as parameters:

type
  TNodeState = (nsCut, nsDisabled... blah blah);

function SetItemState(node : TTreeNode; State : set of TNodeState);

--
Jeremy Collins

Re:HELP: What does MFC's SetItemState() do?


Thanks very much for the help.
The trick was that stateMask has to be set to TVIS_SELECTED as well.
I couldn't find it anywhere. I was *only* setting "state".

Regards,
Nasir

Other Threads