简体   繁体   中英

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM