Setting treeview checkbox state

Setting treeview checkbox state

I am trying to use CVF 6.1 (though I also have v6.6 that I haven't installed yet) to set the checkbox state on a treeview control. The SDK gives the example in C below. I can duplicate this in Fortran except for the line where tvItem.state = INDEXTOSTATEIMAGEMASK... But when I do that, the fortran compiler says INDEXTOSTATEIMAGEMASK is undefined (though I call "use dfwin" and "use Comctl32"). Any ideas would be appreciated.

Larry Scheier
SEI Associates

BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck)
{
TVITEM tvItem;

tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK;

/*
Since state images are one-based, 1 in this macro turns the check off, and
2 turns it on.
*/
tvItem.state = INDEXTOSTATEIMAGEMASK((fCheck ? 2 : 1));

return TreeView_SetItem(hwndTreeView, &tvItem);
}

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

INDEXTOSTATEIMAGEMASK is just a C macro. Since Fortran does not support macros, Compaq has turned these "pseudo-APIs" into functions and assembled them in DFWIN.lib (with interfaces in DFWIN). However, not all are translated, and this one is not even supported in 6.6B.

MSDN says that:

The INDEXTOSTATEIMAGEMASK macro is defined as follows:
#define INDEXTOSTATEIMAGEMASK(i) ((i) << 12)

which is matched with ISHL(i,12) in Fortran.

Jugoslav

Jugoslav
www.xeffort.com

Thanks, Jugoslav. That was exactly the hint I needed. For anyone interested how to set a treeview checkbox state, here is the code:

SUBROUTINE TreeView_SetCheckState(TVitem, hItem, fCheck)
USE Comctl32
INTEGER*4 hItem !handle to treeview item
INTEGER*4 fCheck !1=turn checkbox off; 2= turn checkbox on
TYPE (T_TVITEM) TVitem !Treeview item structure

!* Validate item properties to be returned
tvItem.mask = IOR(TVIF_TEXT, IOR(TVIF_HANDLE , TVIF_STATE))

!* Pass handle of selected tree item
tvItem.hItem = hItem

!* Set stateMask flag
tvItem.stateMask = TVIS_STATEIMAGEMASK

!* Since state images are one-based, 1 in this macro turns the check off,
!* and 2 turns it on.
tvItem.state = ISHL(fCheck,12)

END SUBROUTINE

Leave a Comment

Please sign in to add a comment. Not a member? Join today