如何使编辑框的字体大小与编辑框一样大??

lfxiansheng 2011-12-11 11:08:24
我用GetWindowRect(rect2)得到编辑框大小后,怎么转为字体高度?用ScreenToClient(rect2)不可行;求解?
我的代码如下:
void CMillimarView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
int eHeight,eWidth,sHeight,sWidth;
CRect rect1;
this->GetWindowRect(rect1);

if (m_EDVal.m_hWnd!=NULL)
{

float hstatic;
hstatic=0.5f;
eHeight=rect1.Height()/5;
eWidth=rect1.Width();
sHeight=eHeight*hstatic;

m_static1.MoveWindow(0,0,eWidth,sHeight); //设置静态文本框和编辑框的大小和位置
m_EDVal.MoveWindow(0,sHeight,eWidth,eHeight);

CRect rect2;

int hfont;
m_EDVal.GetWindowRect(rect2); //获得编辑框的客户区大小
//hfont=(rect2.Height()-10)*7;
this->ClientToScreen(rect2); //没有效果,用ScreenToClient()也一样;
hfont=(rect2.Height())*6.5; //设置字体高度;

if (&m_edFont==NULL)
{
m_edFont.CreatePointFont(hfont, _T("Arial"));
m_stFont.CreatePointFont(hfont*hstatic, _T("Arial"));
//这里也有个问题,如果我把*m_edFont定义为指针型成员变量,那运行时老是报错???????????不知道为什么

}
else
{
m_edFont.DeleteObject();
m_edFont.CreatePointFont(hfont, _T("Arial"));
m_stFont.DeleteObject();
m_stFont.CreatePointFont(hfont*hstatic, _T("Arial"));

}


// VERIFY(font1->CreatePointFont(hfont, _T("Arial")));


//pFont->CreatePointFontIndirect(&lf);

// pFont->CreatePointFontIndirect(180,_T("楷体_GB2312"));
m_EDVal.SetFont(&m_edFont,true);
m_edvals="3.1415926 mm";
m_static1.SetFont(&m_stFont,true);
m_stTips="设备状态:123";
m_EDVal.SetSel(-1);
UpdateData(false);


}


}
...全文
272 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2012-01-10
  • 打赏
  • 举报
回复
您好
我是本版版主
此帖已多日无人关注
请您及时结帖
如您认为问题没有解决可按无满意结帖处理
另外本版设置了疑难问题汇总帖
并已在版面置顶
相关规定其帖子中有说明
您可以根据规定提交您帖子的链接
如您目前不想结帖只需回帖说明
我们会删除此结帖通知

见此回复三日内无回应
我们将强制结帖
相关规定详见界面界面版关于版主结帖工作的具体办法
yayafu 2011-12-12
  • 打赏
  • 举报
回复
创建一种字体以后
SetFont();
或自绘编辑框
sunny_2 2011-12-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yayafu 的回复:]

创建一种字体以后
SetFont();
或自绘编辑框
[/Quote]
正解
Eleven 2011-12-11
  • 打赏
  • 举报
回复
创建一种字体以后
SetFont();
战在春秋 2011-12-11
  • 打赏
  • 举报
回复
CreatePointFont函数中nPointSize参数定义如下:
Requested font height in tenths of a point. (For instance, pass 120 to request a 12-point font.)

显然与CRect::Height 函数返回值不匹配。或者转换,或者改用CreateFont函数创建字体。
lfxiansheng 2011-12-11
  • 打赏
  • 举报
回复
rect2.Height()x10的话远远要大于编辑框的高度。。。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧