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