I'm trying to write a simple "MSPaintish" program, but I can't handle this one issue.
case WM_LBUTTONDOWN:{
button = true;
//save the start cords and invoke WM_MOUSEMOVE
x1=LOWORD(lParam);
y1=HIWORD(lParam);
SendMessage(hwnd, WM_MOUSEMOVE, wParam, lParam);
break;
}
case WM_LBUTTONUP:{
button=false;
break;
}
case WM_MOUSEMOVE:{
if(button){
HDC hdc=GetDC(hwnd);
HDC hdcmem = CreateCompatibleDC(hdc);
HBITMAP bitmap = CreateCompatibleBitmap(hdc,500,600); // (1)
SelectObject(hdcmem, bitmap);
// save the end cords and draw a line
x2=LOWORD(lParam);
y2=HIWORD(lParam);
DrawMyLine(hdc,x1,y1,x2,y2)
BitBlt(hdc,0,0,500,600,hdcmem,0,0,SRCCOPY);
DeleteDC(hdcmem);
DeleteObject(bitmap);
ReleaseDC(hwnd, hdc);
}
}
What I'm trying to achieve is to draw for example a line using double buffering so I can move the line freely changing it's cords in WM_MOUSEMOVE. The problem is when I try to draw another line obviously the first one that I've draw is gone because I cover the screen once again with the buffer bitmap (1). How can I draw another line that way without erasing what I've done before? It would be great if I could use the existing drawing as a buffer instead of blank bitmap (1), but I'm new to WinAPI and I fail to code it properly. Thanks for any input.