如何使编辑框的字体大小与编辑框一样大??
时间:2011-12-11
来源:互联网
我用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);
}
}
我的代码如下:
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);
}
}
作者: lfxiansheng 发布时间: 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函数创建字体。
Requested font height in tenths of a point. (For instance, pass 120 to request a 12-point font.)
显然与CRect::Height 函数返回值不匹配。或者转换,或者改用CreateFont函数创建字体。
作者: fight_in_dl 发布时间: 2011-12-11
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28