 |
|
 |
居然 用VC 6 打不开
i don't know white what wu wu @@
|
|
|
|
 |
|
 |
The message handler OnLButton is not called every time. It is called only with double click
Best regards!
Hello world!
|
|
|
|
 |
|
 |
i am finding this "fatal error RC1015: cannot open include file 'atlres.h'." error while compiling. This may be because of missing "atlres.h" from the project files.
Could not find it any where, need your help for this.
Thanks
Akshat
|
|
|
|
 |
|
 |
Someone should post a VC6 version of this.
Eventually I end up with this error:
c:\documents and settings\tmarshall\my documents\download\treectrl\treectrl.h(99) : error C2664: 'Add' : cannot convert parameter 1 from 'struct _TREEITEM *' to 'struct _TREEITEM *& '
A reference that is not to 'const' cannot be bound to a non-lvalue
figure that one out?
thanks
|
|
|
|
 |
|
 |
void GetSelectedItems( CSimpleArray < HTREEITEM >& aSelectedItems )
{
aSelectedItems.RemoveAll();
if ( !m_bMultipleSelect )
{
aSelectedItems.Add( GetSelectedItem() ); // <--- Here
return;
}
// get all selected tree items (recursive)
GetSelectedItems( GetRootItem(), aSelectedItems );
}
|
|
|
|
 |
|
 |
Please make the tree items editable. That's will be perfect.
|
|
|
|
 |
|
 |
Looks good and I like the approach -
Couple of fixes here -
Override SetBkColor to allow non-white background. Maybe a better way to handle background color (and text color) is by getting and setting the treeviews colors through TVM_GETBKCOLOR etc.
Fixed clicking on expand buttons so it doesn't affect the current selection.
Also just FYI - I got this working on 7.1 by copying out the relavent classes from ATL 7.5 (CDoubleBuffer, CMemoryDC and CLogFont)
COLORREF SetBkColor(COLORREF bk)
{
m_rgbBackground = bk;
return CWindowImpl< CTreeCtrl, CTreeViewCtrl >::SetBkColor(bk);
}
void OnLButtonDown( UINT nFlags, CPoint point )
{
if ( m_bMultipleSelect )
{
// reset selected item if click on a single item
UINT flags = 0;
HTREEITEM hNewItem = HitTest( point, &flags );
if (flags & TVHT_ONITEMBUTTON)
{
SetMsgHandled( FALSE );
return;
}
m_bCtrlKey = ( ( GetKeyState( VK_CONTROL ) & 0x8000 ) != 0 );
m_bShiftKey = ( ( GetKeyState( VK_SHIFT ) & 0x8000 ) != 0 );
if ( m_bCtrlKey || m_bShiftKey )
return;
if ( hNewItem != NULL )
{
UINT nNewSelectState = ( GetItemState( hNewItem, TVIS_SELECTED ) & TVIS_SELECTED );
ResetSelected( GetRootItem() );
SetItemState( hNewItem, nNewSelectState, TVIS_SELECTED );
m_hFirstSelected = hNewItem;
}
}
SetMsgHandled( FALSE );
}
void OnLButtonUp( UINT nFlags, CPoint point )
{
SetMsgHandled( FALSE );
if ( !m_bMultipleSelect )
return;
UINT flags = 0;
HTREEITEM hNewItem = HitTest( point, &flags );
if (flags & TVHT_ONITEMBUTTON)
return;
HTREEITEM hOldItem = GetSelectedItem();
if ( m_bCtrlKey )
{
if ( hNewItem != NULL )
{
UINT nNewSelectState = GetItemState( hNewItem, TVIS_SELECTED ) & TVIS_SELECTED ? 0 : TVIS_SELECTED;
UINT nOldSelectState = hOldItem == NULL ? 0 : GetItemState( hOldItem, TVIS_SELECTED );
// select new item (to get focus)
SelectItem( hNewItem );
// set highlight state for new item
if ( GetItemState( hNewItem, TVIS_SELECTED ) != nNewSelectState )
SetItemState( hNewItem, nNewSelectState, TVIS_SELECTED );
// restore state of old selected item
if ( hOldItem != NULL && hOldItem != hNewItem && GetItemState( hOldItem, TVIS_SELECTED ) != nOldSelectState )
SetItemState( hOldItem, nOldSelectState, TVIS_SELECTED );
m_hFirstSelected = NULL;
}
}
else if ( m_bShiftKey )
{
// initialise the reference item if this is the first shift selection
if ( m_hFirstSelected == NULL )
m_hFirstSelected = GetSelectedItem();
// select new item (to get focus)
if ( hOldItem == hNewItem )
SelectItem( NULL ); // to prevent edit
if ( m_hFirstSelected != NULL )
SelectItems( m_hFirstSelected, hNewItem );
}
m_bCtrlKey = FALSE;
m_bShiftKey = FALSE;
}
Chris Davies
|
|
|
|
 |
|
 |
I see your CListCtrl WTL version too, I hope have MFC version.
|
|
|
|
 |
|
 |
I had downloaded and build it, the tree control 's item text can't display fully when I launch it and choice "TheMe".
My OS is chinese XP, It display normally when i change the Dialog template's language property to chinese.
I'm sorry for my pool english!
|
|
|
|
 |
|
 |
Start the program then click on the first item. The selection disappears.
Get the selection back on the first item, then Shift+Click further down. The section incorporates everything from the second clicked item to the bottom of the tree.
Select the first three items using Ctrl+Click, then Shift+Click the somewhere further down. The first item is not de-selected.
Use the arrow keys to move up and down the tree. At the top and bottom, the selection disappears if you hold the key down. The same happens if you use the left and right arrow keys to expand or collapse a node.
Put checkboxes into the tree using the dialog editor. Pressing the space bar will only flip one checkbox out of the selection, and the selection goes away.
I think that the custom painting is great, and I want to use it, but the multiple selection functionality needs a lot of work. I did a bit to address a few of these, but it's going to take more, I think.
Here's the diff:
135,144c135,136
< HTREEITEM hItem = GetNextVisibleItem( GetRootItem() );
<
< SetRedraw( FALSE );
<
< // clear selection upto the first item
< for ( ; hItem != NULL && hItem != hItemFrom && hItem != hItemTo; hItem = GetNextVisibleItem( hItem ) )
< SetItemState( hItem, 0, TVIS_SELECTED );
<
< // is item visible?
< if ( hItem != NULL )
> HTREEITEM hItem = GetRootItem();
> for ( ; hItem != NULL; hItem = GetNextVisibleItem( hItem ) )
146,148c138,142
< SelectItem( hItemTo );
<
< if ( hItem == hItemTo )
> if ( hItem == hItemFrom )
> {
> break;
> }
> else if ( hItem == hItemTo )
152a146
> break;
153,155c148,149
<
< // go through remaining visible items
< for ( BOOL bSelectItem = TRUE; hItem != NULL; hItem = GetNextVisibleItem( hItem ) )
> }
> if ( hItem == NULL )
157,161c151
< SetItemState( hItem, bSelectItem ? TVIS_SELECTED : 0, TVIS_SELECTED );
<
< // do we need to start removing items from selection?
< if ( hItem == hItemTo )
< bSelectItem = FALSE;
> return FALSE;
163a153,162
>
> SetRedraw( FALSE );
>
> // clear whole selection
> ResetSelected( GetRootItem() );
>
> // is item visible?
> for ( hItem = hItemFrom; hItem != hItemTo; hItem = GetNextVisibleItem( hItem ) )
> {
> SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
164a164
> SetItemState( hItemTo, TVIS_SELECTED, TVIS_SELECTED );
242c243,245
< if ( ( nChar == VK_UP || nChar == VK_DOWN ) && GetKeyState( VK_SHIFT ) & 0x8000 )
> if ( m_bMultipleSelect && ( nChar == VK_UP || nChar == VK_DOWN ) )
> {
> if ( GetKeyState( VK_SHIFT ) & 0x8000 )
265c268,290
< else if ( nChar >= VK_SPACE )
> else // no shift key
> {
> HTREEITEM hSel = GetSelectedItem();
> m_hFirstSelected = NULL;
> ResetSelected( GetRootItem() );
> SelectItem( hSel );
> }
> }
> else if ( nChar == VK_SPACE && (GetStyle() & TVS_CHECKBOXES) == TVS_CHECKBOXES )
> {
> HTREEITEM hSel = GetSelectedItem();
> BOOL bChecked = GetCheckState(hSel);
> CSimpleArray<HTREEITEM> aSel;
> GetSelectedItems(aSel);
> for (int ctr = 0; ctr < aSel.GetSize(); ctr++)
> {
> if (aSel[ctr] != hSel)
> {
> SetCheckState(aSel[ctr], !bChecked);
> }
> }
> }
> else if ( isalnum(nChar) )
300c325,326
< if ( HitTest( point, NULL ) != NULL )
> HTREEITEM hNewItem = HitTest( point, NULL );
> if ( hNewItem != NULL )
302a328
> UINT nItemSelState = GetItemState(hNewItem, TVIS_SELECTED) & TVIS_SELECTED;
303c330,331
< m_hFirstSelected = NULL;
> SetItemState(hNewItem, nItemSelState, TVIS_SELECTED);
> m_hFirstSelected = hNewItem;
This still doesn't address what happens to the selection if you click and drag another item, or if you set or clear the checkbox if another item is selected.
Phil.
--
All things considered, you can't really consider all things ...
|
|
|
|
 |
|
 |
Phil,
I've fixed this now - the new code should include these changes.
Many thanks for your help.
|
|
|
|
 |
|
 |
Thanks for your work, But I find a bug, you miss MSG_WM_CREATE(OnCreate) in message map, so if create a treeCtrl in a window at runtime not in a dialog at design time, the treeCtrl display isn't right!
|
|
|
|
 |
|
 |
Thanks for pointing that out - I'll update the code soon.
|
|
|
|
 |
|
 |
Hey
I am getting this compiler error:
"Could not include file atlapp.h. File not found."
Please help.
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
The latest (stable) version 7.5 should be fine
|
|
|
|
 |