CString str = "1234567890abcdefg";
CStatic *sta = (CStatic*)m_wndImagesInDB.GetDlgItem(IDC_00);
sta->SetWindowText(str);
现在假设IDC_00的长度不足以显示str中的字符串,请问如何设置才能使Static控件自动换行?
CStatic *sta = (CStatic*)m_wndImagesInDB.GetDlgItem(IDC_00);
sta->SetWindowText(str);
现在假设IDC_00的长度不足以显示str中的字符串,请问如何设置才能使Static控件自动换行?
根据所输入的文本的长度来决定换行GetWindowRect()
GetCharWidth()
计算要显示的字符串的长度(GetTextExtent),和static的长度比较,来相应的调整static的宽度
例如如果字符串长度为static长度1-2倍之间,就把宽度设置为原来2倍
ModifyStyle( 0, SS_LEFTNOWORDWRAP );
是设置Static不能自动换行的。
但是我的程序中默认就是不自动换行
所以我觉得肯定可以通过某种方法使它自动换行
还请高人指点
void CTestDlg::OnButton1()
{ CWnd * pWnd = GetDlgItem(IDC_STATIC_TEXT);
CString str;
pWnd->GetWindowText(str);
CString sTitle = str;
sTitle += str; CDC * pDC = pWnd->GetDC();
CSize sz = pDC->GetTextExtent(sTitle); CRect rc;
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc); int nRatio = (sz.cx+2)/rc.Width() +1;
rc.bottom = rc.top + (sz.cy) * nRatio;
pWnd->MoveWindow(&rc); pWnd->SetWindowText(sTitle);}每次点击按钮都会将标题长度*2,这里我保持的是控件宽度不变来计算换行后需要的高度~
选择styles,选中muitiline和Want return去掉
auto hscroll 就可以了!