【问题标题】:Scrollable CStatic on CDialogCDialog上的可滚动CStatic
【发布时间】:2015-07-21 00:26:21
【问题描述】:

我在用于绘制内容的 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。

【问题讨论】:

    标签: c++ windows mfc


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      相关资源
      最近更新 更多