在基于mfc对话框中,CDispView是从CScrollView驱动的。需要放大到左键单击时的点,右键单击时缩小。以下工作部分。任何方式使其更好地工作?相应地调整滚动条的大小,放大一点等等。
xzfac = 1;
yzfac = 1;
void CDispView::OnInitialUpdate()
{
SetScrollSizes(MM_TEXT, CSize(cWidth, cHeight));
CScrollView::OnInitialUpdate();
}
void CDispView::OnDraw(CDC* pDC)
{
StretchDIBits(pDC->GetSafeHdc(), 0, 0,
(xzfac * pBmpInfo->bmiHeader.biWidth),
(yzfac * pBmpInfo->bmiHeader.biHeight),
0, 0, pBmpInfo->bmiHeader.biWidth,
pBmpInfo->bmiHeader.biHeight,
imageBuf, pBmpInfo, DIB_RGB_COLORS,
SRCCOPY);
}
void CDispView::refresh()
{
OnInitialUpdate();
}
void CDispView::OnLButtonDown(UINT nFlags, CPoint point)
{
yzfac = yzfac + 1;
xzfac = xzfac + 1;
refresh();
RedrawWindow();
CScrollView::OnLButtonDown(nFlags, point);
}
void CDispView::OnRButtonDown(UINT nFlags, CPoint point)
{
yzfac = yzfac - 1;
if (yzfac < 1) yzfac = 1;
xzfac = xzfac - 1;
if (xzfac < 1) xzfac = 1;
refresh();
RedrawWindow();
CScrollView::OnRButtonDown(nFlags, point);
}
答案 0 :(得分:0)
基于mfc对话框:使用此代码,无论我在哪里点击放大,它都会放大图像的右下部分.CDispView派生自CScrollView。
int sWidth = imgWidth;
int sHeight = imgHeight;
int PtX = 0;
int PtY = 0;
int cHeight; //client
int cWidth; //client
int vWidth = imgWidth;
int vHeight = imgHeight;
void CDispView::OnInitialUpdate()
{
SetScrollSizes(MM_TEXT, CSize(cWidth, cHeight));
CScrollView::OnInitialUpdate();
}
void CDispView::OnDraw(CDC* pDC)
{
StretchDIBits( pDC->GetSafeHdc(),
0, 0,
cWidth,
cHeight,
0, 0,
vWidth,
vHeight,
imgBuffer,
pBmpInfo,
IB_RGB_COLORS,
SRCCOPY );
}
void CDispView::InitBitmapInfo()
{
pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pBmpInfo->bmiHeader.biWidth = vWidth;
pBmpInfo->bmiHeader.biHeight = vHeight;
..etc..
}
void CDispView::refresh()
{
OnInitialUpdate();
}
void CDispView::OnLButtonDown(UINT nFlags, CPoint pt)
{
long x, y;
x= PtX + (pt.x/cWidth * vWidth);
y= PtY + (pt.y/cHeight * vHeight);
vWidth = (int) (vWidth/2);
vHeight = (int) (vHeight/2);
PtX= x - (pt.x/cWidth * vWidth);
PtY= y - (pt.y/cHeight * vHeight);
if (PtX < 0)
{PtX= 0;}
if (PtY < 0)
{PtY= 0;}
long temp = sWidth - vWidth;
if (PtX > temp)
{
PtX = temp;
}
temp= sHeight - vHeight;
if (PtY > temp)
{
PtY = temp;
}
if (vWidth < 50)
{
vWidth = sWidth;
vHeight = sHeight;
PtX = 0;
vPt = 0;
}
refresh();
Invalidate(0);
CScrollView::OnLButtonDown(nFlags, pt);
}
void CDispView::OnRButtonDown(UINT nFlags, CPoint pt)
{
PtX = 0;
PtY = 0;
vWidth = imgWidth;
vHeight = imgHeight;
refresh();
Invalidate(0);
CScrollView::OnRButtonDown(nFlags, pt);
}
答案 1 :(得分:-1)
您可以覆盖CView :: OnPrepareDC方法。它在OnDraw之前调用,并且是将CDC调整为不同比例因子和偏移以提供缩放效果的位置。例如,打印时使用此功能。通过改变CDC的比例,它可以让OnDraw同样适用于屏幕显示和打印。