0
votes

I am trying to implement a zoom in function to my app. The idea is when I chose to zoom in, the graph should expand horizontally 2 times larger so that only half of the graph will be shown in the window, and one will need to scroll to see the other half despite the size of the window.

I have a zoom variable for zoom factor. Then in onDraw(CDC &pDC):

//...set pen and others...
CRect rect;
GetClientRect(rect);
for (int x=0; x < zoomFactor*rect.Width(); x++)
    //....draw the graph

then in onToolsZoomin():

void CMyGraphView::OnToolsZoomin()
{
    zoom *= 2;
    CRect rect;
    GetClientRect(rect);
    CSize sizeTotal;
    sizeTotal.cx = zoom*rect.Width();
    sizeTotal.cy = 0;
    SetScrollSizes(MM_TEXT, sizeTotal);
    this->RedrawWindow();
}

When I run this, I can have the window correctly draw half of the graph and a scrollbar that indicate only half of the graph is shown. But when I try to scroll it, it goes back to the original position (bottom left) and the other half of the graph won't show up.

1
what kind of application is this? Is it a dialog based, or SDI/MDI. In the latter case, all you need to do is to expand the size of the View you are using to draw the graph (using MoveWindow()). The scrollbars will appear automatically on the mainframe.cha
I'm doing MDI. I tried to add MoveWindow(rect.left, rect.top,rect.Width(), rect.Height(),true); to onToolsZoomin, but still not working. (i also tried to pass 2*rect.width() and rect.width()/2). It looks like the original graph would be split to two but both are still visible in same window if I call it with rect.width()/2.LoveProgramming

1 Answers

0
votes

The parameters in both functions are not the same one. It can be the first reason of the problem. Can you put the code that is suppose to call OnToolsZoomin please ? Is it handled through a WM_VSCROLL or WM_HSCROLL message ? Is your function OnToolsZoomin called at all ? Is you scrollbar properly initialized (scroll range) ?