开发者

Setting the scroll position in edit control

I'm trying to set the scroll position in edit control and开发者_运维百科 I want set it 20% to bottom from the top. how I may go do that by taking a percentage?


The WM_VSCROLL message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.

http://msdn.microsoft.com/en-us/library/bb787577%28v=vs.85%29.aspx

You can first GetScrollRange() (http://msdn.microsoft.com/en-us/library/bb787587%28v=vs.85%29.aspx), calculate how many lines there are, then calculate the percentage. Afterward WindowProc() with VM_SCROLL or, of a much more simpler solution use the SetScrollPos() function http://msdn.microsoft.com/en-us/library/bb787597%28v=vs.85%29.aspx

You can find all the scroll functions here http://msdn.microsoft.com/en-us/library/ff486021%28v=VS.85%29.aspx

Hope this helped.


Specifically for an edit control setting the scroll position doesn't appear to actually move the text to the position expected. The scroll bar position is moved but the text stays where it is at.

To scroll an edit box I found the following to work as I expected:

double desiredPercentage = 0.7;
CEdit* pEditBox = (CEdit*)GetDlgItem(IDC_CONTROLID)

int totalLines = pEditLog->GetLineCount();
// Truncatest to the nearest int, do different rounding method for round up/down.
int scrollLine = (int)(desiredPercentage * (double)totalLines));

pEditBox->LineScroll(scrollLine);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜