dtwordbreak word break - 电脑|办公 - 电脑办公-杀毒安全-网络-V3学习网
微商网
 
 
导航:首页 |电脑|办公|正文

dtwordbreak word break

时间:2021-04-28 17:04:35
您好,请问您的vc listbox 显示多行的问题解决了么 class CMultiLineListBox :public CListBox 定义一个多行的类,父类是ClistBox { publi
作者:

您好,请问您的vc listbox 显示多行的问题解决了么

class CMultiLineListBox :public CListBox//定义一个多行的类,父类是ClistBox { public: //重载以下两个方法,这两个方法是用来绘图的 void MeasureItem(LPMEASUREITEMSTRUCT); void DrawItem(LPDRAWITEMSTRUCT); }; void CMultiLineListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS) { int nItem = lpMIS->itemID; CPaintDC dc(this); CString sLabel; CRect rcLabel; GetText( nItem, sLabel ); GetItemRect(nItem, rcLabel); int itemHeight = dc.DrawText( sLabel, -1, rcLabel, DT_WORDBREAK | DT_CALCRECT ); lpMIS->itemHeight = itemHeight; } //以下两个是方法实体 void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); COLORREF rColor = (COLORREF)RGB(255,255,255);//lpDIS->itemData; // RGB in item data CString sLabel; if (lpDIS->itemID == -1) return; GetText(lpDIS->itemID, sLabel); if ((lpDIS->itemState & ODS_SELECTED) && (lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE))) { CBrush colorBrush(rColor); CRect colorRect = lpDIS->rcItem; CBrush labelBrush(::GetSysColor(COLOR_HIGHLIGHT)); CRect labelRect = lpDIS->rcItem; pDC->FillRect(&labelRect,&labelBrush); COLORREF colorTextSave; COLORREF colorBkSave; colorTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); colorBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); pDC->DrawText( sLabel, -1, &lpDIS->rcItem, DT_WORDBREAK ); pDC->SetTextColor(colorTextSave); pDC->SetBkColor(colorBkSave); return; } if (lpDIS->itemAction & ODA_DRAWENTIRE) { CBrush brush(rColor); CRect rect = lpDIS->rcItem; pDC->SetBkColor(rColor); pDC->FillRect(&rect,&brush); pDC->DrawText( sLabel, -1, &lpDIS->rcItem, DT_WORDBREAK ); return; } if (!(lpDIS->itemState & ODS_SELECTED) && (lpDIS->itemAction & ODA_SELECT)) { CRect rect = lpDIS->rcItem; CBrush brush(rColor); pDC->SetBkColor(rColor); pDC->FillRect(&rect,&brush); pDC->DrawText( sLabel, -1, &lpDIS->rcItem, DT_WORDBREAK ); return; } } ======================== 使用create方法创建时,应该使用如下的style LBS_USETABSTOPS|LBS_STANDARD|WS_VISIBLE|LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS 不可以缺少其中的任何一个,否则可能没有效果

qt中drawtext只能绘制常量的字符串吗

使用DrawText函数输出文字,如果需要让输出的内容在指定矩形内自动换行,则可以使用DT_WORDBREAK选项。

但根据API说明,该选项只能截断单词,即只在单词间的空格处分割。

如果输出内容是一长串没有空格分隔的ASCII码(如英文字符或数字),那么该长串会被当做一个单词来处理而不会自动换行(中文字符没有此问题)。

如果要让ASCII码组成的长字符自动换行,那么可以使用DT_WORDBREAK和DT_EDITCONTROL两个选项搭配控制。

函数原型:int DrawText(HDC hDC, // 设备描述表句柄LPCTSTR lpString, // 将要绘制的字符串int nCount, // 字符串的长度LPRECT lpRect, // 指向矩形结构RECT的指针UINT uFormat // 正文的绘制选项);函数描述:函数DrawText用设备环境中的字体、正文颜色和背景颜色来写正文。

DrawText裁剪正文,不会超出指定矩形,除非指定了DT_NOCLIP。

除非使用DT_SINGLELINE格式化,否则其余的格式都认为正文有多行。

C++里MFC的静态文本文字会在输出位置出现一个白色的大方

没有太好的办法,只能自己新建一个类继承CStatic,然后响应WM_PAINT消息自己来绘制文本,在绘制文本的时候设置背景模式为透明模式。

然后为你的这个静态文本框添加控制变量,变量类型就是你新建的这个类。

绘制静态框文本大致代码如下,必要的时候自己再构建合适的字体:void CMyStatic::OnPaint() {CPaintDC dc(this); // device context for paintingRECT rcClient;GetClientRect(&rcClient);int nLen = ::GetWindowTextLength(m_hWnd);char *strTitle = new char[nLen + 1];::GetWindowText(m_hWnd, strTitle, nLen + 1);dc.SetBkMode(TRANSPARENT);dc.DrawText(strTitle, nLen, &rcClient, DT_WORDBREAK | DT_LEFT);delete strTitle;}

【zt】DrawText如何换行

例如如果输入一连串英文字符,那么它会当做一个单词来处理,而不会自动换行。

而对于中文字符则可以。

如果要对所有字符都可以像Edit控件中那样自动换行,那么可以使用DT_WORDBREAK | DT_EDITCONTROL DT_EDITCONTROLDuplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.(2)DT_CALRECT的使用对于一段text,要计算他的显示大小,那么可以使用DT_CALRECT标志。

其中的rect参数属于IN/OUT类型。

输出时,左上角坐标不变,右下角坐标改变。

函数返回值是文本的高度。

当然,它要与不同格式标志一起使用得到的结果是不一样的。

DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawText will use the width of the rectangle pointed to by lpRect and extend the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText will modify the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text, but does not draw the text

C++ DrawText DT

DT_EDITCONTROL的官方解释是:Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.简单讲就是加了这个标志,当字符串比较长,edit control 无法容纳最后一些个多出来的字符串的时候,edit control就不显示它们。

只有当字符串比较长的时候才可以看出来加和没加DT_EDITCONTROL的区别。

vb print 换行

使用DrawText函数输出文字,如果需要让输出的内容在指定矩形内自动换行,则可以使用DT_WORDBREAK选项。

但根据API说明,该选项只能截断单词,即只在单词间的空格处分割。

如果输出内容是一长串没有空格分隔的ASCII码(如英文字符或数字),那么该长串会被当做一个单词来处理而不会自动换行(中文字符没有此问题)。

如果要让ASCII码组成的长字符自动换行,那么可以使用DT_WORDBREAK和DT_EDITCONTROL两个选项搭配控制。

函数原型:int DrawText(HDC hDC, // 设备描述表句柄LPCTSTR lpString, // 将要绘制的字符串int nCount, // 字符串的长度LPRECT lpRect, // 指向矩形结构RECT的指针UINT uFormat // 正文的绘制选项);函数描述:函数DrawText用设备环境中的字体、正文颜色和背景颜色来写正文。

DrawText裁剪正文,不会超出指定矩形,除非指定了DT_NOCLIP。

除非使用DT_SINGLELINE格式化,否则其余的格式都认为正文有多行。

...

大家还关注
阅读排行
推荐阅读