第一个问题,看看CTreeCtrl类的InsertItem()、SetImageList()
第二个不知道,呵呵
第二个不知道,呵呵
解决方案 »
- WTL在REBAR里创建工具栏到新行如何设置到靠右显示
- vs2005 向导生成的mfc项目无法编译成功
- [VC7.1]编译工程到一半时就没动静了,是工程设置问题还是VC的问题?
- 怎么判断 计算机是否装了 摄像头 ! 请求代码 最好 VC 的!
- !!!!!!!VC(数据库)群(10647837)欢迎高手加入,要考试通过才可以进入的(请找272319436考试,通过后方可加入)!!!!
- 分解字符串的简单问题,求最简洁的方法
- 怎样实现窗体的部分透明?
- 寻求一个Windows API ---共享文件夹
- ((WORD) ('M' << 8) | 'B')) 这句能解释一下吗?
- 如何将vc程序打包生成setup文件
- 4.从底层编写富文本编辑器的一些问题?欢迎讨论!(龙星)
- 如何实现XP风格的平面菜单
Setting up state images--------------------------------------------------------------------------------As you are already aware, the tree view control can display two images for each item. Each of these two images belong in different image list controls that have to be associated with the tree control. Whereas, an item can have upto 256 item images, it can only have 15 state images. Nevertheless, the programming for the state images is very similar to the programming for item images.
An image list has to be created before it can be associated with the tree view control. You can create the image list from a single bitmap, horizontally laid out to contain all the images or you can add individual icons to the image list. Step 1: Create the bitmap
Add a bitmap resource in the resource editor that contains all the icons. Here is an example below. The individual icons in this bitmap are 13x13 pixels, but you may choose a different size and it need not be a square. The first image in the list is not used.
Step 2: Add a member variable to hold the image list
The member variable is usually added to the class that is responsible for setting up the tree view control. This would usually be the CView derivative or a CDialog derivative. You can also add the member variable to the sub-class of CTreeCtrl which is what I recommend.
class CTreeCtrlX : public CTreeCtrl
{
// Construction
public:
CTreeCtrlX();// Attributes
public:
CImageList m_imageState ;
:
:
:}
Step 3: Create and set the image list
Call the Create() function of the image object with the resource id of the bitmap we created in step 1 and the width of each icon. The height of the icons is automatically set to the height of the bitmap. The third argument required by the Create() function represents the number of new images the resized image list can contain. Since we are creating the image list from a bitmap, we would normally not add any more images at runtime so we let this value be one. The last argument is the mask color. That is, all the pixels of this color will behave as a transparent color. Since normally the window color is white, we set the mask color to white.
Once the image list has been created, the tree view control has to be instructed to use it. We do that by calling the SetImageList() function. The following statement usually belongs in the OnInitDialog() function or the OnInitialUpdate() function. Note that in the call to SetImageList(), the second argument is TVSIL_STATE.
m_tree.m_imageState.Create( IDB_STATE, 13, 1, RGB(255,255,255) );
m_tree.SetImageList( &(m_tree.m_imageState), TVSIL_STATE );
Step 4: Specify state icons for the items
Once an image list has been associated with the tree view control, you can instruct the tree view control to the use the state image you want when inserting an item to the control. You can also use the SetItemState() image function. In both the cases you have to use the macro INDEXTOSTATEIMAGEMASK(). This macro essentially rearranges the bits of the index value to be compatible with what the tree view control expects. To remove the state image for an item, use the index zero. Here are example usages –
// Using TV_INSERTSTRUCT
CString str = "xyzASDFqwerZCV";
TV_INSERTSTRUCT tv_is;
tv_is.hParent = parent ? parent : TVI_ROOT;
tv_is.hInsertAfter = TVI_LAST ;
tv_is.item.mask = TVIF_TEXT | TVIF_STATE;
tv_is.item.stateMask = TVIS_STATEIMAGEMASK;
tv_is.item.state = INDEXTOSTATEIMAGEMASK( 1 );
tv_is.item.pszText = str.GetBuffer(1);
tv_is.item.cchTextMax = str.GetLength();
hItem = InsertItem( &tv_is );
str.ReleaseBuffer();
// Using SetItemState
SetItemState( hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK );