Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TreeView and TVITEMEX.iIntegral

32 views
Skip to first unread message

jwallison

unread,
Feb 11, 2005, 2:33:05 PM2/11/05
to
I am porting an existing .Net application to Win32/Visual C++, targeting
Windows XP/2000+ and IE 5.5+.

One of the requirements is to be able to set the item/node height in a
TreeView/MFC CTreeCtrl to varing values in order to support the display of
images of varing sizes.

It appears from the MS documentation that using SetItemHeight() and using
TVITEMEX.iIntegral with CustomDraw is the way to tackle this, but I have
seen a number of posts referring to problems with using iIntegral (ScrollBar
problems; painting problems), and no solutions.

I am seeing the same painting/repanting issues noted on these sites, and I
need to find a solution.

1. Does anyone know of any sample code showing successful use of varying
line heights?
2. My intended approach was going to (eventually) be to SetItemHeight() to 1
or 2, and use iIntegral to scale items to the height I intended for each
individual tree item. Is this the correct approach? CustomDraw and iIntegral
seemed like a good idea at the time - is it a valid approach?

--
Regards,

Jim Allison
jwall...@bellsouth.net
(de-mung by removing '.1')

jwallison

unread,
Feb 17, 2005, 2:25:22 PM2/17/05
to

jwallison

unread,
Feb 17, 2005, 2:29:57 PM2/17/05
to

Rhett Gong [MSFT]

unread,
Feb 17, 2005, 10:32:57 PM2/17/05
to
Hi Jim,
From your descriptin, I get that you would like to know how to set the tree
control's items with different height. But I am not sure what problems you
may meet. For a quick test, I write a simple code to add some tree items
with different height. You may try it first and let me know if it could
meet you need.

// steps
1. construct a mfc dlg based applicatioin(name it as
CTreeViewItemHeightDlg);
2. add a treecontrol and set the scroll style to True from property page;
3. add following code after following TODO line:
// TODO: Add extra initialization here
CTreeCtrl* pTree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
AddTreeItems(pTree);
4. add a function (name AddTreeItems) in the CTreeViewItemHeightDlg class
and implement it as following:
bool CTreeViewItemHeightDlg::AddTreeItems(CTreeCtrl *pTree)
{
if( pTree == NULL)
return false;

TVITEMEX items[3];

//construct the items
items[0].mask = TVIF_TEXT;
items[0].pszText = _T("Root");

items[1].mask = TVIF_TEXT;
items[1].pszText = _T("Leaf");

items[2].mask = TVIF_TEXT|TVIF_INTEGRAL;
items[2].pszText = _T("Leaf2");
items[2].iIntegral = 2;

HTREEITEM phTree[20];

TVINSERTSTRUCT inItems[3];
inItems[0].hParent = NULL;
inItems[0].hInsertAfter = TVI_ROOT;
inItems[0].itemex = items[0];
phTree[0] = pTree->InsertItem( inItems);

inItems[1].hParent = phTree[0];
inItems[1].hInsertAfter = TVI_LAST;
inItems[1].itemex = items[1];

inItems[2].hParent = phTree[0];
inItems[2].hInsertAfter = TVI_LAST;
inItems[2].itemex = items[2];

for( int i=1; i<20; i++)
{
if( (i % 2) != 0 )
phTree[i] = pTree->InsertItem(inItems +1);
else
phTree[i] = pTree->InsertItem(inItems +2);
}

return true;
}
5. compile and run
//end of steps

If not, please feel free to let me know what you think it should be. And
please note: you need to draw the extra space by yourself in a custom draw.

Thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.

jwallison

unread,
Feb 18, 2005, 11:20:10 AM2/18/05
to
Rhett -

The (re)drawing problems seem to occur when you change iIntegral AFTER the
control has been loaded with items.

Change the stdafx.h settings for WINVER etc. to 0500
Change the setting for _WIN32_IE to 0501

Add a control variable for the tree and namer it m_TreeCtrl;

Add a Button to the dialog, and label it "Test";
Double-click to create OnBnClickedButton1() and open code editor at that
point.
Insert the following code into OnBnClickedButton1():
HTREEITEM hTVI = m_TreeCtrl.GetSelectedItem();

if ( hTVI != NULL)

{

TVITEMEX tvi;

tvi.mask = TVIF_INTEGRAL | TVIF_HANDLE;

tvi.hItem = hTVI;

tvi.iIntegral = 2;

m_TreeCtrl.SetItem( reinterpret_cast<TVITEM*>(&tvi)); // TVITEMEX for
commctrl v 4.71+

m_TreeCtrl.Invalidate(TRUE); // brute force

}

else

AfxMessageBox("No item selected");

}


- Compile and run the program
- select the first "Leaf" node
- click the "Test" button to set that item's iIntegral to 2
- scroll down to move the "Leaf" item out of the control's client area, then
scroll back to the "Root" item again.
- if it doesn't happen the first time, try it several times, and on other
nodes - you will see drawing artifacts appear in a number of items.

Thanks for you assistance -


"Rhett Gong [MSFT]" <v-ra...@online.microsoft.com> wrote in message
news:U2gHVqW...@TK2MSFTNGXA01.phx.gbl...

Rhett Gong [MSFT]

unread,
Feb 21, 2005, 1:36:56 AM2/21/05
to
Hi Jim,
Thanks for your detailed feedback.
I've successfully had the problem repro'ed in my side. From my research,
internally, the iIntegral is assumed always 1 in its scrolling calculations
and we already have a bug filed for this, however currently there is no
good workaround for this.
So I would suggest following ways for this problem:
1. Write your own TreeView control or seek a third-party solution
2. Contact our PSS (at:
http://www.microsoft.com/services/microsoftservices/supp.mspx) to request a
hotfix on the common control treeview.

Best regards,

jwallison

unread,
Feb 22, 2005, 3:14:34 PM2/22/05
to
Rhett -

I'm afraid I don't understand your explanation, since it doesn't agree with
the results of running your original sample code.

If TVITEMEX.iIntegral is always assumed to be equal to one during scrolling
operations, and this is the source of the (re)drawing error, then why does
the redrawing problem not occur in the sample you provided, where "Leaf"
nodes have iIntegral == 1, and "Leaf2" nodes have iIntegral == 2. One can
perform exactly the same scrolling operations in your unmodified sample, and
no (re)drawing artifacts appear - the only difference between your sample
and my modifications being that my code changes iIntegral AFTER the items
have already been inserted into the tree.

In EITHER sample, some iIntegrals are 1, some are 2, so it doesn't seem
assumptions about iIntegral during scrolling are the cause of the problem
(unless you can repro the problem in your original sample?) If this is a
known bug, can you point me to a PRB/KB/PSS id that notes the details of the
bug?

"Rhett Gong [MSFT]" <v-ra...@online.microsoft.com> wrote in message

news:JX8xE$9FFHA...@TK2MSFTNGXA02.phx.gbl...

Rhett Gong [MSFT]

unread,
Feb 23, 2005, 8:49:56 PM2/23/05
to
There is no PRB/KB/PSS id but Bug ID 935869.
The reason my first case appears to work is that I am alternating
iIntegral=1 and iIntegral=2. From the bug notes "There is no workaround,
except that if the item *before* the one you want to scroll to has an
integral height of 1, then it will work."
We will need to implement a custom TreeView to get variable height items.
Currently there is no workaround to do this with the common control
TreeView.


Thanks,

0 new messages