简体   繁体   中英

Scrollable CStatic on CDialog

I have a CStatic picture control on a CDialog that I use to draw content:

CMyDrawingControl.h

CMyDrawingControl : CStatic
{
   //Constructor, Destructor, other items

   //End Constructor, Destructor, other items
public:
   void DrawStuff(CDC *dc);

protected:
   afx_msg void OnPaint();
   afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
}

CMyDrawingControl.cpp

CMyDrawingControl::CMyDrawingControl
{

}

BEGIN_MESSAGE_MAP(CMyDrawingControl, CStatic)
//{{AFX_MSG_MAP(CMyDrawingControl)
ON_WM_VSCROLL()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CMyDrawingControl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    //determine delta
    ScrollWindow(0, -delta);
    Invalidate();
    UpdateWindow();
}

void CMyDrawingControl::OnPaint()
{
    CPaint dc(this);

    DrawStuff(&dc);
}

void CMyDrawingControl::DrawStuff(CDC *dc)
{
    dc->SetMapMode(MM_LOMETRIC);

    //draw on dc
    //text, lines, shapes, etc
}

However the content is usually bigger than the control so I need to be able to scroll the content. CScrollView automatically handles by drawing to the view in OnDraw, but I can't seem to get it to work in OnPaint(). The control either will draw blank or has a lot of repeated content when scrolling.

I'm basically trying to duplicate the exact behavior of CScrollView on a CDialog; I've seen some posts that come close to this, but I don't want to implement a CDocument and a CView.

I think it is much simpler to use a read only edit control.

Beside scrolling this also makes it possible that the user can select and copy parts of the text.

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