i have the following code in a form, i want to do a SetPixel on left mouse click (it must set a red pixel on 10,10). my code is the following:



WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUC
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_LBUTTONDOWN
invoke BeginPaint,hWnd,ADDR ps
mov hdc, eax

invoke SetPixel,hdc,10,10,255

invoke EndPaint,hWnd,ADDR ps
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp


if i change

.ELSEIF uMsg==WM_LBUTTONDOWN

to

.ELSEIF uMsg==WM_PAINT

my code works, but then it executes my code every time and i dont want that because its gona be bigger, is there some other way to do this? do i need to refresh my form or something before it becomes visible?

thnx, Scorpie
Posted on 2004-07-31 12:13:48 by diguin
Hi....


I believe you ...i.e. I didn't do test...

But if really it doesn't work...then try to have this little change---

invoke SetPixel,ps.hdc,10,10,255

i.e. Structure PAINTSTRUC is...

PAINTSTRUCT STRUCT
hdc DWORD ?
fErase DWORD ?
rcPaint RECT <>
fRestore DWORD ?
fIncUpdate DWORD ?
rgbReserved BYTE 32 dup(?)
PAINTSTRUCT ENDS


I hope my help will be welcome for you...

Gerard...
----
Posted on 2004-08-01 02:53:02 by gerard
it gives no error but so did my code, but i still cant see a pixel :(
Posted on 2004-08-01 02:58:30 by diguin
I found...normally one has to use BeginPaint after a call of WM_PAINT ...


Then for your case....

Try to build a Dc then draw pixel then close Dc...

i.e. use following code...

.ELSEIF uMsg==WM_LBUTTONDOWN
invoke GetDC,hwnd
mov hDC,eax
invoke SetPixel,hDC,10,10,255

invoke ReleaseDC,hwnd,hDC


Now it must corectly...I am sure I tested it...

Gerard..
-----
Posted on 2004-08-01 03:35:36 by gerard
thnx :)

gona test it later, gota eat first now

edit: it works, kewl ty

btw i got another question, is it normal to put the painting at wm_paint instead of my methode? (and i mean even if there is some big code that is painting)
Posted on 2004-08-01 03:53:56 by diguin
Painting your window is usually done in WM_PAINT - for normal GUI applications anyway.

Begin+EndPaint should only be used in WM_PAINT - and if you handle WM_PAINT, you really should use those two calls.

Never send a WM_PAINT message manually - use InvalidateRect API call instead.
Posted on 2004-08-01 06:27:43 by f0dder
so if i have a longer painting code its still better to put it in wm_paint ?
Posted on 2004-08-01 07:47:57 by diguin