January 19th, 2009, 08:16 PM
I'm learning on my own how drawing icons, scaling, and scrolling using Visual C++. My project is to place any icon in the child window, zoom in or out, and scroll anywhere. I am able to place icons with a rectangle around the icon, zoom in (out is just as easy and I'll include it later), BUT I can't scroll. The scroll bars will change size as I zoom in. However, the scroll bars don't scroll but return to their original location after I try to drag them even though they change size depending on the scale I'm using. What can I do? I included the relevant parts of code in CScrollView as I don't use the CDocument or anything else.
I right click to zoom in use the OnRButton message:
// Increment the scale to zoom in and set the scrollbar size
void CME6View::OnRButtonUp(UINT nFlags, CPoint point)
Here's my OnPrepareDC code. I use GetClipBox to cause window extent to be the size of visible window instead of a CSize variable in the document as most examples use. I make sure to subtract the BottomRight from the TopLeft so that the BottomRight is larger than normal in the I have scrolled as in VRx and VRy.
void CME6View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
CME6Doc* pDoc = GetDocument();
pDC->GetClipBox(m_VisRect);// Visible rectangles in pixels
int VRx = m_VisRect.BottomRight().x - m_VisRect.TopLeft().x;
int VRy = m_VisRect.BottomRight().y - m_VisRect.TopLeft().y;
int PpIX = pDC->GetDeviceCaps(LOGPIXELSX);// pixels / inch - x
int PpIY = pDC->GetDeviceCaps(LOGPIXELSY);// pixels / inch - y
// Calculating the window
int WEx = VRx / PpIX;
if(WEx < 1) // To prevent the window extent x-coord from being zero
WEx = 1;
int WEy = VRy / PpIY;
if(WEy < 1) // To prevent the window extent y-coord from being zero
WEy = 1;
// Calculating the viewport extent
int VEx = WEx * m_Scale;
int VEy = WEy * m_Scale;
// For troubleshooting
//AfxMessageBox(_T("ClipBox: " + ToStringI(VRx) + ", " + ToStringI(VRy) + "\npixels / inch: " + ToStringI(PpIX) + ", " + ToStringI(PpIY) + "\nWE: " + ToStringI(WEx) + ", " + ToStringI(WEy) + "\nVE: " + ToStringI(VEx) + ", " + ToStringI(VEy)), MB_OK);
This is how I set the scroll bar sizes:
// Set the scroll bars
SetScrollSizes(MM_TEXT, CSize((m_VisRect.BottomRight().x - m_VisRect.TopLeft().x) * m_Scale, (m_VisRect.BottomRight().y - m_VisRect.TopLeft().y) * m_Scale));
I had oringially used OnInitialUpdate but I have left it blank to set up scrollbars after zooming
// Not using this as it's not initially important
January 19th, 2009, 08:29 PM
Re: inmovable scrollbars
Hard to understand code without [code][/code] tag...
Anyway, I don't think you can call directly OnPrepareDC()... It is called by the framework when it is needed, in response to an appropriate window message being sent where needed... I suggest not to mess with function that start with On---, because they are message handlers, and usually don't work outside their context
Last edited by Buzzyous; January 19th, 2009 at 08:38 PM.
- Buzzyous -
January 20th, 2009, 07:50 AM
Re: inmovable scrollbars
Does that explain why I can zoom in but the scroll bars don't move?
Tags for this Thread
Click Here to Expand Forum to Full Width