Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
If I use the DC of my CTreeCtrl-derived class to calculate the horizontal extent of a tree item I would like to insert:

C#
CDC *pDC = GetDC();

CSize nameSize = pDC->GetTextExtent (*dString);


... it seems I cannot depend on this function while appending characters to the string (dString)in order to make all tree items the same length (within a pixel or two). In other words, I can do:

C#
while (nameSize.cx < someLimit) {
  dString->Append ("-");
  nameSize = pDC->GetTextExtent (*dString);
 }


If I 'extend' each string in this fashion, they indeed have a final text extent (length) within a few pixels, but when they are displayed in the CTreeCtrl, they are all of different length.

It is as if the DC of the CTreeCtlr does not match the actual DC. Any ideas?

Thx
Posted

1 solution

My guess would be that when you do the GetDC-GetTextExtent thing the DC has a different font selected into it (System font maybe?) than when the tree is drawing the items.
When you do the calculation, maybe try querying the tree for its font with GetFont[^] and use it for the calculation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900