简体   繁体   English

CDialog上的可滚动CStatic

[英]Scrollable CStatic on CDialog

I have a CStatic picture control on a CDialog that I use to draw content: 我在用于绘制内容的CDialog上有一个CStatic图片控件:

CMyDrawingControl.h 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.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(). CScrollView通过在OnDraw中绘制视图来自动进行处理,但是我似乎无法在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; 我基本上是想在CDialog上复制CScrollView的确切行为; I've seen some posts that come close to this, but I don't want to implement a CDocument and a CView. 我已经看到了一些与此相关的文章,但是我不想实现CDocument和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. 除了滚动之外,这还使用户可以选择和复制部分文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM