Jump to content


how do i re-paint in win32??


7 replies to this topic

#1 ela

    New Member

  • Members
  • Pip
  • 4 posts

Posted 25 February 2007 - 04:34 AM

hi guys
am a rookie here....just startin with my win32 programming.....i have painted a single pixel in my window using setpixel()....&now i want 2 know how do i re-paint the adjacent pixel every time when i build my application.....???am working in visual studio 2005 ide.
thnkq

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 25 February 2007 - 06:28 AM

If you put the SetPixel call in the message handler for WM_PAINT, it will be drawn whenever the window is displayed...is that what you meant?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 ela

    New Member

  • Members
  • Pip
  • 4 posts

Posted 25 February 2007 - 01:53 PM

yeah thank u.....but i actually wanted to know how to move the pixel horizontally by keeping the y coordinate constant &by varying the x coordinate...for tat purpose if i give x=x+1 in the wm_paint the pixel is not moving...i want the pixel to move horizontally every time when the wm
_paint is being called(the position of the pixel should be incremented everytime)...how do i do tat????

#4 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 25 February 2007 - 03:34 PM

could you please post your wm_paint handler?
My music: http://myspace.com/planetarchh <-- my music

My stuff: torus.untergrund.net <-- some diy electronic stuff and more.

#5 ela

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 February 2007 - 03:42 AM

int x=400;
int y=300;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg1, WPARAM wParam, LPARAM lParam)
{            
             HDC hDC;
    
	switch(msg1)			
{
	case WM_LBUTTONDOWN:
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);				
                          return 0;
	case WM_PAINT:
		HDC hDC;
		PAINTSTRUCT ps;
		hDC =BeginPaint(hwnd, &ps);
		
		{
			SetPixel(hDC,x,y,RGB(255,255,255));
		}	
			
		x=x+1;
		return 0;

	}


#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 26 February 2007 - 05:25 AM

That should work, except for a couple of things:
1. You never call EndPaint. This is the complement to BeginPaint and should be called at the end of the WM_PAINT handler.
2. If you want to force the screen to be continuously redrawn, after your call to EndPaint, insert a call InvalidateRect(hwnd, NULL, false). This tells Windows to "invalidate" your window, meaning it will be immediately redrawn. Putting it in WM_PAINT means the window will be invalidated as soon as it is painted, causing it to be repainted over and over again.

By the way, please use [ code ] [ /code ] tags when posting code. I inserted them for you this time.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 celu

    New Member

  • Members
  • PipPip
  • 20 posts

Posted 26 February 2007 - 02:17 PM

you might want to set the flag in the InvalidateRect() to true if you want to have the appearence of the pixel moving on adjacent frames.If the flag is set to false the last position of the pixel showsup on the next frame and the moving pixel will leave its trial on screen.

#8 ela

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 February 2007 - 02:34 PM

Reedbeta said:

That should work, except for a couple of things:
1. You never call EndPaint. This is the complement to BeginPaint and should be called at the end of the WM_PAINT handler.
2. If you want to force the screen to be continuously redrawn, after your call to EndPaint, insert a call InvalidateRect(hwnd, NULL, false). This tells Windows to "invalidate" your window, meaning it will be immediately redrawn. Putting it in WM_PAINT means the window will be invalidated as soon as it is painted, causing it to be repainted over and over again.

By the way, please use [ code ] [ /code ] tags when posting code. I inserted them for you this time.

thnks a lot reedbeta,you were exactly to the point.i tried it &i got it rite.hey celu even your point was quite useful.i'll get back to you guys if i need anymore clarifications.
thnkq





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users