CTreeCtrl-GetTextExtent似乎很奇怪 [英] CTreeCtrl - GetTextExtent seems strange

查看:110
本文介绍了CTreeCtrl-GetTextExtent似乎很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用派生自CTreeCtrl的类的DC来计算我想插入的树项目的水平范围,则:

If I use the DC of my CTreeCtrl-derived class to calculate the horizontal extent of a tree item I would like to insert:

CDC *pDC = GetDC();

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



...似乎无法在将字符附加到字符串(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:

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



如果我以这种方式扩展"每个字符串,它们的确在几个像素内具有最终的文本范围(长度),但是当它们在CTreeCtrl中显示时,它们的长度都不同.

好像CTreeCtlr的DC与实际DC不匹配.有什么想法吗?

Thx



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

推荐答案

我的猜测是,当您执行GetDC-GetTextExtent时,DC会选择与树不同的字体(可能是系统字体?).正在绘制项目.
在进行计算时,也许尝试使用 GetFont查询树的字体 [ ^ ]并用于计算.
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.


这篇关于CTreeCtrl-GetTextExtent似乎很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆