 |
|
 |
Excelent a very well coded sample.
Very Thanks
|
|
|
|
 |
|
 |
I have 1 check box + 1 icon + text on tree item.
now i want 1 check box + 1 icon + 1 icon + text.
How to achieve this?
RT
Cheers
RunningThread
|
|
|
|
 |
|
 |
I just wants to replace tree control's buttons with arrow images.
Here is my code. i don't know why this is not working.
Please refer the code. Give me suggestion where i am going wrong.
Here is code
void CExTreeCtrl::OnPaint()
{
HDC hdc;
HDC hDcMem; // Memory base device context for flicker free painting
HBITMAP hBitmap;
HBITMAP bm_old;
int old_mode;
hdc = GetDC( m_hWnd );
GetClientRect( m_hWnd,&m_rect );
hDcMem = CreateCompatibleDC( hdc );
hBitmap = CreateCompatibleBitmap( hdc, m_rect.right - m_rect.left , m_rect.bottom - m_rect.top );
bm_old = (HBITMAP) SelectObject( hDcMem, hBitmap );
//old_mode = SetBkMode( hDcMem , TRANSPARENT );
DrawItems( hDcMem );
BitBlt( hdc, m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top, hDcMem, 0, 0, SRCCOPY);
//SetBkMode( hDcMem, old_mode );
SelectObject( hDcMem, bm_old );
//DeleteDC (hDcMem);
}
void CExTreeCtrl::DrawItems( HDC &hDC )
{
HTREEITEM show_item, parent;
RECT rc_item;
DWORD tree_style;
BITMAP bm;
HDC dc_mem;
HBITMAP button;
int count = 0;
int state;
bool selected;
bool has_children;
TV_ITEM tvi;
show_item = TreeView_GetFirstVisible( m_hWnd );
if ( show_item == NULL )
return;
dc_mem = CreateCompatibleDC( NULL );
tree_style = ::GetWindowLong(m_hWnd, GWL_STYLE );
do
{
ZeroMemory(&tvi,sizeof(TV_ITEM));
tvi.hItem = show_item;
tvi.mask = TVIF_STATE|TVIF_CHILDREN;
TreeView_GetItem( m_hWnd, &tvi );
state = tvi.state;
parent = TreeView_GetParent( m_hWnd, show_item );
has_children = tvi.cChildren || parent == NULL;
if ( TreeView_GetItemRect( m_hWnd, show_item, &rc_item, TRUE ) )
{
if ( has_children )
{
if ( state & TVIS_EXPANDED )
{
//button = m_hbmp_tree_open;
button = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_TREE_OPENED ));
}
else
{
//button = m_hbmp_tree_closed;
button = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_TREE_CLOSED ));
}
GetObject( button,sizeof(bm), (LPVOID)&bm);
HBITMAP bmp_old = (HBITMAP) SelectObject( dc_mem,button);
int i = BitBlt( hDC, rc_item.left - bm.bmWidth - 2, rc_item.top, bm.bmWidth, bm.bmHeight,
dc_mem, 0, 0, SRCAND );
// CleanUp
dc_mem = (HDC)SelectObject( hDC, bmp_old );
}
}
} while ( (show_item = TreeView_GetNextVisible( m_hWnd, show_item )) != NULL );
}
Thank You in advance....
|
|
|
|
 |
|
 |
I have used the The VividTree class in my dialog. But it is not listed by the MFC ClassWizard. Is there any specific reason for this. Thanks in advance.
|
|
|
|
 |
|
 |
(chinese)
>正在链接...:linking
1>CVTRES : fatal error CVT1100: 重复的资源(repeat rc)。type:MANIFEST, name:1, language:0x0409
1>LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏(file futile or bad);
Long (xiaohelong China)
龙行天下,为爱永不言弃
|
|
|
|
 |
|
 |
复制资源 CVT1100 致命错误。 type:STRING name:7、 language:0x0409
转换到 COFF 期间失败 " LNK1123 致命错误文件无效或损坏:
第一个错误发生的原因是新资源文件的字符串表中没有字符串项。
如果文件中的现有资源文件和新资源字符串表 ID 冲突出现第二条错误信息。 资源编译器编译字符串表, 时它保留一组的 16 ID。 例如, 如果 ID 100 用于字符串表的第一个资源文件中并使用 ID 110 的第二个资源文件, 字符串表中发生冲突。
要解决此问题, 请按照下列步骤:
1. 新资源文件的字符串表中添加一个字符串条目。
2. 为了避免冲突, 请不要使用字符串 ID 是太关闭到对方的 MFC 项目不同资源文件中。 例如, 如果一个资源文件包含字符串 ID 100, 不使用 ID 值其他资源文件的同一 MFC 项目中 100 到 115 范围中
Sorry, Chinese
|
|
|
|
 |
|
 |
i display the VividTree .
If the item have child that the child icon is IDI_CODE_PROJECT
the parent icon is triangle.
But ,Now i have a problem , i delete a item if the item have't child item
that it's parent icon will become the IDI_CODE_PROJECT so why??
my english is not good
|
|
|
|
 |
|
 |
i use CImagelist attach to VividTree.
buf can't work
Example:
bitmap.LoadBitmap(IDB_ONLINESTATE);
MImage.Create(16, 16, ILC_COLORDDB|ILC_MASK, 2, 1);
MImage.Add(&bitmap, RGB(255,255,255));
Tree.SetImageList(&MImage,TVSIL_NORMAL);
..
Tree.InsertItem(BuddyInfo->UserOnline.UserName,0,0,hRoot);
no image on left??
|
|
|
|
 |
|
 |
The way you are trying to do this is not supported by VividTree. However, it's very easy to solve it a different way. See my previous answer about this here:
http://www.codeproject.com/treectrl/VividTree.asp?df=100&forumid=218049&select=1424744#xx1424744xx
-Jim
|
|
|
|
 |
|
 |
VividTree.obj : error LNK2001: unresolved external symbol __imp__GradientFill@24
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
test.exe - 2 error(s), 0 warning(s)
|
|
|
|
 |
|
 |
Please see my response to the same issue reported earlier.
Thanks
-Jim
http://www.codeproject.com/treectrl/VividTree.asp?df=100&forumid=218049&select=1238191#xx1238191xx
|
|
|
|
 |
|
 |
i will use it in my project.
|
|
|
|
 |
|
|
 |
|
 |
Hello zhoupeter,
This control is designed to look similar to the interface of Skype, so it doesn't the standard support [+|-]. Instead, it uses the triangles both to show expanded/unexpanded state and as the click on item to cause expanding and unexpanding. This is an owner draw control, so you could add your own +/- display code. I'm sure there are some examples of owner draw code that do this within Code Project that you could borrow from. Or, if you don't want the triangles you could just replaces those bitmaps with the +/- bitmaps.
Good Luck,
-Jim
|
|
|
|
 |
|
 |
Hi, Jim
Great thank to your help.
|
|
|
|
 |
|
 |
A question on that - turns out that if you are using icons or bitmaps larger than 16 x 16 on the standard CTreeCtrl, the +/- gets very large. So I am trying to figure out if there is a message or some way to know when just that part is drawn. It appears your code draws the entire item. Or, the other way around, could your code be modified to handle larger bitmaps from image lists as opposed to icons as is does now? TIA
Ed
|
|
|
|
 |
|
 |
We are using your project vivid tree sample for our application.Its fine working to set bitmaps and gradient background for tree controls but we have one bug fixed in that, if we set treecontrol of your class we are not able to add different icons for the tree control sub items,rather we are able to set same icons for each tree. we need to add different icons for a single tree control items of about ten to fifteen icons.please do resolve this so that i can make use of it.
hai
|
|
|
|
 |
|
 |
The class itself only supports one icon. A user wanting to have multiple icons can create their own derived class and override this member function to handle multiple icons.
virtual HICON GetItemIcon( HTREEITEM item ); // Overridable
-Jim
|
|
|
|
 |
|
 |
Hi,
There is a workaround for it, you should add a SetImageListEx to your class and set the icons as usual for the tree:
vividtree.h
public:
inline void SetImageListEx(CImageList* pImageList) { m_pImageList = pImageList;};
private:
CImageList* m_pImageList;
add init to the end of the constructor
m_pImageList = NULL;
If you use the original SetImageList then the icons of the groups will e displayed in wrong position.
You should just add the following lines to the
// Draw TreeCtrl Items
void CVividTree::DrawItems( CDC *pDC )
{
....
if ( !has_children )
{
//original code
// lookup the ICON instance (if any) and draw it
/*
HICON icon;
icon = GetItemIcon( show_item );
if ( icon != NULL )
DrawIconEx( pDC->m_hDC, rc_item.left - 18, rc_item.top, icon, 16, 16,0,0, DI_NORMAL );
*/ //draw icon from image list
if(pImageList) {
POINT pt;
pt.x = rc_item.left - 18;
pt.y = rc_item.top;
pImageList->Draw(pDC,iIcon,pt,ILD_NORMAL);
}
}
Rgds, Domo
|
|
|
|
 |
|
 |
Very nice work on this. This is the only example I could use to expand further. This code is still missing some treestyle support (like checkboxes and lines), but they were quite easily to implement in the DrawItems function.
One problem is getting a bit annoying though. it seems the CTreeCtrl has a mind of it's own when it comes to drawing. If I use pageup/down when the tree contains a lot of items, I can see some distortion caused by the fact that CTreeCtrl wants to scroll the view first and after that, the OnPaint is called. I think the only way to get rid of this is reimplement some of the control functions (scroll, keys, etc), so it doesn't use the default behaviour.
|
|
|
|
 |
|
 |
Hello,
Yes, I should have mentioned that it was not intended to support checkboxes or lines. It's purpose was to serve as it's basis for a skype like interface. CTreeCtrl was simply a nice starting point for this. I could have used ClistCtrl as well, but CTreeCtrl had more of the needed base functionality.
I've never added a large number of tree items to this before as my application that uses this tends to be small. I'll have to give it a try when I can find the time.
Thanks for the feedback,
-Jim
|
|
|
|
 |
|
 |
Hi Jim
I developed an application to share music between Skype user, and I am doing an upgrad to use the App2App in new Skype API, and make it more like a Skype. Your VididTree is exactly what I am looking for.
The old version of my music sharing application is posted on the Skype website. If you are interested, I could send you the new application.
York
|
|
|
|
 |
|
 |
hey man u saved my life! thanks for such an awesome code!
o yeah here are some minor bugs that ive found...
if the object is not inserted from class wizard or if the object is dynamically created from new VividTree or casted from (VividTree ) GetDlgItem(IDC_TREE1) ... Background mode does not apply sometimes, and errors occur if i try to use the SetItemIcon with it.
heres a feature suggestion :
how about skinning also the scrollbars, like some controls here in codeproject.
anyways... your projects great as it is... thanks again.
|
|
|
|
 |
|
 |
The control is great and I implemented it in one of my projects. However, as I add more child in the tree, the vertical scroll bar does not appear although the Scroll property is already checked.
|
|
|
|
 |
|
 |
Hello Breakpoint,
I tried adding a few more child items and shrinking the vertical size of the dialog/tree, but the scroll bar turns on for me without fault. Are you sure you haven't made some other change that might effect this? Please try modifying the orignal test project provided here and see if it works for you. If it still fails, then perhaps it has something to do with the OS your using. I'm currently only testing on WinNT.
-Jim
-- modified at 22:39 Friday 24th February, 2006
|
|
|
|
 |