Drawing is slow, so have to try and create the GDIs only once.
We also try to do the drawing offscreen and when finished, post to screen with a paint msg.
If you declare a variable in the callback (and want it to retain the value each msg) you must declare the variable as a static.
I use something like....
Code:
static HDC hdcScr = NULL;
static HBITMAP hbmpScr = NULL, hbmpOrig = NULL;
//WM_CREATE
//create our DC, BMP and set it up
//get the size of the whole screen [GetDeviceCaps() with HORZRES|VERTRES]
//create a mem DC [CreateCompatibleDC( NULL )]
//create a BMP [CreateCompatibleBitmap( memDC)]
//select the BMP into mem DC, catching return [SelectObject]
//fill the DC with a solid colour [FillRect GetStockObject(WHITE_BRUSH)]
//WM_DESTROY
//clean up our DC and BMP
//Select original BMP back into mem DC
//delete comp BMP
//delete mem DC
//WM_PAINT
//draw our mem DC to the paint DC
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
BitBlt(hdc,
ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top, //only redraw the invalid area, not the whole screen.
hdcScr, //from mem DC
ps.rcPaint.left, ps.rcPaint.top, //assuming no offset for the image
SRCCOPY);
EndPaint(hwnd, &ps);
//MSG to draw new line (ie mouse click)
//draw a new line as required
//draw line (you have the code to do this)
//call for a paint msg to draw line to screen
InvalidateRect( hWnd, NULL, FALSE); //redraw whole client area but not background
UpdateWindow( hWnd); //bypass the OS msg queue and send directly tothis callback (is faster)