简体   繁体   中英

Have trouble with setting a scroll bar

So i have 2 sub classed windows,both edit controls each has his own individual styles... I need the top window to hold a scroll bar with it since its a chat program,once there are more than 37 lines of text,there is no more space in this window. So by adding a scroll bar i alow extra space. now what i am trying to do is to set it to be,by default,at the bottom of the window,meaning to show the last written message. currently it is "stuck" on the upper side. what i tried to do is:

RECT    rc,rc2;
GetClientRect(window, &rc);
info.cbSize = sizeof(SCROLLINFO);
info.fMask = SIF_ALL|SIF_DISABLENOSCROLL;
info.nMax = lines;
info.nMin = 0;
info.nPage = 37;

And when the focus is set on that window (WM_SETFOCUS) i do this:

case WM_SETFOCUS:
{
     SetScrollInfo(window, SB_VERT, &info, TRUE);
            if( lines > 37 ){
                SetScrollPos(window,SB_VERT,400,TRUE);
            }
            else if( lines < 37){
                SetScrollPos(window,SB_VERT,0,TRUE);
            }
            ShowScrollBar(window,SB_VERT,1);
        return 0;
            }

So when i type,in the lower window (the other child) i get the scroll bar on top. When i click on the window i am talking about,his scroll bar drops down but the text is not redrawn. when i click the scroll bar to start scroling,it immidiatly redraws the text. To solve the problem when i type in the lower window i send a message from the lower child to the upper one. A message to WM_SETFOCUS that executes the code that puts the scroll bar at the bottom,but what happens is....that is goes down for a milisecond and comes right back up. i wonder why does it happen. I mean what message or default action causes the scroll bar to go up. Also how could i redraw the text with out needing to click the scroll bar? i tried something like ScrollWindowEx(window,0,400,&rc,NULL,NULL,&rc2,SW_SCROLLCHILDREN); but that fails...it redraws the text over the old text and disapears after a milisecond.. my only idea is to add another ScrollWindowEx and set it to erase the current text and redraw the new text but again i faer it will just disappear in a milisecond as it already does. Thanks for the help in advance :)

What you need to do is to tell the edit control to scroll to the bottom, and let it update the scroll bar. Just changing the appearance of the scroll bar isn't going to get the text into view.

Take a look at messages like EM_SCROLL and EM_SCROLLCARET . Or perhaps just send the edit control a WM_VSCROLL message with SB_BOTTOM . The edit control will then figure out how to update the scroll bar.

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