WM_PAINT

I'm just learning Win32. Went through a couple tutorials and trying my first original program. All I want to do is draw random shapes on the screen. I have a function that initializes random numbers for the shapes whenever the left mouse button is clicked, then the WM_PAINT case in my message loop draws the shapes. Problem is, I have to resize the screen or do something else that causes the WM_PAINT paint message to be sent. Is there a way I can add this message to the queue at the end of my WM_LBUTTONDOWN case?
Post the WM_PAINT section of your code. Are you calling InvalidateRect()?
No, I'm not. Didn't learn anything about that yet. I'll look it up. Meanwhile here's the code:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
case WM_PAINT:
		{
		//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...

		int r,g,b,x1,x2,y1,y2;
		HPEN penold;
		HPEN ellipsepen;
		HPEN linepen;
		COLORREF linecolor;
		COLORREF ellipsecolor;
		int i=1;
		if(numlines>0){
		for(int t=1;t<numlines;++t){
		if(q==1)break;
		//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);	
		
			r=lines.at(i);
			++i;
			g=lines.at(i);
			++i;
			b=lines.at(i);
			++i;
			x1=lines.at(i);
			++i;
			x2=lines.at(i);
			++i;
			y1=lines.at(i);
			++i;
			y2=lines.at(i);
			++i;
			
			linecolor=RGB(r,g,b);
			linepen=CreatePen(PS_SOLID,7,linecolor);
			penold=(HPEN)SelectObject(hdc,linepen);
			MoveToEx(hdc,x1,y1,NULL);
			LineTo(hdc,x2,y2);
			SelectObject(hdc,penold);
			DeleteObject(linepen);
		}		}
		if(numellipses>0){
			i=0;
			for(int t=0;t<numellipses;++t){
			r=lines.at(i);
			++i;
			g=lines.at(i);
			++i;
			b=lines.at(i);
			++i;
			x1=lines.at(i);
			++i;
			x2=lines.at(i);
			++i;
			y1=lines.at(i);
			++i;
			y2=lines.at(i);
			++i;
			
			ellipsecolor=RGB(r,g,b);
			ellipsepen=CreatePen(PS_SOLID,3,ellipsecolor);
			penold=(HPEN)SelectObject(hdc,ellipsepen);
			Arc(hdc,x1,y1,x2,y2,0,0,0,0);
			SelectObject(hdc,penold);
			DeleteObject(ellipsepen);}}
		EndPaint(hWnd, &ps);
		break;  }
ok, thanks a lot, the IvalidateRect() function was exactly what I needed!
Topic archived. No new replies allowed.