capturing the mouse events to draw lines in c++

can any one please submit a C++ program for- capturing the mouse events to draw lines in c++
Programming Windows, 5th edition by Charles Petzold covers this particular application as an example in this worldwide-famous book. Google up to see if you can find it, or buy the book. The book is amazing; you should buy it and read it regardless if you are really serious about Windows programming.

The technique is rather simple:

1. Monitor for WM_LBUTTONDOWN.
2. Capture the mouse using SetCapture().
3. Save the position of the mouse relative to your window; this is usually captured in a static variable like static POINT startingPoint = { 0 };. This is the starting point of the line.
4. Make sure you have the image information ready to re-paint on every WM_MOUSEMOVE.
5. Set a boolean flag indicating the user has started to draw a line. The simplest form of this flag is static bool bDrawingLine = false;.
6. Monitor for WM_MOUSEMOVE. If the boolean flag is set, draw the contents of the window, then draw the potential new line.
7. Monitor for WM_LBUTTONUP. If the boolean flag is set, draw the contents of the window, then draw the now permanent line.
Topic archived. No new replies allowed.