我试图在CScrollView
- 派生类中显示图像:
C++ CScrollView, how to scroll an image?
所以我想覆盖OnDraw
,将代码从OnPaint
移到OnDraw
。但我不能。每次拨打Invalidate()
时,只会调用OnPaint
。
void CCardioAppView::OnDraw(CDC* pDC)
{
}
void CCardioAppView::OnPaint()
{
if (theApp.ImageFolderPath == _T("")) return;
//---------------------метод № 2 с CPictureHolder-------------------------------
CPaintDC dc(this);
CBitmap bmp;
BITMAP b;
HBITMAP hbitmap;
CRect rect;
auto bmp_iter = theApp.FullBmpMap.find(m_iCurrentImage);
if (bmp_iter == theApp.FullBmpMap.end()) return;
hbitmap = bmp_iter->second;
bmp.Attach((*bmp_iter).second);
bmp.GetObject(sizeof(BITMAP), &b);
GetClientRect(&rect);
scaleRect = rect;
OriginalWidth = b.bmWidth;
OriginalHeight = b.bmHeight;
if (rect.Height() <= b.bmHeight)
scaleRect.right = rect.left + ((b.bmWidth*rect.Height()) / b.bmHeight);
else if (rect.Height() > b.bmHeight)
{
scaleRect.right = b.bmWidth;
scaleRect.bottom = b.bmHeight;
}
scaleRect.right = scaleRect.right + scale_koef_g;
scaleRect.bottom = scaleRect.bottom + scale_koef_v;
pic.CreateFromBitmap(hbitmap);
pic.Render(&dc, scaleRect, rect);
(*bmp_iter).second.Detach();
(*bmp_iter).second.Attach(bmp);
bmp.Detach();
int isclWidth = scaleRect.Width();
int isclHeight = scaleRect.Height();
int irHeight = rect.Height();
int irWidth = rect.Width();
if ((isclWidth> irWidth)||(isclHeight > irHeight))
{
SetScrollSizes(MM_TEXT, CSize(isclWidth, isclHeight));
}
else SetScrollSizes(MM_TEXT, CSize(irWidth, irHeight));
}
答案 0 :(得分:1)
当然它不会调用OnDraw()
。当您致电Invalidate()
时,它会以WM_PAINT
派生类的CView
消息结束。 CView::OnPaint()
的默认实现获得了一个绘制DC,然后它调用CView::OnDraw()
。您已覆盖OnPaint()
,并且永远不会在OnDraw()
处理程序中调用OnPaint()
。
您可以将部分OnPaint()
代码移至OnDraw()
,但明显的内容除外CPaintDC dc(this);
之后,您可以删除OnPaint()
声明和实施。然后,删除您的ON_WM_PAINT()
消息映射条目。我不能保证你的绘图代码。