Problem with WM_PAINT

Hello, for some reason the code is constantly drawing a line upon compiling even though I have created a proper if structure which tells it when to draw or not to draw a line. Basically, I want it to draw a line when the user clicks line from the menu, but for whatever reason, the if statement is always executing and thus a line is almost always drawn when starting the application, can anyone spot where I'm going wrong? I have a class called Lineand inside is a draw function that looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Line::Draw(HDC _hdc)
{
	PAINTSTRUCT ps;
	HPEN hPenOld;
	HPEN hLinePen;
	COLORREF qLineColor;
	qLineColor = RGB(255, 0, 0);
	hLinePen = CreatePen(PS_SOLID, 7, qLineColor);
	hPenOld = (HPEN)SelectObject(_hdc, hLinePen);

	MoveToEx(_hdc, 100, 100, NULL);
	LineTo(_hdc, 500, 250);

	SelectObject(_hdc, hPenOld);
	DeleteObject(hLinePen);
}


and here is the WinMain function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	bool isDrawingLine = false;
	bool isClosed = false;
	int wmID, wmEvent;
	HDC hdc;
	PAINTSTRUCT ps;

	switch (msg)
	{
	case WM_COMMAND:
		wmID = LOWORD(wParam);
		wmEvent = HIWORD(wParam);

		switch (wmID)
		{
		case ID_FILE_EXITPROGRAM:
			isClosed = true;
			break;

		case ID_SHAPES_LINE:
			/sDrawingLine = true;
			break;
		}

		if (isClosed)
		{
		case WM_CLOSE:
			DestroyWindow(hwnd);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		}

		if (isDrawingLine) // This is always executing and I don't know why
		{
		case WM_PAINT:
			Line aLine;
			hdc = BeginPaint(hwnd, &ps);
			aLine.Draw(hdc);
			EndPaint(hwnd, &ps);
			break;
		}
		
Last edited on
That's cause the cases are testing true and control is basically 'bypassing' if you will, the if-statements. Here's a tip, try placing the if statements INSIDE the cases, see if that gives you the desired results.
Topic archived. No new replies allowed.