Changes for multiple window support
[reactos.git] / reactos / apps / tests / multiwin / multiwin.c
1 #include <windows.h>
2 #include <stdio.h>
3
4 static UINT WindowCount;
5 LRESULT WINAPI TopLevelWndProc(HWND, UINT, WPARAM, LPARAM);
6 LRESULT WINAPI ChildWndProc(HWND, UINT, WPARAM, LPARAM);
7
8 int WINAPI
9 WinMain(HINSTANCE hInstance,
10 HINSTANCE hPrevInstance,
11 LPSTR lpszCmdLine,
12 int nCmdShow)
13 {
14 WNDCLASS wc;
15 MSG msg;
16 HWND hWnd1;
17 HWND hWnd2;
18 HWND hWndChild;
19
20 wc.lpszClassName = "TopLevelClass";
21 wc.lpfnWndProc = TopLevelWndProc;
22 wc.style = CS_VREDRAW | CS_HREDRAW;
23 wc.hInstance = hInstance;
24 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
25 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
26 wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
27 wc.lpszMenuName = NULL;
28 wc.cbClsExtra = 0;
29 wc.cbWndExtra = 0;
30 if (RegisterClass(&wc) == 0)
31 {
32 fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
33 GetLastError());
34 return(1);
35 }
36
37 wc.lpszClassName = "ChildClass";
38 wc.lpfnWndProc = ChildWndProc;
39 wc.style = CS_VREDRAW | CS_HREDRAW;
40 wc.hInstance = hInstance;
41 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
42 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
43 wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
44 wc.lpszMenuName = NULL;
45 wc.cbClsExtra = 0;
46 wc.cbWndExtra = 0;
47 if (RegisterClass(&wc) == 0)
48 {
49 fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
50 GetLastError());
51 return(1);
52 }
53
54 hWnd1 = CreateWindow("TopLevelClass",
55 "TopLevel1",
56 WS_OVERLAPPEDWINDOW,
57 0,
58 0,
59 320,
60 240,
61 NULL,
62 NULL,
63 hInstance,
64 NULL);
65
66 hWndChild = CreateWindow("ChildClass",
67 "Child1 of TopLevel1",
68 WS_CHILD | WS_BORDER | WS_CAPTION | WS_VISIBLE | WS_SYSMENU,
69 20,
70 120,
71 200,
72 200,
73 hWnd1,
74 NULL,
75 hInstance,
76 NULL);
77
78 #ifdef TODO
79 hWnd2 = CreateWindow("TopLevelClass",
80 "TopLevel2",
81 WS_OVERLAPPEDWINDOW,
82 400,
83 0,
84 160,
85 120,
86 NULL,
87 NULL,
88 hInstance,
89 NULL);
90 #else
91 hWnd2 = CreateWindow("TopLevelClass",
92 "TopLevel2",
93 WS_OVERLAPPEDWINDOW,
94 400,
95 0,
96 160,
97 490,
98 NULL,
99 NULL,
100 hInstance,
101 NULL);
102 #endif
103
104 if (! hWnd1 || ! hWnd2 || ! hWndChild)
105 {
106 fprintf(stderr, "CreateWindow failed (last error 0x%X)\n",
107 GetLastError());
108 return(1);
109 }
110 WindowCount = 2;
111 ShowWindow(hWnd1, SW_NORMAL);
112 ShowWindow(hWnd2, SW_NORMAL);
113
114 while(GetMessage(&msg, NULL, 0, 0))
115 {
116 TranslateMessage(&msg);
117 DispatchMessage(&msg);
118 }
119 return msg.wParam;
120 }
121
122 LRESULT CALLBACK TopLevelWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
123 {
124 PAINTSTRUCT ps;
125 HDC hDC;
126
127 switch(msg)
128 {
129 case WM_PAINT:
130 hDC = BeginPaint(hWnd, &ps);
131 EndPaint(hWnd, &ps);
132 break;
133
134 case WM_DESTROY:
135 if (0 == --WindowCount)
136 {
137 PostQuitMessage(0);
138 }
139 break;
140
141 default:
142 return DefWindowProc(hWnd, msg, wParam, lParam);
143 }
144
145 return 0;
146 }
147
148 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
149 {
150 PAINTSTRUCT ps;
151 HDC hDC;
152
153 switch(msg)
154 {
155 case WM_PAINT:
156 hDC = BeginPaint(hWnd, &ps);
157 EndPaint(hWnd, &ps);
158 break;
159
160 default:
161 return DefWindowProc(hWnd, msg, wParam, lParam);
162 }
163
164 return 0;
165 }