Archived

This topic is now archived and is closed to further replies.

saisoft

Drawing a line(win32)

Recommended Posts

I am trying to draw a line in a window I created with win32. When you hold the left mouse button down and move it, it is supposed to track the mouse and draw a pixel at the appropriate spot. This is part of the code, but the damn thing is not working. Someone please help, thanks. case WM_LBUTTONDOWN: PAINSTRUCT ps; x = LOWORD(lParam); //already declared y = HIWORD(lParam); //already declared BeginPaint(hWnd,&ps); SetPixelV(ps.hdc,x,y,RGB(255,0,0)); EndPain(hWnd,&ps); break; When I hold the Left mouse button down and move it over the window, it does not draw the pixels at the mouse current x,y location on the window.

Share this post


Link to post
Share on other sites
Correct me if I''m wrong someone, but doesn''t WM_LBUTTONDOWN only get sent to the window when the button is first pressed?

You might want to have it track whether it is up or down, and on a WM_MOUSEMOVE draw the pixel. I haven''t used the GDI forever, so I couldn''t check the rest of your code.

Null and Void
It is an inexperienced programmer who speaks of the length of his works.
It is an experienced one who speaks of the briefness.
http://www.crosswinds.net/~druidgames/

Share this post


Link to post
Share on other sites
I have found the solution, in case anyone else falls into this problem here it is:

In all cases, an application can draw in a window as soon as it is created. To draw in the window, the application must first retrieve a handle of a display DC for the window. Ideally, an application carries out most of its drawing operations during the processing of WM_PAINT messages. In this case, the application retrieves a display DC by calling the BeginPaint function. If an application draws at any other time, such as from within WinMain or during processing of keyboard or mouse messages, it calls the GetDC or GetDCEx function to retrieve the display DC.

So i just called GetDC from in side my mouse move and it worked fine.

Share this post


Link to post
Share on other sites