我正在尝试在CScrollView-derived类中显示图像:
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));
}发布于 2016-10-21 14:23:35
当然它不会调用OnDraw()。当您调用Invalidate()时,它以CView派生类的WM_PAINT消息结束。CView::OnPaint()的默认实现获得一个paint DC,然后调用CView::OnDraw()。您正在重写OnPaint(),并且从未在OnPaint()处理程序中调用OnDraw()。
除了像CPaintDC dc(this);这样显而易见的东西之外,您可以将一些OnPaint()代码转移到OnDraw()中
之后,您可以删除您的OnPaint()声明和实现。然后,删除您的ON_WM_PAINT()消息映射条目。我不能保证你的绘图代码。
https://stackoverflow.com/questions/40148533
复制相似问题