CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    3

    SetViewportOrg and weird artifacts after scrolling

    Hello all!

    For some reason, after a call to SetViewpointOrg I get strange artifacts in the client window after scrolling.

    Basically, the setup is as follows:

    In CMyAppView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo):

    [ccode]
    CScrollView::OnPrepareDC(pDC, pInfo);
    pDC->SetMapMode( MM_ANISOTROPIC );
    pDC->SetWindowExt( 200, -200 );
    pDC->SetViewportExt( 1000, 1000 );
    pDC->SetViewportOrg( 500, 500 );
    [/ccdode]

    The idea is to set up a Cartesian coordinate system to plot graphs. If I comment out the SetViewportOrg line above, I have no problems (except the origin is fixed in its location in the upper left-hand corner, whereas I want some flexibility for this). However, after a call to SetViewportOrg, no matter what arguments I send it -- (0,0), (100,100), (0,100), etc. -- I always have artifacts left on the window if I scroll about.

    What am I doing wrong? I hope that some better minds out there can pull me out of this morass!




  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: SetViewportOrg and weird artifacts after scrolling

    Are the artifacts in the region that should have been invalidated? If it is, this is a clue that you may not be receiving (or handling) the WM_PAINT message properly when you scroll a window.

    Also, run the app using a different screen resolution, and see if the problem still occurs.

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: SetViewportOrg and weird artifacts after scrolling

    Hmmm ... you're right: I have NOT been handling WM_PAINT messages. All my screen updates were handled through OnDraw(). However, erasing the background and redrawing through OnPaint() brought EXACTLY the same results. I have found a workaround though:

    In the OnPrepareDC() function:

    pDC->SetMapMode( MM_ANISOTROPIC );
    pDC->SetWindowExt( 100, -100 );
    pDC->SetViewportExt( 1000, 1000 );
    pDC->SetWindowOrg( 0, 0);
    pDC->SetViewportOrg( -GetDeviceScrollPosition() );
    pDC->OffsetViewportOrg(500, 500);

    The key section appears to be where I call SetViewportOrg() with the negative of the return from GetDeviceScrollPosition(), and the use OffsetViewportOrg to correctly locate the origin. This works perfectly, with the origin just about anywhere I want it, and no artifacts or any other undesirable behaviour when scroll.

    Now my question is ... ***?!!! What did I just do? I do not understand it all -- basically it was just one of the hundreds of things I was trying and cobbled together largely by accident (I saw the SetViewportOrg() used in the above way in some sample code, and it worked for me, so I tried adding the OffsetViewportOrg in what I thought was going to be a vain attempt at setting the origin properly). Can you or anyone else enlighten me on what exactly is going on here? Why does the above code fragment do, and why does it do it well when the previous one could not at all? What did I do right?

    Thanks!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured