您的位置:首页 > 运维架构

error C2677: binary '-' : no global operator defined which takes type 'class CString' (or there is n

2014-12-01 15:48 525 查看
下面为MFC中加入的OnPaint()的代码:

CPaintDC dc(this);

CRect rectWnd;
CString cstrText;
UINT uFormat;
GetWindowText(cstrText);
dc.SelectObject(GetFont());
CSize size=dc.GetTextExtent(cstrText);
DWORD dwStyle=GetStyle();
GetWindowRect(rectWnd);
uFormat=DT_TOP;
if(dwStyle&SS_NOPREFIX)
uFormat|=DT_NOPREFIX;
dc.Draw3dRect(0,rectWnd.Height()/2,(rectWnd.Width()-size.cx)/2-m_Text,2,::GetSysColor(COLOR_3DSHADOW),::GetSysColor(COLOR_3DHIGHLIGHT));
dc.SetBkMode(TRANSPARENT);
dc.DrawText(cstrText,CRect((rectWnd.Width()-size.cx)/2,0,(rectWnd.Width()-size.cx)/2+size.cx,size.cy),DT_LEFT|DT_SINGLELINE|DT_VCENTER);
dc.Draw3dRect((rectWnd.Width()-size.cx)/2+size.cx,rectWnd.Height()/2,(rectWnd.Width()-size.cx)/2-m_Text,2,::GetSysColor(COLOR_3DSHADOW),::GetSysColor(COLOR_3DHIGHLIGHT));

提示:error C2677: binary '-' : no global operator defined which takes type 'class CString' (or there is n……

我查了一下代码,看了一下我给静态文本控件关联上了变量,而且正确引用了为什么会出错呢?

原来,静态文本控件绑定的变量是字符串类型,而在这里的代码段里需要一个数值类型,所以我在第一段之前加上了一段:

int m_TextConver=atof(m_Text.GetBuffer(0));

编译运行,问题解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐