CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Scroller

  1. #1
    Join Date
    May 1999
    Posts
    19

    Scroller

    Hia. I've tried to put up a scroller like this:


    EnableScrollBarCtrl(SB_VERT,TRUE);
    SetScrollRange(SB_VERT,0,1000,TRUE);




    My scrollbar appears, but it's not scrollable at all, even though my ondraw draws beyond the borders. How do I enable it?

    Sincerely yours

    Niklas


  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Scroller

    Is this a CScrollView you are using? If yes, then you do not need to fiddle with the scroll bars, but instead call SetScrollSizes() to tell the view how big it is supposed to be; after that, scrolling will be automatic.

    If you are not using a CScrollView, why not? If you want a view, and you want scrolling, = CScrollView!



    --
    Jason Teagle
    [email protected]

  3. #3
    Join Date
    May 1999
    Posts
    19

    Re: Scroller

    I am not using CScrollView as I'm developing an edit control which I want to support scrolling.


  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Scroller

    Hmmm... If you are using an edit control, why are you 'drawing' on it (you mentioned both OnDraw() and drawing)?

    An edit box judges whether it needs to scroll or not by how many lines of text it contains. If you are drawing in it rather than setting text into it, that's why it doesn't work. You would have to override OnVScroll() to change this behaviour, but that means deriving from the edit control. In your OnVScroll() you would then have to decide how big the viewing area is and redraw as if the DC had been scrolled to the new position - tricky.



    --
    Jason Teagle
    [email protected]

  5. #5
    Join Date
    May 1999
    Posts
    19

    Re: Scroller

    As I said I am developing an Edit-control as CEdit didn't have close to the functions we needed when it comes to structurizing information. Think of it as a CView which I want to implement a scrollbar on.


  6. #6
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Scroller

    I'm afraid we seem to be going round in circles and not solving your problem.

    You want a window (read: control) which supports editing, but which can be drawn in and allows scrolling INCLUDING the area used by images.

    How about a CRichEdit control (CRichEditView)? This can include text and pictures, handles editing, and handles the scrolling and everything.

    I can't understand why you would not want to use this, which appears to have the basic features you want, but if you don't, CScrollView is still the best bet - you said yourself 'think of it as a CView which supports scrolling' - exactly what CScrollView is! CEditView can give you a scrollable edit system, but will not be any good for pictures.

    I seriously suggest you consider CRichEditView.



    --
    Jason Teagle
    [email protected]

  7. #7
    Join Date
    Apr 1999
    Posts
    4

    Re: Scroller

    You should have handled such messages as WM_HSCROLL and WM_VSCROLL in your
    view class. In those message handlers you can call ScrollWindow() API to
    make your view be scrollable. But it will be hard work if you start it from
    scratch. See the MSDN sample code 'ShowDIB.c' for an old fashoned example
    of scroll message handling, or MFC source code of CScrollView class for an
    alternative(and much more general form of) example.

    Good luck!



  8. #8
    Join Date
    May 1999
    Posts
    19

    Re: Scroller

    As I said, I am developing a control. The 'view' is derived from COleControl which in turn is derived from CWnd which is derived from CCmdTarget which is derived from CObject. I cannot use CScrollView as it is not this kind of application. I cannot use neither CEdit nor CRichTextEdit as what I need is to parse structured information and keep it internally on that structured format so that I can give away a pointer to the data which at any given time are structured there. Therefor it's alpha and omega for me to draw the contents of my control. What I want is an easy way to implement a scroller into this control. Any suggestions how?


  9. #9
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Scroller

    I am beginning to understand. When you originally said control, I assumed you just meant that you were developing a new window-based class - I did not realise you meant OCX / ActiveX / whateverX.

    I think you can embed a CView-derived window in this control, by creating it as a child. Then you can make it cover the whole of the COleControl window, making it look like it is just the one window.

    Anyway, working on your plain CWnd, you need to maintain the total size of your effective drawing area (which will become greater than the actual window size), and also of the top-left position of the drawing area (since when you scroll, the top-left of the drawing area moves to the left and above the window's top-left). This is effectively what CScrollView does.

    Just setting the size of the scrollbar is not enough - for a generic CWnd, you need to actually do something when a scroll is attempted (handle WM_HSCROLL and WM_VSCROLL messages). In this case, all you need to do is adjust the maintained top-left position, call SetViewportOrg() to offset DC operations correctly (negative values passed to SetViewportOrg() make it look like you have scrolled to the right or down), and invalidate the window, so that it repaints (to reduce flicker, use CWnd::ScrollWindow() (and possibly CDC::ScrollDC() ) - the new portion of window will be painted when OnPaint() is next called by the system).

    When you want to draw beyond the existing area, you will have to adjust your maintained size and the scroll bar sizes accordingly.



    --
    Jason Teagle
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured