CDialog上的可滚动CStatic

时间:2015-07-20 13:30:51

标签: c++ windows mfc

我在CDialog上有一个用于绘制内容的CStatic图片控件:

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
}

但是内容通常比控件大,所以我需要能够滚动内容。 CScrollView通过绘制到OnDraw中的视图自动处理,但我似乎无法让它在OnPaint()中工作。滚动时,控件将绘制空白或具有大量重复内容。

我基本上试图在CDialog上复制CScrollView的确切行为;我已经看到了一些与此相近的帖子,但我不想实现CDocument和CView。

1 个答案:

答案 0 :(得分:0)

我认为使用只读编辑控件要简单得多。

除了滚动之外,还可以让用户选择和复制部分文本。

相关问题