CStatic and scrollbars

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • absolute0
    New Member
    • Feb 2008
    • 8

    CStatic and scrollbars

    Hello,

    I am not quite familiar with MFC and I am having problems with scrollbars.

    I have a class that derives from CStatic.

    class CMyStatic : public CStatic

    I set up a horizontal scrollbar for it.

    SCROLLINFO si;
    si.cbSize = sizeof(SCROLLIN FO);
    si.fMask = SIF_PAGE | SIF_RANGE;
    si.nPage = rFrame.Height() ;
    si.nMax = rFrame.Height() + 8;
    si.nMin = 0 ;

    SetScrollInfo( SB_VERT, &si );
    EnableScrollBar Ctrl( SB_VERT, TRUE );


    I also have the OnHScroll, handled from my class

    void CMyStatic::OnHS croll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    {
    ...
    }


    When I run this, the scrollbar appears but it doesn't do anything. It doesn't respond when I click it.

    Any ideas why this is happening?

    Thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    The static control beneath the CStatic class is drawn in a specific way, since a static control doesn't normally have scroll bars I guess this takes no account of possible scroll bars on the control.

    If you want to do this you will need to override the OnDraw handler and draw the output of the control ourself taking account of the scrollbar locations.

    However if what you want is a scrollable control of uneditable text it might be easier to use an Edit Box with the Read Only style set.

    Comment

    • absolute0
      New Member
      • Feb 2008
      • 8

      #3
      The CStatic derived class is for displaying a graph. I've read that if a CWind derived class (of which CStatic is one) has a custom painting, the WM_PAINT is sent instead of WM_HSCROLL. Is this correct? I've tried to put a breakpoint at OnHScroll (in my class derived from CStatic) but it does not go there, so either the WM_HSCROLL is not sent or is sent somewhere else.

      I've seen a similar application that uses CStatic to display something and then scrollbar for it works. The OnHScroll is just used for it.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by absolute0
        The CStatic derived class is for displaying a graph. I've read that if a CWind derived class (of which CStatic is one) has a custom painting, the WM_PAINT is sent instead of WM_HSCROLL. Is this correct?
        That sounds rather wrong to me actually, those 2 messages are independent and if you had a window with a horizontal scrollbar that you painted yourself you would definitely need to receive both messages.

        Originally posted by absolute0
        I've tried to put a breakpoint at OnHScroll (in my class derived from CStatic) but it does not go there, so either the WM_HSCROLL is not sent or is sent somewhere else.

        I've seen a similar application that uses CStatic to display something and then scrollbar for it works. The OnHScroll is just used for it.
        In some cases the message goes to the parent and has to be reflected back to the control (but I am not sure this is one of those). Are you sure the other application did not use a separate scroll bar control rather than enabling the scroll bar on the static window?

        Comment

        • absolute0
          New Member
          • Feb 2008
          • 8

          #5
          I am sure the other application does not use a separate scrollbar control.

          It only has something like this

          SetScrollInfo( SB_HORZ, &si );
          EnableScrollBar Ctrl( SB_HORZ, TRUE );
          ShowScrollBar( SB_HORZ );

          It's also what I tried to follow

          Comment

          Working...