Visual C++ ONDRAW()- Flickering/Refreshing images drawn by CDC::setpixel()

1
2
3
4
5
for(int y=0; y<=600; y++)
 {
	for(int x=0; x<=600; x++)
	pDC->SetPixel(x,y,RGB(0,255,0));
 }

These codes I have writeeen in a SDI application in the ONDRAW(CDC *pDC) function
This loop runs and draws a rectangle of green colour.
I am facing a problem is that whenever I maximaise, minimise, restore, resize the window the image gets refreshed i.e. ONDRAW() is called on resizing. Also, if say the generated image is large scroll bar doesnot appear to see the complete image say if the window resized to small.
How to avoid it?
I thought of 1 way:
Create and temporary bitmap image using bitmap class in the working directory and show the image.
Can anyone suggest me how to implement it or any sample code. or anyother way to avoid refreshing of images. Also if say i want to save the bmp image any possibility of that
Yes, a message gets sent each time you call one of the max min etc functions to refresh the window. AFAIK it's not something u would want to change...
You should look for an alternative to SetPixel() since this function is known to be very slow and flickery like you described.
If it is a simple rectangle that you want to draw I know there must be some DrawLine() or DrawRect() functions out there that'll do it much more efficiently.
Topic archived. No new replies allowed.