How to draw a line with the mouse

So the point of the program is when a person left clicks its meant to emulate the line function in paint. Im new to windows programming in general so im open to any suggestions. Here is the code I used.

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
HDC hdc;
	PAINTSTRUCT ps;
	RECT rect;
	int fMouse;
	static int cxMouse,cyMouse, xMouse, yMouse;
	static int cxClient, cyClient;
	switch(message){
		case WM_CREATE:
			if(!(fMouse = GetSystemMetrics(SM_MOUSEPRESENT))){
				MessageBox(hwnd, TEXT("Please install a mouse"), TEXT("ERROR"), MB_OK);
			}

			return 0;
		case WM_SIZE:

			cxClient = LOWORD(lParam);  
			cyClient = HIWORD(lParam);
			SetRect(&rect,0, 0, cxClient,cyClient);
			return 0;
		case WM_MOUSEMOVE:
			cxMouse = LOWORD(lParam);
			cyMouse = HIWORD(lParam);
			if(xMouse != cxMouse || yMouse != cyMouse){
				InvalidateRect(hwnd, &rect, true);
			}
			cxMouse = xMouse;
			cyMouse = yMouse;
			return 0;
		case WM_PAINT:
			hdc = BeginPaint(hwnd, &ps);
			MoveToEx(hdc, xMouse, yMouse, NULL);
			LineTo(hdc, cxMouse, cyMouse);
			EndPaint(hwnd,&ps);
			return 0;
		case WM_LBUTTONDOWN:
			xMouse = LOWORD(lParam);
			yMouse = HIWORD(lParam);
			return 0;
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
	}
Last edited on
Topic archived. No new replies allowed.