Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh after scrolling

Status
Not open for further replies.

StefanoCarniel

Programmer
Apr 29, 2005
15
0
0
IT
I have a problem with an SDI application with the View class derived from CScrollView. In the main window, every time the user click the mouse I draw a point.
Then I use the horizontal scroll bar to reach the right margin of the window and the go back to the left margin, but the previous point are lost. To have the correct picture again I have to resize the window. In the OnPaint function I wrote a cycle the draws all the point saved in an archive (using the document/view paradigma). I tried to call the OnPaint function in the OnScroll event but nothing happens.
Can you help me?
Thank you
 
Do you take GetScrollPosition(...) into account when drawing your stuff?

I tried to call the OnPaint function in the OnScroll event but nothing happens.

You typically call Invalidate(...) to enforce repainting.

/Per
[sub]
www.perfnurt.se[/sub]
 
I don't know how to use GetScrollPosition...
Here's the code I use:

CView::OnPaint()
{
CPaintDC dc(this); // device context for painting

CRect rect;
GetClientRect (&rect);
dc.FillSolidRect (rect, RGB (0, 0, 0));
CSchermoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

int i;
for (i=0; i<pDoc->x.GetSize(); i++)
dc.SetPixel (pDoc->x,pDoc->y, RGB (0,0,0));
}

... and then ...

BOOL CSchermoView::OnScroll(UINT nScrollCode, UINT nPos,
BOOL bDoScroll)
{
OnPaint();

return CScrollView::OnScroll(nScrollCode, nPos,
bDoScroll);
}
 
>I don't know how to use GetScrollPosition

See
You typically add the scroll positions' x and y to the coordinates used when drawing stuff otherwise scrolling will have no effect (you keep drawing on the same place)

As mentioned, you typically call Invalidate(...) to enforce repainting.
Code:
CSchermoView::someMehtodThatNeedsRepainting()
{
  Invalidate();
  ...
But I dont think you really need to do that when scolling.

Other than that, your drawing doesn't make much sense:
1) First you fill it all black
Code:
dc.FillSolidRect (rect, RGB (0, 0, 0));
2) Then you put black pixels on the black background
Code:
dc.SetPixel (pDoc->x[i],pDoc->y[i], RGB (0,0,0));
What do you expect, really?



/Per
[sub]
www.perfnurt.se[/sub]
 
Ok, but is it working now? Using Invalidate etc.

/Per
[sub]
www.perfnurt.se[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top