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

来源:互联网 发布:java bigdecimal 比较 编辑:程序博客网 时间:2024/04/28 12:53

下面为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));

编译运行,问题解决


0 0
原创粉丝点击