Jump to content
  • Advertisement
Sign in to follow this  
hick18

[win32] TreeView State Images

This topic is 2698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to create my tree where when creating a node, the check box is initially checked. Yet with the following code, they are not checked. Any ideas?


TreeView::TreeView( const std::string& Name, bool CheckBoxes )
: Window(Name)
{
DWORD Style = WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_LINESATROOT | TVS_NOHSCROLL;

if( CheckBoxes )
{
Style |= TVS_CHECKBOXES;
}

m_hWinapiTreeView = CreateWindow( WC_TREEVIEW, Name.c_str(), Style,
0, 0, 0, 0, GetHandle(), (HMENU)0, g_hInstance, NULL);
}



HTREEITEM TreeView::AddNode( const std::string& Name, HTREEITEM ParentHandle ) // Default ParentHandle == TVI_ROOT
{
TVITEM tvItem;
ZeroMemory( &tvItem, sizeof(TVITEM) );
tvItem.mask = TVIF_TEXT | TVIF_STATE;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
tvItem.state = INDEXTOSTATEIMAGEMASK(2);
tvItem.pszText = (LPSTR)Name.c_str();
tvItem.cchTextMax = Name.size();

TVINSERTSTRUCT tvInsert;
ZeroMemory( &tvInsert, sizeof(TVINSERTSTRUCT) );
tvInsert.item = tvItem;
tvInsert.hInsertAfter = TVI_LAST;
tvInsert.hParent = ParentHandle;

return (HTREEITEM)SendMessage( m_hWinapiTreeView, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsert);
}

Share this post


Link to post
Share on other sites
Advertisement
Edit :

Version 4.70. Enables check boxes for items in a tree-view control. A check box is displayed only if an image is associated with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box altogether. For more information, see Working with state image indexes.

Version 5.80. Displays a check box even if no image is associated with the item.

Once a tree-view control is created with this style, the style cannot be removed. Instead, you must destroy the control and create a new one in its place. Destroying the tree-view control does not destroy the check box state image list. You must destroy it explicitly. Get the handle to the state image list by sending the tree-view control a TVM_GETIMAGELIST message. Then destroy the image list with ImageList_Destroy.

[color="#ff0000"]If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.

[/quote]


DWORD Style = WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_LINESATROOT | TVS_NOHSCROLL | TVS_SHOWSELALWAYS;

m_hWinapiTreeView = CreateWindow( WC_TREEVIEW, Name.c_str(), Style, 0, 0, 0, 0, GetHandle(), (HMENU)0, g_hInstance, NULL);

if( CheckBoxes )
{
SetWindowLong( m_hWinapiTreeView, GWL_STYLE, Style | TVS_CHECKBOXES );
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!