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')
// 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.
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...
Best regards,
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...
Thanks,