我用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);
}
}
解决方案 »
- 在Win7下使用服务调用应用程序的问题
- 为嘛总是有人拿着MFC做界面这个事成天叨叨????
- PNG图片已经是透明的了,为什么贴图之后,还是有一个白底?
- 问个vc连接SQL的问题
- 招聘C++程序员,工作地点成都
- 为什么我挂接的WH_GETMESSAGE全局钩子有时会失效?
- 用过xvid的帮帮我吧,windows下是不是就用vfw目录下的那个就可以了?
- 请问大家,现在小弟想从一个文件中读出所以文本来,如何是好?
- FindWindow查找窗体句柄的时候为空
- 怎么做从一侧滑出的对话框,象mediaplay一样,从主体边滑出另一个小的对话框,例如声音调整。
- VS2008下不能从“const char *”转换为“LPCTSTR”,用_T()解决不了
- 界面开发
Requested font height in tenths of a point. (For instance, pass 120 to request a 12-point font.)显然与CRect::Height 函数返回值不匹配。或者转换,或者改用CreateFont函数创建字体。
SetFont();
SetFont();
或自绘编辑框