|
|
 Prize winner in Competition
"Best C++/MFC article of Jul 2007"
Comments and Discussions
|
|
 |

|
Great job!!! give me much help!!! thanks!!!
|
|
|
|
|

|
That's what I needed, and this is how I solved. Maybe someone will need this
ps: a big for your share, thanks.
LRESULT CAccessSetDeviceRoles::OnTreeCheckbox(WPARAM wParam, LPARAM lParam)
{
XHTMLTREEMSGDATA *pData = (XHTMLTREEMSGDATA *)wParam;
ASSERT(pData);
if(pData){
HTREEITEM hItem = pData->hItem, hParent;
BOOL bCheckedItem = m_treeCtrl.GetCheck(hItem);
hParent = m_treeCtrl.GetParentItem(hItem);
if (hParent && !bCheckedItem) {
BOOL bCheck = m_treeCtrl.GetCheck(hParent);
if (bCheck) {
m_treeCtrl.SetCheck(hItem, TRUE);
return 0;
}
}
}
return 0;
}
modified 6-Sep-12 11:53am.
|
|
|
|

|
when drag and then drop, tooltip text(note) for the item dragged disappeared when using savexml() to write xml file.
|
|
|
|

|
Firstly hanks for your great job!
I want to use xhtmltree in my vc6 project.
While inlcuding unicode char in .xml file and using loadxmlfromfile() to load it,
parsing is failed, and tree item name is set null(and all sub item disappeared.).
When loading from xml file, i used the parameter: CXHtmlTree::ConvertToUnicode.
|
|
|
|

|
very nice class with great documentation!
thanks
|
|
|
|
|

|
The tree does not respect the TVS_SHOWSELALWAYS style. That is, the tree always shows selected items (nodes) in the standard selected colors, even if TVS_SHOWSELALWAYS is not turned on. This is annoying if you are using color to represent the state of something.
The fix for this is straightforward. In CXHtmlTree::OnCustomDraw, find the two occurrences of
if ((hItem == hSelected) ||
(GetItemState(hItem, TVIF_STATE) & TVIS_DROPHILITED))
Before the first occurrence, insert:
bool UseSelectedColors =
(GetItemState(hItem, TVIF_STATE) & TVIS_DROPHILITED) ||
((hItem == hSelected) &&
((GetStyle() & TVS_SHOWSELALWAYS) || (::GetFocus() == m_hWnd)));
Then replace each occurrence with:
if (UseSelectedColors)
|
|
|
|

|
Hi Hans,
Can you think of a quick way that I could limit your tree to allow only a given number of allowed selections (# of checked checkboxes)?
Thank you, and thanks again for your much appreciated great work.
Mike
|
|
|
|

|
I could not build the x64 - are there any special settings like the "Not Using Precompiled Headers" etc.?
thanks in advance,
E.
p.s.
You did a remarkable work over here!
|
|
|
|

|
hi,
i am trying to use the ECC implementation in borZoi
how can i use the borZoi functions from within C# .NEt,
how can i integrate these library to VS 2008,and use its functions using C# .NET
thanks alot
|
|
|
|

|
Thank you for your very generous contribution Hans! Your code is so good that I'm compelled to look up all your articles!
Question: Is there a way to turn checkboxes on or off for each node in the tree?
Kind regards,
Mike
|
|
|
|

|
Dear Mr. Hans,
Many thanks for a great control! I am using XHtmlTree within one of my projects. I put XHtmlTree control in CDockablePane (which was introduced in the Feature Pack of VS 2008) container window. With the exception of the check box, everything works like a charm!
Things go like this. When I click an unchecked tree item, it does not put a check mark (a tick sign) into the check box. To look for whys and wherefores, I decide to map the WM_XHTMLTREE_CHECKBOX_CLICKED message to check the new checkbox state when a checkbox is clicked. Step-by-step debugging proved that I can get the correct checkbox state every time a XHtmlTree item is clicked. I don't know why.
What's make me more surprising is that I could resolve this kind of problem by poping up a message box in the handler as follows:
LRESULT CDataTreePane::OnCheckbox(WPARAM wParam, LPARAM lParam)
{
TRACE(_T("in CGeoSatDataPane::OnCheckbox\n"));
XHTMLTREEMSGDATA *pData = (XHTMLTREEMSGDATA *)wParam;
ASSERT(pData);
BOOL bChecked = lParam;
if (pData)
{
HTREEITEM hItem = pData->hItem;
if (hItem)
{
CString strMessage;
strMessage.Format(_T("Checkbox %schecked at '%s'"), bChecked ? _T("") : _T("un"), m_pTree->GetItemText(hItem));
AfxMessageBox(strMessage);
}
}
return 0;
}
As soon as I click "OK" button to dismiss the message box the check mark will be placed into the check box. That is to say, the check box functionality behaves in normal operating conditions.
Looking forward to hearing your answer to this question. Thank you!
Golden Lee
|
|
|
|

|
CXHtmlTree::OnClick()
BOOL rc
at end should change to
return TRUE
Otherwise could course execute OnClick function twice error in some cases.
environment: Visual Studio C++ 2005
|
|
|
|

|
Hello and thank you for this tree control.
I have a problem with tree items bitmaps colors.
bitmaps supplied to CImageList::LoadBitmap are 3channels, 8bits -depth. The result however is as if they were treated as 4bits depth. Somehow it also looks as gray scale images.
This is both the case of the sample program as well as with projects I created using xHTMLTree.
Thank you in advance.
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|

|
If a treeitem's checkbox is empty, After I click it, the checkbox displays with the tri-state, then I move the mouse out of the checkbox's rect, the checkbox redraw with the check state.
I don't know the reason!
Please help me! Thanks!
|
|
|
|

|
Hello,
I'd like to hide some treeitems in my XHtmlTree Control, i.e. these items are present in the data model, but they shall not be displayed. Is there an elegant way to achieve this?
Thanks alot.
|
|
|
|

|
Hi,
I followed the instructions in how to use the control but I am getting 30 compiler errors.
Any suggestion?
|
|
|
|
|

|
Hans,
This is an excellent contribution to software development, thank you!
My question is how can I display multiple root nodes in the XHtmlTree control when reading from an XML file? I do see how this is done from a text file but was wondering if it's possible from an XML file.
Also, on these same lines, the SaveXml call incorectly saves the multi-root tree (from the Multiple Roots option in XHtmlTreeTest.exe)
Thanks for all the work you did on this.
Curt
|
|
|
|

|
But would anyone tell me how to specify the tree node value?
|
|
|
|

|
I am very very happy to see such a precious article.
You are not only sharing good knowledge,
but almost provide the hours taking design.
Thanks a lot. A good job.
Radim Köhler
|
|
|
|

|
Hello,
thanks for this great class, however on one of my XP machines, I get red borders around all of my checkboxes (see screenshot).
I have absolutely no idea why this happens, and what to do against it. Is there a possibility to use default checkboxes instead?
Here is a screenshot:
http://www.abload.de/image.php?img=treez9g.png[^]
I have tried to reset the desktop theme and all Windows settings to default, 96dpi, etc.
|
|
|
|

|
Hi,
Currently, as far as I've found,
it is possible to "drop" only after and item,
and not "on" item.
This is a problem for me, since in my tree, I use the items as "folders" and "files".
So I cannot drop a file on a folder.
In _particular_, if the folder has no child, it will not expand,
and there is no way to move an item to be its child.
I would like to ask:
1) Am I right in my findings ?
2) If yes:
a) Do u plan to support drop "on" item ?
b) If you don't plan to support, or any case,
How can I suggest my solution, so it will be included in
next versions ?
|
|
|
|

|
Hi,
I really like this treecontrol, but I am wondering if there is an easy way to have owner-drawn bitmaps for the checkbox-states displayed, instead of the Vista-styled ones. Can I insert my own bitmaps for that purpose, like for example the installation-state-bitmaps found in many installers (Installshield setup, Microsoft installer engine)?
Thanks alot.
|
|
|
|

|
Cant figure out a trivial way to do this..
|
|
|
|

|
If the downloaded source samples raise any errors, that means you have not installed the Platform SDK. So do the following.
1. Edit the following in PPTooltip.cpp in the top after #include "PPTooltip.h"
#define SM_XVIRTUALSCREEN 76
#define SM_YVIRTUALSCREEN 77
#define SM_CXVIRTUALSCREEN 78
#define SM_CYVIRTUALSCREEN 79
#define SM_CMONITORS 80
#define SM_SAMEDISPLAYFORMAT 81
2. You have to copy these three files [ schemadef.h, Uxtheme.h, Tmschema.h ] in the
<drive>:\Program Files\Microsoft Visual Studio\VC98\INCLUDE folder.
Note:
Q: Where to find these files?
Ans: They are by default installed when you install VS.NET under the folder
<drive>:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include
Just after doing the above, you can compile and execute all the sources even if you have not installed or doesn't want to install the Platform SDK.
Best of luck .
Habeeballah Hasnoddin
|
|
|
|

|
If the downloaded source samples raise any errors, that means you have not installed the Platform SDK. So do the following.
1. Edit the following in PPTooltip.cpp in the top after #include "PPTooltip.h"
#define SM_XVIRTUALSCREEN 76
#define SM_YVIRTUALSCREEN 77
#define SM_CXVIRTUALSCREEN 78
#define SM_CYVIRTUALSCREEN 79
#define SM_CMONITORS 80
#define SM_SAMEDISPLAYFORMAT 81
2. You have to copy these three files ( schemadef.h, Uxtheme.h, Tmschema.h ) in the
:\Program Files\Microsoft Visual Studio\VC98\INCLUDE folder.
Note:
Q: Where to find these files?
Ans: They are by default installed when you install VS.NET under the folder
:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include
Just by doing the above, you can compile and execute all the sources even if you have not installed or doesn't want to install the Platform SDK.
Best of luck .
Habeeballah Hasnoddin
|
|
|
|

|
It looks like if you select a child item and collapse its parent, the selection is changed to the parent but m_hPreviousItem is not updated and TVN_SELCHANGED is not sent out. It was blocked by
if (hItem == m_hPreviousItem)
rc = TRUE;
in the OnSelchanged function.
You can then expand the tree and select the previous child item with no TVN_SELCHANGED as well. I believe the same arguments can be made for TVN_SELCHANGING, but I haven't thoroughly checked.
I tried to add code it several places, but was thwarted by good programming. I eventually put the last two line of the snippet of code below in the Expand function:
if (nCode == TVE_COLLAPSE || nCode == TVE_COLLAPSERESET)
{
pXTCD->bExpanded = FALSE;
if( hItem == GetParentItem(GetSelectedItem()) )
SelectItem(hItem);
}
This results in an extra TVN_SELCHANGING/TVN_SELCHANGED message being sent out from SelectItem where the SendMessage in SelectItem initiates one sequence and the return CTreeCtrl::SelectItem(hItem) initiates another. I returned after the SendMessage, and it appears to be functioning properly but I haven't traced all the implications of doing this.
Anyways, that fixed most of the problems I was seeing, but I was also getting a lot of zeros back from (DWORD)pNMTreeView->itemNew.lParam when I was checking the item data for the newly selected item in my TVN_SELCHANGED handler. I traced it back to the SelectItem function, which only partially populated the NMTREEVIEW structure.
I added:
if( hItem )
nmtv.itemNew.lParam = GetItemData(hItem);
nmtv.itemOld.hItem = hPrevItemSel;
if( hPrevItemSel )
nmtv.itemOld.lParam = GetItemData(hPrevItemSel);
to the SelectItem function, and everything works as expected. I hope this helps, and if anything is insanely stupid in the above, a message letting me know would be great.
Thanks.
|
|
|
|
|

|
I am trying to disable the checkbox, drag and drop and rename options for a child in the tree but not the parents. Does anyone have any idea how to do that?
I used this to get rid of the checkbox, but the check box reappears if you check the parent or anything above the child.
m_prefsTree.SetItemState( hChildInspectionField, 0, TVIS_STATEIMAGEMASK );
thanks!
michael
|
|
|
|

|
I'm thinking about adding multi-column support into this wonderful control. Maybe someone already started something similar?
|
|
|
|

|
I would like to have tri-state checkboxes, but I want to manage them myself, rather than turning on smart-check. The control doesn't seem to support this, and it's not clear (at least to me) how to extend the code to do this. Can you offer any guidance in doing this? Thanks,
Don
|
|
|
|

|
First, let me say that your tree control looks great and very professional. The example works very well. I plop the same code into an existing MDI CFormView application and I get several redraw problems, and let me preface this by saying I didn't write all of the existing code. The +/-, lines, and checkboxes (state images) are not drawn. They are there and if you click in the appropriate area, everything works as expected. The messages/notifications all seem to passed correctly. I've looked into the NM_CUSTOMDRAW notification and several other things but haven't found the problem yet. I would appreciate suggestions on where to look for the problem. When I find the problem, I'll post a warning or fix for others. Edit: I should add that the same code using the CTreeCtrl minus the CXHTMLTree specific code works fine. Also, I'm using no HTML, tool tips, or XML. <div class="ForumMod">modified on Sunday, December 23, 2007 6:11:27 PM</div>
|
|
|
|

|
Thank you for sharing, that is very usefull project!!!
Zqr
|
|
|
|

|
Hi!
A Great article
I'm trying to use your control but for som reason the I have a drawing problem, when mouse is over the checkbox the checkbox dissapears, When I click the unvisible checkbox of a child the parent checkbox dissapears.
I'm using it in a program with Ultimate Toolbox from this site
Any hints?
BR /Magnus
/Magnus
|
|
|
|

|
Thanks for this great control
How to prevent from dragging a root item to a child item?
And how to drag a child item and set it as a root item?
Thanks in advance!
|
|
|
|

|
Hi Hans,
I am creating a custom state image list for TreeControl. I draw the checkboxes using DrawFrameControl. (I took some guidelines from your code)
I need 3d checkboxes in this control. But when the checkboxes are rendered, they have a black border around them, which looks quite ugly. Here is the code --
_pStateImageList->Create(16,16, ILC_COLOR32 | ILC_MASK , nImages, 10 );
(I use mask flag here deliberately)
_pStateImageList->Add(&bitmapCheck, RGB(0,0,0));
Now if I add the bitmap with mask Color as Black, the checkboxes do not have black border, they look fine. But the checkboxes with "checked" state are not drawn at all.
IF I use a different color , say white, both type of checkboxes are drawn but they have a black border around them. This has to do with masking.
Any ideas would greatly be appreciated..
Thanks in advance
Misha
Evil triumphs when good people sit quiet...
|
|
|
|

|
Hi,
does anyone know how to implement drag and drop
between two instances of XHTMLTree? Or does anyone
know where the general topic is adressed? Thank you.
cheers mike
|
|
|
|

|
Hi Hans,
There’s an unhandled exception as soon as you uncheck the image checkbox! The problem seems the GetImageList call in function InsertXmlItem. The returned pImageList pointer is NULL and therefore the GetImageCount results into the unhandled exception. The NULL pointer is ok; it was set to NULL in the UpdateTree. Just a slip of the mind …;)
Greetings, Berni Slootbeek
|
|
|
|

|
Has anyone tried drag and drop with this control? I managed to get it working with a basic CTreeCtrl but am struggling with the XHtmlTree.
My problem is that I cannot get any of the items to be drawn as drop highlighted. The mouse move and hit test finds the item but when I call CTreeCtrl::SelectDropTarget() it seems as if nothing happens. Adding traces to the XHtmlTree source it looks as if the tree doesn't even get the TVM_SELECTITEM message which is sent?
Using the mini dialog example, add handlers for the IDC_TREE2 -> TVN_BEGINDRAG, WM_MOUSEMOVE and WM_LBUTTONUP messages with the following contents:
void CMinDialogDlg::OnTvnBegindragTree2(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
m_DragImageList = m_Tree.CreateDragImage(pNMTreeView->itemNew.hItem);
if(NULL != m_DragImageList)
{
CRect item_rect;
CPoint hotspot(pNMTreeView->ptDrag);
SetFocus();
SetCapture();
m_Tree.GetItemRect(pNMTreeView->itemNew.hItem, item_rect, TRUE);
int normal_image, selected_image;
if(m_Tree.GetItemImage(pNMTreeView->itemNew.hItem, normal_image, selected_image) && TV_NOIMAGE != normal_image)
{
IMAGEINFO image_info;
m_Tree.GetImageList(TVSIL_NORMAL)->GetImageInfo(normal_image, &image_info);
item_rect.left -= (CRect(image_info.rcImage).Width() + 3);
}
hotspot.x = hotspot.x - item_rect.left; hotspot.y = hotspot.y - item_rect.top; m_DragImageList->BeginDrag(0, hotspot);
CPoint point(pNMTreeView->ptDrag);
m_DragImageList->DragEnter(NULL, point);
}
*pResult = 0;
}
void CMinDialogDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(NULL != m_DragImageList)
{
CPoint cursor_point(point);
ClientToScreen(&cursor_point);
m_DragImageList->DragMove(cursor_point);
HTREEITEM tree_item;
UINT flags;
CPoint hit_point(point);
ClientToScreen(&hit_point);
m_Tree.ScreenToClient(&hit_point);
tree_item = m_Tree.HitTest(hit_point, &flags);
if((NULL != tree_item) && (TVHT_ONITEM & flags))
{
TRACE("Drag target item 0x%08lx\n", tree_item);
CImageList::DragShowNolock(FALSE);
m_Tree.SelectDropTarget(tree_item);
CImageList::DragShowNolock(TRUE);
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CMinDialogDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if(NULL != m_DragImageList)
{
m_DragImageList->DragLeave(NULL);
m_DragImageList->EndDrag();
ReleaseCapture();
delete m_DragImageList;
m_DragImageList = NULL;
}
CDialog::OnLButtonUp(nFlags, point);
}
And in the class definition add:
CImageList *m_DragImageList;
There are some other raw issues with the drag image, but I've got that sorted in my main code. It's just the drop highlighting I've got problems.
Thanks for any assistance.
|
|
|
|

|
Hi,
This is, as usual, a very nice article by you. I have a question though,
You said:
"You are free to use it in any way you like, except that you may not sell this source code."
Can I use this in a closed source commercial application written by me?
|
|
|
|
|

|
It might be easier for me to detail the steps to reproduce the problem than trying to explain in words.
Try selecting the Kangaroo Dog, click on the see picture link. Hopefully, IE (or whatever browser) pops up in front of the test app dialog. Now, when you Alt-Tab back to the test app, the HTML based tree items don't seem to get redrawn.
BTW, thanks for adding Shih Tzu to the list .
|
|
|
|

|
Can't compile the vs6 project: CVisualStylesXP error
|
|
|
|

|
Hi,
First of all: nice work, it's very impressive
Second, here are some bugs I found:
1) Checking checkboxes with the space key does not always work when smart checkboxes are enabled, for items with child items. It seems to be related to CXHtmlTree::GetStateImage(). It only checks the nChecked and nChildren item, not the desired new state of the checkbox and ends up returning the same state as the item already has. This causes the rest of the CXHtmlTree::SetCheck() to not execute, including CXHtmlTree::SetCheckChildren() which is what actually sets the state of the checkbox that was clicked on.
2) When you have started an in place edit and press an up/down arrow key the selection moves to the next item but the in place edit is still present. You can still type in the in place edit, but when it shrinks you now see the text of the item behind it.
3) The in place edit check seems to be offset by the width of the item image. To check, run the XHtmlTreeTest demo, navigate down to Sight Hounds->Borzoi and try clicking on the "B". Nothing happens, but if you click over the "r" or "z" then you get the in place edit.
Third a suggestion:
In CXHtmlTree::OnClick(), line 952, use "point = GetCurrentMessage()->pt;" instead of "::GetCursorPos(&point);". It means the message handler will use the co-ordinates of the mouse at the time of the event rather than the current co-ordinates. Useful for debugging if nothing else
Thanks again for sharing this excellent control.
|
|
|
|

|
Awesome work. Thanks for sharing.
From the "For What It's Worth" department, may I suggest that the control would be much more useful if it could load from an external data source, rather than solely from memory/resource. The ability to load data from an SQLite or MySQL connection directly would be a huge plus as well.
This article is still a '5' though -- Great job.
In business, if two people always agree, one of them is unnecessary.
|
|
|
|

|
Hans,
I grabbed this code when you first posted back in August.
After I compiled a debug version, I ran the exe from the bin, and began changing a few props on the tree control.
What I noticed was the icon's on my desktop flickered horribly when modifying the tree's properties as well as checking the checkboxes...etc.
Any idea's?
Thx
Greg
|
|
|
|

|
Got my 5!
Very well written !
|
|
|
|

|
Dear Mr. Hans,
Wow, what a powerfull tree control with direct support of check boxes! Every time I saw your code published on codeproject website, its rich features impressed me, and the beauty of GUI hit me right between the eyes. But, do you have a plan to make the XHtmlTree control's node to have a capability of in place editing.
Thank you!
Golden Lee
Golden Lee
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
XHtmlTree is an MFC control based on CTreeCtrl, with support for HTML text, web links, APP: links, XML load/save, Smart Checkboxes, and Drag & Drop.
| Type | Article |
| Licence | CPOL |
| First Posted | 9 Aug 2007 |
| Views | 233,843 |
| Downloads | 7,317 |
| Bookmarked | 349 times |
|
|