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));
编译运行,问题解决
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));
编译运行,问题解决
相关文章推荐
- 解决 C++错误 error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Stude
- C++,如何输出string类型的数据(报错:no operator defined which takes a right-hand operand of type 'class std::bas)
- error C2679: binary ',class std::allocator >' (or there is no accept
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_s
- error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::
- C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::basic
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- 错误 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::str
- ssh--添加json后,初始化配置一直显示There is no result type defined for type 'json' mapped with name
- Struts2 错误:There is no result type defined for type 'json' mapped with name 'success'.
- There is no result type defined for type 'json' mapped with name 'success'.
- SSH搭建遇到的问题---There is no result type defined for type 'json' mapped with name 'success'.
- struts2 配置错误There is no result type defined for type 'json'