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.
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;
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.