C++ DrawText不';在MFC中,不要在文本末尾添加省略号
我有一个简单的MFC应用程序,我试图在字符串的末尾添加省略号 这是我的密码:C++ DrawText不';在MFC中,不要在文本末尾添加省略号,c++,mfc,C++,Mfc,我有一个简单的MFC应用程序,我试图在字符串的末尾添加省略号 这是我的密码: void CMFCApplication1Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc(
void CMFCApplication1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
CRect rect;
rect.top = 0;
rect.bottom = 100;
rect.left = 0;
rect.right = 100;
dc.DrawText(_T("This is a very very long text that should span accross multiple lines and have elipsis at the end"), -1, &rect, DT_WORDBREAK | DT_MODIFYSTRING | DT_END_ELLIPSIS);
CDialogEx::OnPaint();
}
}
void CMFCApplication1Dlg::OnPaint()
{
if(IsIconic())
{
CPaintDC(this);//用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND,reinterpret_cast(dc.GetSafeHdc()),0);
//在客户端矩形中居中图标
int cxIcon=GetSystemMetrics(SM_cxIcon);
int cycon=GetSystemMetrics(SM_cycon);
正确无误;
GetClientRect(&rect);
intx=(rect.Width()-cxIcon+1)/2;
int y=(rect.Height()-cycon+1)/2;
//绘制图标
dc.DrawIcon(x,y,m_hIcon);
}
其他的
{
CPaintDC(this);//用于绘制的设备上下文
正确无误;
rect.top=0;
rect.bottom=100;
rect.left=0;
rect.right=100;
dc.DrawText(_T(“这是一个非常长的文本,应该跨越多行,并且在末尾有省略号”),-1,&rect,DT_WORDBREAK | DT_MODIFYSTRING | DT|u end |省略号);
CDialogEx::OnPaint();
}
}
这就是我得到的:
我希望在字符串的末尾添加省略号。我做错了什么?如@JonnyMoop
DT\u MODIFYSTRING
所述,不能与常量字符串的DT\u END\u省略号一起使用。在这种情况下,您只需删除DT_MODIFYSTRING
DT_分词
和DT_结尾_省略号
不能很好地协同工作。尝试添加DT\u EDITCONTROL
另外,CDialogEx::OnPaint()
是对CPaintDC(this)的调用代码>所以不要同时使用它们
void CMFCApplication1Dlg::OnPaint()
{
CPaintDC dc(this);
CRect rect;
rect.top = 0;
rect.bottom = 100;
rect.left = 0;
rect.right = 100;
CString s = L"This is a very very long text that should span accross multiple lines and have elipsis at the end";
dc.DrawText(s, &rect, DT_EDITCONTROL | DT_WORDBREAK | DT_END_ELLIPSIS);
}
正如@JonnyMoopDT\u MODIFYSTRING
所指出的,对于常量字符串,不能与DT\u END\u省略号一起使用。在这种情况下,您只需删除DT_MODIFYSTRING
DT_分词
和DT_结尾_省略号
不能很好地协同工作。尝试添加DT\u EDITCONTROL
另外,CDialogEx::OnPaint()
是对CPaintDC(this)的调用代码>所以不要同时使用它们
void CMFCApplication1Dlg::OnPaint()
{
CPaintDC dc(this);
CRect rect;
rect.top = 0;
rect.bottom = 100;
rect.left = 0;
rect.right = 100;
CString s = L"This is a very very long text that should span accross multiple lines and have elipsis at the end";
dc.DrawText(s, &rect, DT_EDITCONTROL | DT_WORDBREAK | DT_END_ELLIPSIS);
}
您有DT_MODIFYSTRING
,但正在发送常量字符串。尝试发送可修改的字符串。您有DT\u MODIFYSTRING
,但正在发送常量字符串。尝试发送可修改的字符串。