我正在写一个查找字符的功能,要查找字符的开始(start)和结束(end)位置都已确定,就是在显示的时候不是总能移动到正确的位置,特别是在移动的距离较大是,就失败,不知道为什么,请高手帮忙。窗口移动的代码如下:
void CProgramView::ShowFind(int start, int end)
{
CEdit& theEdit = GetEditCtrl();
theEdit.SetSel(start, end, TRUE); CPoint pt = theEdit.PosFromChar(start);
CRect rc;
theEdit.GetClientRect(&rc); TEXTMETRIC tc;
CDC *pDC = theEdit.GetDC();
pDC->GetTextMetrics(&tc);

if(pt.y < 0)//在框的上面
{
theEdit.LineScroll(pt.y/tc.tmHeight);
} if (pt.y > rc.Height() - 18)//在框的下面
{
theEdit.LineScroll((pt.y - rc.Height() + 30 )/tc.tmHeight);
}
}