Scrolling size on zooming
-
Hi, I got one CZoomView sample file form code project.Actually i want zoom fucntion in my applcaiton for every view.In tht,initially when i set scrollposition,extra window is appearing. For example,in OnDraw(),i set background of window as black
CRect mClientArea;
GetClientRect(&mClientArea);
pDC->FillRect(&mClientArea,&CBrush(RGB(0,0,0)));I set scroolsize as
m_layout.cx = GetSystemMetrics( SM_CXSCREEN );
m_layout.cy = GetSystemMetrics( SM_CYSCREEN );
m_page.cx = m_layout.cx/2; m_page.cy = m_layout.cy/2;
m_line.cx = m_layout.cx/50; m_line.cy = m_layout.cy/50;
SetScrollSizes(MM_TEXT, m_layout, m_page, m_line);What happended is after execution,when i scroll the horizonatal or vertical scrolls,the window is scrolling more than actual window rect. More white screen is appearing apart for black background.How can i avoid that? Because while zooming,if user move the scrolls,then extra empty window will appear.i want to avoid that.
Anu
-
Hi, I got one CZoomView sample file form code project.Actually i want zoom fucntion in my applcaiton for every view.In tht,initially when i set scrollposition,extra window is appearing. For example,in OnDraw(),i set background of window as black
CRect mClientArea;
GetClientRect(&mClientArea);
pDC->FillRect(&mClientArea,&CBrush(RGB(0,0,0)));I set scroolsize as
m_layout.cx = GetSystemMetrics( SM_CXSCREEN );
m_layout.cy = GetSystemMetrics( SM_CYSCREEN );
m_page.cx = m_layout.cx/2; m_page.cy = m_layout.cy/2;
m_line.cx = m_layout.cx/50; m_line.cy = m_layout.cy/50;
SetScrollSizes(MM_TEXT, m_layout, m_page, m_line);What happended is after execution,when i scroll the horizonatal or vertical scrolls,the window is scrolling more than actual window rect. More white screen is appearing apart for black background.How can i avoid that? Because while zooming,if user move the scrolls,then extra empty window will appear.i want to avoid that.
Anu
Anu, Try this: // header file: "MyScrollView.h"
#pragma once
class CDoc;
class CMyScrollView : public CScrollView
{
DECLARE_DYNCREATE(CMyScrollView)
DECLARE_MESSAGE_MAP()public:
CMyScrollView();
virtual ~CMyScrollView();CDoc\* GetDocument();
protected:
virtual void OnDraw(CDC* pDC);
virtual void OnInitialUpdate();private:
int Height;
int Width;
CBitmap* Bitmap;
CDC* MemDC;
};// implementation file: "MyScrollView.cpp"
#include "stdafx.h"
#include "MyScrollView.h"IMPLEMENT_DYNCREATE(CMyScrollView, CScrollView)
BEGIN_MESSAGE_MAP(CMyScrollView, CScrollView)
END_MESSAGE_MAP()CMyScrollView::CMyScrollView() :
Bitmap(new CBitmap), Width(1000), Height(200), MemDC(new CDC)
{
MemDC->CreateCompatibleDC(NULL);
}CMyScrollView::~CMyScrollView()
{
delete Bitmap;
delete MemDC;
}CDoc* CMyScrollView::GetDocument()
{ return (CDoc*)m_pDocument; }void CMyScrollView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();GetParentFrame()->SetWindowText("CMyScrollView"); CClientDC dc(this); Bitmap->CreateCompatibleBitmap(&dc, Width, Height); Bitmap->SetBitmapDimension(Width, Height); CBitmap\* OldBitmap = MemDC->SelectObject(Bitmap); MemDC->PatBlt(0, 0, Width, Height, BLACKNESS); CPen WhitePen(PS\_SOLID, 1, RGB(255,255,255)); CPen\* OldPen = MemDC->SelectObject(&WhitePen); MemDC->MoveTo(0, 0); // ie top left MemDC->LineTo(Width, Height); // ie bottom right MemDC->MoveTo(Width, 0); // ie top right MemDC->LineTo(0, Height); // ie bottom left MemDC->SelectObject(OldPen); CPen RedPen(PS\_SOLID, 1, RGB(255,0,0)); OldPen = MemDC->SelectObject(&RedPen); MemDC->Rectangle(0,0,10,10); // red rect in top left MemDC->SelectObject(OldPen); CPen GreenPen(PS\_SOLID, 1, RGB(0,255,0)); OldPen = MemDC->SelectObject(&GreenPen); MemDC->Ellipse(Width-20, Height-20, Width, Height); // green circle bottom right MemDC->SelectObject(OldPen); CRect Rect(0,Height-20,20,Height); CBrush Brush(RGB(0,0,255)); MemDC->FillRect(Rect, &Brush); // blue rect in bottom left MemDC->SelectObject(OldBitmap); SetScrollSizes(MM\_TEXT, CSize(Width, Height)); ResizeParentToFit(TRUE);
}
void CMyScrollView::OnDraw(CDC* pDC) // works!
{
if (Bitmap)
{
pDC->SetStretchBltMode( COLORONCOLOR );CBitmap\* OldBitmap = MemDC->SelectObject(Bitmap); pDC->BitBlt( // l, t, w, h 0, 0, Width, Height,