本文介绍了GetTextExtent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的listcontol的子项目中,我正在使用子类CIPAddresctrl。
In my listcontol's subitem I am using subclassed CIPAddresctrl.
我正在使用GetTextExtent(" 255.255.255.255 ")计算CIPAddressCtrl宽度,但GetTextExtent(" 255.255.255.255") 没有给出正确的值。
I am using GetTextExtent("255.255.255.255") to calculate the CIPAddressCtrl width but GetTextExtent("255.255.255.255") is not giving correct value.
CRect r;
GetClientRect( &r);
//adjust height
r.bottom += 2;//(r.Height()*(v.size()+5)); //5 safe side
//adjust width
CClientDC dc(pParentWnd);
int nSave = dc.SaveDC();
dc.SelectObject(pParentWnd->GetFont());
int w=dc.GetTextExtent("255.255.255.255").cx;
if(w>r.Width()) r.right=r.left+w;
提前致谢。
Thanks in advance.
推荐答案
为什么使用父窗口的DC?
CClientDC dc ( pParentWnd );
Why are you using the parent window's DC ?
CClientDC dc(pParentWnd);
试试通过在子类控件上调用GetDC()来划分DC。
-Seetharam
这篇关于GetTextExtent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!