Hi Guys,
I'm trying to write a simple game of drawing rectangles and circles in a window. I've created a different class for each shape: RectClass and CircClass. Each of these classes has it own DrawShape() function which suppose to draw the shapes in the window with given coordinates argument.
As far as I can tell drawing with GDI is accomplished using the InvalidateRect() function which sends the WM_PAINT message. And when handling the message, depend on some global parameter, you call a specific drawing function. Something like this:
//global parameters
#define DRAW_RECT 1
#define DRAW_CIRC 2
int DrawMode;
//drawing functions of each class - dispatch the WM_PAINT nessage
RectClass::DrawShape(RECT rct)
{
DrawMode = DRAW_RECT;
InvalidateRect(hwnd, &rct, TRUE);
}
CircClass::DrawShape(RECT rct)
{
DrawMode = DRAW_CIRC;
InvalidateRect(hwnd, &rct, TRUE);
}
//in the main file
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
.
.
.
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
switch (DrawMode)
{
case DRAW_RECT:
DrawingARect(hdc, RectClassObj.getCoordinates());
break;
case DRAW_CIRC:
DrawingACircle(hdc, CircClassObj.getCoordinates());
break;
}
EndPaint(hWnd, &ps);
break;
.
.
.
}
}
However if I want to implement my idea like this, I need to use the hwnd handler within the class member functions (as shown in the code above). But the handler is created in the main program file and I do not have access to it in my classes.
Is there another way to draw using GDI with OOP?
Is there a way to get the HWND handle into the classes? I couldn't find a place in the main program to copy a HWND handle to the classes.
Thank you in advance,
GadiK