mfc 让CEdit的宽度自适应内容的宽度。 小弟想实现当CEdit的内容宽度超过其自身的宽度时,让CEdit自动变宽适应其内容 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CDC* pDC = m_edit.GetDC(); CString strText(_T("")); m_edit.GetWindowText(strText); CSize size = pDC->GetTextExtent(strText); m_edit.ReleaseDC(pDC); CRect rc; m_edit.GetWindowRect(&rc); ScreenToClient(&rc); rc.right = rc.left + size.cx; m_edit.MoveWindow(rc);可能不是很精确 的确不是很精确,我之前是用的这个方法。 CRect rc; CSize size; HDC hDC; HWND hWnd; CString strTextValue; int lenStrLen; CFontDialog AAB; CEdit* edit1=(CEdit*)GetDlgItem(IDC_EDITINPUT); edit1->GetClientRect(&rc); edit1->GetWindowText(strTextValue); lenStrLen=edit1->GetWindowTextLength(); hDC=::GetDC(edit1->m_hWnd); hWnd=edit1->m_hWnd; GetTextExtentPoint(hDC,strTextValue,lenStrLen,&size); ::SetWindowPos(hWnd,HWND_TOP,rc.top,rc.left,rc.left+size.cx,rc.bottom+4,SWP_NOMOVE|SWP_NOZORDER); ::ReleaseDC(hWnd,hDC);得到的效果和你的一样,不过你的代码看起来比我的简洁多了。我想找要实现的效果就是像搜狗输入法打字时的那样。 这个需要自绘控件实现 用系统的EDIT 确实可能存在一些问题 当然 你或许可以将(文字宽度)+(一小块宽度)来作为edit的宽度 关于COM的一个问题 使用套接字如何判断对方是否在线 MFC中combo box的与消息问题 对话框调用Navigate2 关于插入符 GDI+的字体问题 ms sans serif 一个很迷惑CComboBox的问题 请问:在c++中定义了两个类,一个类要用到另一个类的成员,另一个类要用到这个类的成员,该如何实现呀?? 帮帮忙,简单。在线等待! 微软公开的源码 文字写到图像文件中 VC 一个对话框界面中多个ComboBox的输入值需要互相限制如何实现?
CDC* pDC = m_edit.GetDC();
CString strText(_T(""));
m_edit.GetWindowText(strText);
CSize size = pDC->GetTextExtent(strText);
m_edit.ReleaseDC(pDC);
CRect rc;
m_edit.GetWindowRect(&rc);
ScreenToClient(&rc);
rc.right = rc.left + size.cx;
m_edit.MoveWindow(rc);可能不是很精确
CRect rc;
CSize size;
HDC hDC;
HWND hWnd;
CString strTextValue;
int lenStrLen;
CFontDialog AAB;
CEdit* edit1=(CEdit*)GetDlgItem(IDC_EDITINPUT);
edit1->GetClientRect(&rc);
edit1->GetWindowText(strTextValue);
lenStrLen=edit1->GetWindowTextLength();
hDC=::GetDC(edit1->m_hWnd);
hWnd=edit1->m_hWnd;
GetTextExtentPoint(hDC,strTextValue,lenStrLen,&size);
::SetWindowPos(hWnd,HWND_TOP,rc.top,rc.left,rc.left+size.cx,rc.bottom+4,SWP_NOMOVE|SWP_NOZORDER);
::ReleaseDC(hWnd,hDC);
得到的效果和你的一样,不过你的代码看起来比我的简洁多了。
我想找要实现的效果就是像搜狗输入法打字时的那样。