0
101 Feb 25, 2007 at 04:34

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

#### 7 Replies

0
139 Feb 25, 2007 at 06:28

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?

0
101 Feb 25, 2007 at 13:53

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????

0
101 Feb 25, 2007 at 15:34

0
101 Feb 26, 2007 at 03:42
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;

}

0
139 Feb 26, 2007 at 05:25

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.

0
101 Feb 26, 2007 at 14:17

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.

0
101 Feb 26, 2007 at 14:34

@Reedbeta

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