如何得到 CRichEditView 最后一个可见行

kenshu 2012-04-14 06:03:35
用 GetRichEditCtrl().GetFirstVisibleLine()可以得到第一个可见行,如何得到最后一个可见行?

谢谢!
...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zacc 2012-04-14
  • 打赏
  • 举报
回复

//当前可见的第一行
const int nFirstVisibleLine = m_cRichEdit.GetFirstVisibleLine();
//可见的第一行的第一个字符的index
const DWORD dwCharIndex = (DWORD)m_cRichEdit.LineIndex(nFirstVisibleLine);
//获取这个字符相对于richedit客户区坐上角的坐标
const DWORD dwPos = m_cRichEdit.SendMessage(EM_POSFROMCHAR,dwCharIndex,0);
const short nXPos = (short)LOWORD(dwPos);
const short nYPos = (short)HIWORD(dwPos);

const int nLineCount = m_cRichEdit.GetLineCount();

for(int i = nFirstVisibleLine ; i < nLineCount ; i++)
{
DWORD dwCurIndex = 获取第i行的第一个字符的index;
short nCurYPos = 获取 dwCurIndex 相对于左上角的坐标;
if(nCurYPos > 客户区的height)
{
return 第i行不可见,第i-1行可见
}
else
{
do nothing
}

}

向立天 2012-04-14
  • 打赏
  • 举报
回复
滚动条滚到底就可以吧
::PostMessage(m_edit.GetSafeHwnd(), WM_VSCROLL, SB_BOTTOM, 0);
Eleven 2012-04-14
  • 打赏
  • 举报
回复

int nLine = m_edit.GetFirstVisibleLine();
CDC* pDC = m_edit.GetDC();
TEXTMETRIC tm;
VERIFY(pDC->GetTextMetrics(&tm));
m_edit.ReleaseDC(pDC);
CRect rect;
m_edit.GetWindowRect(&rect);
int cx = tm.tmHeight;
int nTotal = m_edit.GetLineCount()-1;
int nCount = 0;
CString strText(_T(""));

nCount = rect.Height() / cx + 1 + nLine + 1;


if(nLine >= nTotal)
{
strText.Format(_T("%d"), nTotal);
}
else
{
strText.Format(_T("%d"), nCount);
}
AfxMessageBox(strText);

try it
kenshu 2012-04-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
C/C++ code

//当前可见的第一行
const int nFirstVisibleLine = m_cRichEdit.GetFirstVisibleLine();
//可见的第一行的第一个字符的index
const DWORD dwCharIndex = (DWORD)m_cRichEdit.LineIndex(nFirstVisibleLi……
[/Quote]

谢谢!
kenshu 2012-04-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
滚动条滚到底就可以吧

C/C++ code
::PostMessage(m_edit.GetSafeHwnd(), WM_VSCROLL, SB_BOTTOM, 0);
[/Quote]

我不是要滚到底,比如总共100行,我屏幕能显示50行,第一个可见行为30,我要算出79.
kenshu 2012-04-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
C/C++ code

int nLine = m_edit.GetFirstVisibleLine();
CDC* pDC = m_edit.GetDC();
TEXTMETRIC tm;
VERIFY(pDC->GetTextMetrics(&tm));
m_edit.ReleaseDC(pDC);
CRect rect;
……
[/Quote]

算得好像不准,我没仔细跟(因为用了三楼的办法,可以,嘻,见谅),还是很感谢.

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧