Oh! I'll post some of my code. I have a draw class which has a virtual function called drawFunc(HWND hwnd) which basically draws the object on Window. There are three base class:
Code:
class drawSPen: public drawClass {
public:
void drawFunc(HWND hwnd);
};
Code:
class drawSEllipse: public drawClass {
public:
void drawFunc(HWND hwnd);
};
And
Code:
class drawSText: public drawClass {
public:
void drawFunc(HWND hwnd);
};
When User selects pen, here's how the program draws it on window:
First the mouse position is kept in POINT variable when mouse left button is down:
Code:
case WM_LBUTTONDOWN:
if (!ConvBitmap) {
LPos.x = LOWORD(lParam);
LPos.y = HIWORD(lParam);
}
break;
ConvBitmap is a bool variable which tells whether the user has selected drawing mode or the bitmap mode. When user selects bitmap mode, user won't be able to draw on window.
Now when user moves the mouse, drawing happens like this:
Code:
case WM_MOUSEMOVE:
if (!ConvBitmap) {
if (wParam == MK_LBUTTON && drawWhat == DRAW_SPEN) {
CPos.x = LOWORD(lParam);
CPos.y = HIWORD(lParam);
PenLine.drawFunc(hwnd);
}
}
break;
drawWhat is global unsigned short int variable. And the value of DRAW_SPEN is defined in resource.h file. CPos is POINT variable to store current mouse coordinates. And PenLine.drawFunc(hwnd) calls the drawFunc(hwnd) from drawSPen class.
Code:
void drawSPen::drawFunc(HWND hwnd) {
HPEN CPen = CreatePen(PS_SOLID, PenSize, PenColor);
hdc = GetDC(hwnd);
SelectObject(hdc, CPen);
MoveToEx(hdc, LPos.x, LPos.y, NULL);
LineTo(hdc, CPos.x, CPos.y);
LPos = CPos;
SelectObject(hdc, DefPen);
DeleteObject(CPen);
ReleaseDC(hwnd, hdc);
}
This is how my program draws stuff on the window and I don't know if this is the right or the wrong way.