1 /*
2  * comctl32 month calendar unit tests
3  *
4  * Copyright (C) 2006 Vitaliy Margolen
5  * Copyright (C) 2007 Farshad Agah
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #include "precomp.h"
23 
24 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
25 #define expect_hex(expected, got) ok(expected == got, "Expected %x, got %x\n", expected, got);
26 #define expect_d(expected, got) ok(abs((expected) - (got)) <= 2, "Expected %d, got %d\n", expected, got);
27 
28 #define NUM_MSG_SEQUENCES   2
29 #define PARENT_SEQ_INDEX    0
30 #define MONTHCAL_SEQ_INDEX  1
31 
32 #define SEL_NOTIFY_TEST_ID  100
33 
34 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
35 
36 static HWND parent_wnd;
37 
38 static const struct message create_parent_window_seq[] = {
39     { WM_GETMINMAXINFO, sent },
40     { WM_NCCREATE, sent },
41     { WM_NCCALCSIZE, sent|wparam, 0 },
42     { WM_CREATE, sent },
43     { WM_SHOWWINDOW, sent|wparam, 1 },
44     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
45     { WM_QUERYNEWPALETTE, sent|optional },
46     { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
47     { WM_WINDOWPOSCHANGED, sent|optional },
48     { WM_ACTIVATEAPP, sent|wparam, 1 },
49     { WM_NCACTIVATE, sent },
50     { WM_ACTIVATE, sent|wparam, 1 },
51     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
52     { WM_IME_NOTIFY, sent|defwinproc|optional },
53     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
54     /* Win9x adds SWP_NOZORDER below */
55     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
56     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
57     { WM_SIZE, sent },
58     { WM_MOVE, sent },
59     { 0 }
60 };
61 
62 static const struct message create_monthcal_control_seq[] = {
63     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
64     { WM_QUERYUISTATE, sent|optional },
65     { WM_GETFONT, sent },
66     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
67     { 0 }
68 };
69 
70 static const struct message create_monthcal_multi_sel_style_seq[] = {
71     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
72     { WM_QUERYUISTATE, sent|optional },
73     { WM_GETFONT, sent },
74     { WM_PARENTNOTIFY, sent },
75     { 0 }
76 };
77 
78 static const struct message monthcal_curr_date_seq[] = {
79     { MCM_SETCURSEL, sent|wparam, 0},
80     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
81     { MCM_SETCURSEL, sent|wparam, 0},
82     { MCM_SETCURSEL, sent|wparam, 0},
83     { MCM_GETCURSEL, sent|wparam, 0},
84     { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
85     { 0 }
86 };
87 
88 static const struct message monthcal_first_day_seq[] = {
89     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
90 
91     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
92     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
93 
94     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
95     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
96 
97     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
98     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
99 
100     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
101     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
102 
103     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
104     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
105 
106     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
107     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
108 
109     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
110     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
111 
112     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
113     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
114 
115     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
116     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
117 
118     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
119     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
120 
121     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
122     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
123 
124     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
125     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
126 
127     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
128     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
129 
130     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
131     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
132 
133     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
134     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
135 
136     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
137     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
138 
139     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
140     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
141     { 0 }
142 };
143 
144 static const struct message monthcal_unicode_seq[] = {
145     { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
146     { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
147     { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
148     { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
149     { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
150     { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
151     { 0 }
152 };
153 
154 static const struct message monthcal_hit_test_seq[] = {
155     { MCM_SETCURSEL, sent|wparam, 0},
156     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
157     { MCM_HITTEST, sent|wparam, 0},
158     { MCM_HITTEST, sent|wparam, 0},
159     { MCM_HITTEST, sent|wparam, 0},
160     { MCM_HITTEST, sent|wparam, 0},
161     { MCM_HITTEST, sent|wparam, 0},
162     { MCM_HITTEST, sent|wparam, 0},
163     { MCM_HITTEST, sent|wparam, 0},
164     { MCM_HITTEST, sent|wparam, 0},
165     { MCM_HITTEST, sent|wparam, 0},
166     { MCM_HITTEST, sent|wparam, 0},
167     { 0 }
168 };
169 
170 static const struct message monthcal_todaylink_seq[] = {
171     { MCM_HITTEST, sent|wparam, 0},
172     { MCM_SETTODAY, sent|wparam, 0},
173     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
174     { MCM_GETTODAY, sent|wparam, 0},
175     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON},
176     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
177     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
178     { MCM_GETCURSEL, sent|wparam, 0},
179     { 0 }
180 };
181 
182 static const struct message monthcal_today_seq[] = {
183     { MCM_SETTODAY, sent|wparam, 0},
184     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
185     { MCM_GETTODAY, sent|wparam, 0},
186     { MCM_SETTODAY, sent|wparam, 0},
187     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
188     { MCM_GETTODAY, sent|wparam, 0},
189     { 0 }
190 };
191 
192 static const struct message monthcal_scroll_seq[] = {
193     { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
194     { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
195     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
196     { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
197     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
198     { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
199     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
200     { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
201     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
202     { 0 }
203 };
204 
205 static const struct message monthcal_monthrange_seq[] = {
206     { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
207     { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
208     { 0 }
209 };
210 
211 static const struct message monthcal_max_sel_day_seq[] = {
212     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
213     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
214     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
215     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
216     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
217     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
218     { 0 }
219 };
220 
221 /* expected message sequence for parent*/
222 static const struct message destroy_monthcal_parent_msgs_seq[] = {
223     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
224     { 0 }
225 };
226 
227 /* expected message sequence for child*/
228 static const struct message destroy_monthcal_child_msgs_seq[] = {
229     { 0x0090, sent|optional }, /* Vista */
230     { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
231     { WM_WINDOWPOSCHANGING, sent|wparam, 0},
232     { WM_WINDOWPOSCHANGED, sent|wparam, 0},
233     { WM_DESTROY, sent|wparam|lparam, 0, 0},
234     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
235     { 0 }
236 };
237 
238 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
239     { 0x0090, sent|optional }, /* Vista */
240     { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
241     { WM_WINDOWPOSCHANGING, sent|wparam, 0},
242     { WM_WINDOWPOSCHANGED, sent|wparam, 0},
243     { WM_DESTROY, sent|wparam|lparam, 0, 0},
244     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
245     { 0 }
246 };
247 
248 static void test_monthcal(void)
249 {
250     HWND hwnd;
251     SYSTEMTIME st[2], st1[2], today;
252     int res, month_range;
253     DWORD limits;
254     BOOL r;
255 
256     hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
257                          0, 300, 300, 0, 0, NULL, NULL);
258     ok(hwnd != NULL, "Failed to create MonthCal\n");
259 
260     /* test range just after creation */
261     memset(&st, 0xcc, sizeof(st));
262     limits = SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
263     ok(limits == 0 ||
264        broken(limits == GDTR_MIN), /* comctl32 <= 4.70 */
265        "No limits should be set (%d)\n", limits);
266     if (limits == GDTR_MIN)
267     {
268         win_skip("comctl32 <= 4.70 is broken\n");
269         DestroyWindow(hwnd);
270         return;
271     }
272 
273     ok(0 == st[0].wYear ||
274        broken(1752 == st[0].wYear), /* comctl32 <= 4.72 */
275        "Expected 0, got %d\n", st[0].wYear);
276     ok(0 == st[0].wMonth ||
277        broken(9 == st[0].wMonth), /* comctl32 <= 4.72 */
278        "Expected 0, got %d\n", st[0].wMonth);
279     ok(0 == st[0].wDay ||
280        broken(14 == st[0].wDay), /* comctl32 <= 4.72 */
281        "Expected 0, got %d\n", st[0].wDay);
282     expect(0, st[0].wDayOfWeek);
283     expect(0, st[0].wHour);
284     expect(0, st[0].wMinute);
285     expect(0, st[0].wSecond);
286     expect(0, st[0].wMilliseconds);
287 
288     expect(0, st[1].wYear);
289     expect(0, st[1].wMonth);
290     expect(0, st[1].wDay);
291     expect(0, st[1].wDayOfWeek);
292     expect(0, st[1].wHour);
293     expect(0, st[1].wMinute);
294     expect(0, st[1].wSecond);
295     expect(0, st[1].wMilliseconds);
296 
297     limits = SendMessageA(hwnd, MCM_GETRANGE, 0, 0);
298     ok(limits == 0, "got %u\n", limits);
299 
300     GetSystemTime(&st[0]);
301     st[1] = st[0];
302 
303     SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
304 
305     /* Invalid date/time */
306     st[0].wYear  = 2000;
307     /* Time should not matter */
308     st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
309     st[1].wMilliseconds = 1200;
310     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
311     /* invalid timestamp is written back with today data and msecs untouched */
312     expect(today.wHour, st[1].wHour);
313     expect(today.wMinute, st[1].wMinute);
314     expect(today.wSecond, st[1].wSecond);
315     expect(1200, st[1].wMilliseconds);
316 
317     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
318     ok(st1[0].wYear != 2000, "Lower limit changed\n");
319     /* invalid timestamp should be replaced with today data, except msecs */
320     expect(today.wHour, st1[1].wHour);
321     expect(today.wMinute, st1[1].wMinute);
322     expect(today.wSecond, st1[1].wSecond);
323     expect(1200, st1[1].wMilliseconds);
324 
325     /* Invalid date/time with invalid milliseconds only */
326     GetSystemTime(&st[0]);
327     st[1] = st[0];
328     /* Time should not matter */
329     st[1].wMilliseconds = 1200;
330     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
331     /* invalid milliseconds field doesn't lead to invalid timestamp */
332     expect(st[0].wHour,   st[1].wHour);
333     expect(st[0].wMinute, st[1].wMinute);
334     expect(st[0].wSecond, st[1].wSecond);
335     expect(1200, st[1].wMilliseconds);
336 
337     GetSystemTime(&st[0]);
338 
339     st[1].wMonth = 0;
340     ok(!SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
341             "Should have failed to set limits\n");
342     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
343     ok(st1[0].wYear != 2000, "Lower limit changed\n");
344     ok(!SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st),
345             "Should have failed to set MAX limit\n");
346     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
347     ok(st1[0].wYear != 2000, "Lower limit changed\n");
348 
349     GetSystemTime(&st[0]);
350     st[0].wDay = 20;
351     st[0].wMonth = 5;
352     st[1] = st[0];
353 
354     month_range = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
355     st[1].wMonth--;
356     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
357             "Failed to set both min and max limits\n");
358     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
359     ok(res == month_range, "Invalid month range (%d)\n", res);
360     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX),
361             "Limits should be set\n");
362 
363     st[1].wMonth += 2;
364     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
365             "Failed to set both min and max limits\n");
366     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
367     ok(res == month_range, "Invalid month range (%d)\n", res);
368 
369     st[1].wYear --;
370     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
371             "Failed to set both min and max limits\n");
372     st[1].wYear += 1;
373     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
374             "Failed to set both min and max limits\n");
375 
376     st[1].wMonth -= 3;
377     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
378     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX,
379             "Only MAX limit should be set\n");
380     st[1].wMonth += 4;
381     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
382     st[1].wYear -= 3;
383     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
384     st[1].wYear += 4;
385     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
386     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX,
387             "Only MAX limit should be set\n");
388 
389     /* set both limits, then set max < min */
390     GetSystemTime(&st[0]);
391     st[0].wDay = 25;
392     st[1] = st[0];
393     st[1].wYear++;
394     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
395     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX),
396             "Min limit expected\n");
397     st[1].wYear -= 2;
398     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
399     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
400 
401     expect(0, st1[0].wYear);
402     expect(0, st1[0].wMonth);
403     expect(0, st1[0].wDay);
404     expect(0, st1[0].wDayOfWeek);
405     expect(0, st1[0].wHour);
406     expect(0, st1[0].wMinute);
407     expect(0, st1[0].wSecond);
408     expect(0, st1[0].wMilliseconds);
409 
410     expect(st[1].wYear,      st1[1].wYear);
411     expect(st[1].wMonth,     st1[1].wMonth);
412     expect(st[1].wDay,       st1[1].wDay);
413     expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
414     expect(st[1].wHour,      st1[1].wHour);
415     expect(st[1].wMinute,    st1[1].wMinute);
416     expect(st[1].wSecond,    st1[1].wSecond);
417     expect(st[1].wMilliseconds, st1[1].wMilliseconds);
418 
419     st[1] = st[0];
420     st[1].wYear++;
421     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
422     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX),
423             "Min limit expected\n");
424     st[0].wYear++; /* start == end now */
425     ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
426     ok(SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
427 
428     expect(st[0].wYear,      st1[0].wYear);
429     expect(st[0].wMonth,     st1[0].wMonth);
430     expect(st[0].wDay,       st1[0].wDay);
431     expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
432     expect(st[0].wHour,      st1[0].wHour);
433     expect(st[0].wMinute,    st1[0].wMinute);
434     expect(st[0].wSecond,    st1[0].wSecond);
435     expect(st[0].wMilliseconds, st1[0].wMilliseconds);
436 
437     expect(0, st1[1].wYear);
438     expect(0, st1[1].wMonth);
439     expect(0, st1[1].wDay);
440     expect(0, st1[1].wDayOfWeek);
441     expect(0, st1[1].wHour);
442     expect(0, st1[1].wMinute);
443     expect(0, st1[1].wSecond);
444     expect(0, st1[1].wMilliseconds);
445 
446     /* 0 limit flags */
447     limits = SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1);
448     ok(limits == GDTR_MIN, "got 0x%08x\n", limits);
449 
450     GetSystemTime(st);
451     st[1] = st[0];
452     st[1].wYear++;
453     r = SendMessageA(hwnd, MCM_SETRANGE, 0, (LPARAM)st);
454     ok(r, "got %d\n", r);
455 
456     limits = SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
457     ok(limits == 0, "got 0x%08x\n", limits);
458     ok(st[0].wYear == 0 && st[1].wYear == 0, "got %u, %u\n", st[0].wYear, st[1].wYear);
459 
460     /* flags are 0, set min limit */
461     GetSystemTime(st);
462     st[1] = st[0];
463     st[1].wYear++;
464 
465     r = SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st);
466     ok(r, "got %d\n", r);
467 
468     limits = SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1);
469     ok(limits == GDTR_MIN, "got 0x%08x\n", limits);
470     ok(st1[1].wYear == 0, "got %u\n", st1[1].wYear);
471 
472     /* now set max limit, check flags */
473     r = SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st);
474     ok(r, "got %d\n", r);
475 
476     limits = SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st1);
477     ok(limits == GDTR_MAX, "got 0x%08x\n", limits);
478     ok(st1[0].wYear == 0, "got %u\n", st1[0].wYear);
479 
480     DestroyWindow(hwnd);
481 }
482 
483 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
484 {
485     static LONG defwndproc_counter = 0;
486     LRESULT ret;
487     struct message msg;
488 
489     /* log system messages, except for painting */
490     if (message < WM_USER &&
491         message != WM_PAINT &&
492         message != WM_ERASEBKGND &&
493         message != WM_NCPAINT &&
494         message != WM_NCHITTEST &&
495         message != WM_GETTEXT &&
496         message != WM_GETICON &&
497         message != WM_DEVICECHANGE)
498     {
499         msg.message = message;
500         msg.flags = sent|wparam|lparam;
501         if (defwndproc_counter) msg.flags |= defwinproc;
502         msg.wParam = wParam;
503         msg.lParam = lParam;
504         add_message(sequences, PARENT_SEQ_INDEX, &msg);
505     }
506 
507     if (message == WM_NOTIFY)
508     {
509         NMHDR *hdr = (NMHDR*)lParam;
510         switch (hdr->code)
511         {
512           case MCN_GETDAYSTATE:
513           {
514             NMDAYSTATE *nmstate = (NMDAYSTATE*)lParam;
515             static MONTHDAYSTATE months[14] = { 0 };
516 
517             ok(nmstate->cDayState > 0, "got %d\n", nmstate->cDayState);
518             ok(nmstate->cDayState <= 14, "got %d\n", nmstate->cDayState);
519             ok(nmstate->prgDayState != NULL, "got %p\n", nmstate->prgDayState);
520 
521             nmstate->prgDayState = months;
522 
523             return TRUE;
524           }
525           case MCN_SELECT:
526           case MCN_SELCHANGE:
527           {
528             NMSELCHANGE *nmchg = (NMSELCHANGE*)lParam;
529             SYSTEMTIME st[2];
530             BOOL is_multisel = GetWindowLongPtrA(nmchg->nmhdr.hwndFrom, GWL_STYLE) & MCS_MULTISELECT;
531 
532             if(GetWindowLongPtrA(nmchg->nmhdr.hwndFrom, GWLP_ID) != SEL_NOTIFY_TEST_ID)
533               break;
534             SendMessageA(nmchg->nmhdr.hwndFrom, is_multisel ? MCM_GETSELRANGE : MCM_GETCURSEL,
535                     0, (LPARAM)st);
536 
537             expect(st[0].wYear,  nmchg->stSelStart.wYear);
538             expect(st[0].wMonth, nmchg->stSelStart.wMonth);
539             expect(0,            nmchg->stSelStart.wDayOfWeek);
540             expect(st[0].wDay,   nmchg->stSelStart.wDay);
541 
542             if(is_multisel)
543             {
544               expect(st[1].wYear,  nmchg->stSelEnd.wYear);
545               expect(st[1].wMonth, nmchg->stSelEnd.wMonth);
546               expect(0,            nmchg->stSelEnd.wDayOfWeek);
547               expect(st[1].wDay,   nmchg->stSelEnd.wDay);
548             }
549             else
550               ok(!(nmchg->stSelEnd.wYear | nmchg->stSelEnd.wMonth |
551                         nmchg->stSelEnd.wDayOfWeek | nmchg->stSelEnd.wDay |
552                         nmchg->stSelEnd.wHour | nmchg->stSelEnd.wMinute |
553                         nmchg->stSelEnd.wSecond | nmchg->stSelEnd.wMilliseconds),
554                         "Non-zero member in stSelEnd\n");
555             return TRUE;
556           }
557           default:
558             break;
559         }
560     }
561 
562     defwndproc_counter++;
563     ret = DefWindowProcA(hwnd, message, wParam, lParam);
564     defwndproc_counter--;
565 
566     return ret;
567 }
568 
569 static BOOL register_parent_wnd_class(void)
570 {
571     WNDCLASSA cls;
572 
573     cls.style = 0;
574     cls.lpfnWndProc = parent_wnd_proc;
575     cls.cbClsExtra = 0;
576     cls.cbWndExtra = 0;
577     cls.hInstance = GetModuleHandleA(NULL);
578     cls.hIcon = 0;
579     cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
580     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
581     cls.lpszMenuName = NULL;
582     cls.lpszClassName = "Month-Cal test parent class";
583     return RegisterClassA(&cls);
584 }
585 
586 static HWND create_parent_window(void)
587 {
588     HWND hwnd;
589 
590     InitCommonControls();
591 
592     /* flush message sequences, so we can check the new sequence by the end of function */
593     flush_sequences(sequences, NUM_MSG_SEQUENCES);
594 
595     if (!register_parent_wnd_class())
596         return NULL;
597 
598     hwnd = CreateWindowExA(0, "Month-Cal test parent class", "Month-Cal test parent window",
599             WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE,
600             0, 0, 500, 500, GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
601     ok(hwnd != NULL, "failed to create parent wnd\n");
602 
603     /* check for message sequences */
604     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
605 
606     return hwnd;
607 }
608 
609 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
610 {
611     WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
612     static LONG defwndproc_counter = 0;
613     struct message msg = { 0 };
614     LRESULT ret;
615 
616     msg.message = message;
617     msg.flags = sent|wparam|lparam;
618     if (defwndproc_counter) msg.flags |= defwinproc;
619     msg.wParam = wParam;
620     msg.lParam = lParam;
621     add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
622 
623     /* some debug output for style changing */
624     if ((message == WM_STYLECHANGING ||
625          message == WM_STYLECHANGED) && lParam)
626     {
627         STYLESTRUCT *style = (STYLESTRUCT*)lParam;
628         trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
629     }
630 
631     defwndproc_counter++;
632     ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
633     defwndproc_counter--;
634 
635     return ret;
636 }
637 
638 static HWND create_monthcal_control(DWORD style)
639 {
640     WNDPROC oldproc;
641     RECT rect;
642     HWND hwnd;
643     BOOL ret;
644 
645     hwnd = CreateWindowExA(0, MONTHCAL_CLASSA, "", WS_CHILD | WS_BORDER | WS_VISIBLE | style,
646                     0, 0, 300, 400, parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
647     ok(hwnd != NULL, "failed to create monthcal wnd\n");
648     if (!hwnd) return NULL;
649 
650     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
651                                         (LONG_PTR)monthcal_subclass_proc);
652     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
653 
654     SendMessageA(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
655 
656     /* make sure calendar grid is 2x1 */
657     ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&rect);
658     ok(ret, "got %d\n", ret);
659 
660     ret = SetWindowPos(hwnd, NULL, 0, 0, rect.right * 5 / 2, rect.bottom * 3 / 2, SWP_NOMOVE);
661     ok(ret, "got %d\n", ret);
662 
663     return hwnd;
664 }
665 
666 
667 /* Setter and Getters Tests */
668 
669 static void test_color(void)
670 {
671     COLORREF color, prev;
672     HWND hwnd;
673 
674     hwnd = create_monthcal_control(0);
675 
676     /* invalid color index */
677     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
678     expect(~0u, color);
679     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
680     expect(~0u, prev);
681 
682     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
683     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
684     expect(color, prev);
685     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
686     expect(RGB(0,0,0), color);
687     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
688     expect(color, prev);
689     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
690     expect(RGB(255,255,255), color);
691 
692     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
693     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
694     expect(color, prev);
695     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
696     expect(RGB(0,0,0), color);
697     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
698     expect(color, prev);
699     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
700     expect(RGB(255,255,255), color);
701 
702     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
703     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
704     expect(color, prev);
705     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
706     expect(RGB(0,0,0), color);
707     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
708     expect(color, prev);
709     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
710     expect(RGB(255,255,255), color);
711 
712     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
713     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
714     expect(color, prev);
715     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
716     expect(RGB(0,0,0), color);
717     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
718     expect(color, prev);
719     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
720     expect(RGB(255,255,255), color);
721 
722     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
723     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
724     expect(color, prev);
725     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
726     expect(RGB(0,0,0), color);
727     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
728     expect(color, prev);
729     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
730     expect(RGB(255,255,255), color);
731 
732     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
733     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
734     expect(color, prev);
735     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
736     expect(RGB(0,0,0), color);
737     prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
738     expect(color, prev);
739     color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
740     expect(RGB(255,255,255), color);
741 
742     DestroyWindow(hwnd);
743 }
744 
745 static void test_currdate(void)
746 {
747     SYSTEMTIME st_original, st_new, st_test;
748     int res;
749     HWND hwnd;
750 
751     hwnd = create_monthcal_control(0);
752 
753     flush_sequences(sequences, NUM_MSG_SEQUENCES);
754 
755     /* Setter and Getters for current date selected */
756     st_original.wYear = 2000;
757     st_original.wMonth = 11;
758     st_original.wDay = 28;
759     st_original.wHour = 11;
760     st_original.wMinute = 59;
761     st_original.wSecond = 30;
762     st_original.wMilliseconds = 0;
763     st_original.wDayOfWeek = 0;
764 
765     st_new = st_test = st_original;
766 
767     /* Should not validate the time */
768     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
769     expect(1,res);
770 
771     /* Overflow matters, check for wDay */
772     st_test.wDay += 4;
773     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
774     expect(0,res);
775 
776     /* correct wDay before checking for wMonth */
777     st_test.wDay -= 4;
778     expect(st_original.wDay, st_test.wDay);
779 
780     /* Overflow matters, check for wMonth */
781     st_test.wMonth += 4;
782     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
783     expect(0,res);
784 
785     /* checking if gets the information right, modify st_new */
786     st_new.wYear += 4;
787     st_new.wMonth += 4;
788     st_new.wDay += 4;
789     st_new.wHour += 4;
790     st_new.wMinute += 4;
791     st_new.wSecond += 4;
792 
793     res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
794     expect(1, res);
795 
796     /* st_new change to st_origin, above settings with overflow */
797     /* should not change the current settings */
798     expect(st_original.wYear, st_new.wYear);
799     expect(st_original.wMonth, st_new.wMonth);
800     expect(st_original.wDay, st_new.wDay);
801     ok(st_original.wHour == st_new.wHour ||
802        broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
803        "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
804     ok(st_original.wMinute == st_new.wMinute ||
805        broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
806        "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
807     ok(st_original.wSecond == st_new.wSecond ||
808        broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
809        "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
810 
811     /* lparam cannot be NULL */
812     res = SendMessageA(hwnd, MCM_GETCURSEL, 0, 0);
813     expect(0, res);
814 
815     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
816 
817     /* December, 31, 9999 is the maximum allowed date */
818     memset(&st_new, 0, sizeof(st_new));
819     st_new.wYear = 9999;
820     st_new.wMonth = 12;
821     st_new.wDay = 31;
822     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
823     expect(1, res);
824     memset(&st_test, 0, sizeof(st_test));
825     res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
826     expect(1, res);
827     expect(st_new.wYear, st_test.wYear);
828     expect(st_new.wMonth, st_test.wMonth);
829     expect(st_new.wDay, st_test.wDay);
830     expect(st_new.wHour, st_test.wHour);
831     expect(st_new.wMinute, st_test.wMinute);
832     expect(st_new.wSecond, st_test.wSecond);
833     /* try one day later */
834     st_original = st_new;
835     st_new.wYear = 10000;
836     st_new.wMonth = 1;
837     st_new.wDay = 1;
838     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
839     ok(0 == res ||
840        broken(1 == res), /* comctl32 <= 4.72 */
841        "Expected 0, got %d\n", res);
842     if (0 == res)
843     {
844         memset(&st_test, 0, sizeof(st_test));
845         res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
846         expect(1, res);
847         expect(st_original.wYear, st_test.wYear);
848         expect(st_original.wMonth, st_test.wMonth);
849         expect(st_original.wDay, st_test.wDay);
850         expect(st_original.wHour, st_test.wHour);
851         expect(st_original.wMinute, st_test.wMinute);
852         expect(st_original.wSecond, st_test.wSecond);
853     }
854 
855     /* setting selection equal to current reports success even if out range */
856     memset(&st_new, 0, sizeof(st_new));
857     st_new.wYear = 2009;
858     st_new.wDay  = 5;
859     st_new.wMonth = 10;
860     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
861     expect(1, res);
862     memset(&st_test, 0, sizeof(st_test));
863     st_test.wYear = 2009;
864     st_test.wDay  = 6;
865     st_test.wMonth = 10;
866     res = SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
867     expect(1, res);
868     /* set to current again */
869     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
870     expect(1, res);
871 
872     /* set with invalid day of week */
873     memset(&st_test, 0, sizeof(st_test));
874     st_test.wYear = 2009;
875     st_test.wDay  = 7;
876     st_test.wMonth = 10;
877     st_test.wDayOfWeek = 100;
878     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
879     expect(1, res);
880 
881     memset(&st_test, 0, sizeof(st_test));
882     res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
883     expect(1, res);
884     expect(2009, st_test.wYear);
885     expect(7, st_test.wDay);
886     expect(10, st_test.wMonth);
887     expect(3, st_test.wDayOfWeek);
888 
889     DestroyWindow(hwnd);
890 }
891 
892 static void test_firstDay(void)
893 {
894     int res, fday, i, prev;
895     CHAR b[128], caltype[3];
896     LCID lcid = LOCALE_USER_DEFAULT;
897     HWND hwnd;
898     LRESULT ret;
899 
900     SetLastError(0xdeadbeef);
901     ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
902     if (ret == 0) {
903         skip("Must know local calendar type (%x)\n", GetLastError());
904         return;
905     } else if (atoi(caltype) != CAL_GREGORIAN) {
906         skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
907         return;
908     }
909 
910     hwnd = create_monthcal_control(0);
911 
912     flush_sequences(sequences, NUM_MSG_SEQUENCES);
913 
914     /* Setter and Getters for first day of week */
915     /* check for locale first day */
916     if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
917         fday = atoi(b);
918         res = SendMessageA(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
919         expect(fday, res);
920         prev = fday;
921 
922         /* checking for the values that actually will be stored as */
923         /* current first day when we set a new value */
924         for (i = -5; i < 12; i++){
925             res = SendMessageA(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, i);
926             expect(prev, res);
927             res = SendMessageA(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
928             prev = res;
929 
930             if (i == -1){
931                 expect(MAKELONG(fday, FALSE), res);
932             }else if (i >= 7){
933                 /* out of range sets max first day of week, locale is ignored */
934                 expect(MAKELONG(6, TRUE), res);
935             }else{
936                 expect(MAKELONG(i, TRUE), res);
937             }
938         }
939 
940         ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
941 
942     }else{
943         skip("Cannot retrieve first day of the week\n");
944     }
945 
946     DestroyWindow(hwnd);
947 }
948 
949 static void test_unicode(void)
950 {
951     int res, temp;
952     HWND hwnd;
953 
954     hwnd = create_monthcal_control(0);
955 
956     flush_sequences(sequences, NUM_MSG_SEQUENCES);
957 
958     /* Setter and Getters for Unicode format */
959 
960     /* getting the current settings */
961     temp = SendMessageA(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
962 
963     /* setting to 1, should return previous settings */
964     res = SendMessageA(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
965     expect(temp, res);
966 
967     /* current setting is 1, so, should return 1 */
968     res = SendMessageA(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
969     ok(1 == res ||
970        broken(0 == res), /* comctl32 <= 4.70 */
971        "Expected 1, got %d\n", res);
972 
973     /* setting to 0, should return previous settings */
974     res = SendMessageA(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
975     ok(1 == res ||
976        broken(0 == res), /* comctl32 <= 4.70 */
977        "Expected 1, got %d\n", res);
978 
979     /* current setting is 0, so, it should return 0 */
980     res = SendMessageA(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
981     expect(0, res);
982 
983     /* should return previous settings */
984     res = SendMessageA(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
985     expect(0, res);
986 
987     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
988 
989     DestroyWindow(hwnd);
990 }
991 
992 static void test_hittest(void)
993 {
994     typedef struct hittest_test
995     {
996 	UINT ht;
997         BOOL  todo;
998     } hittest_test_t;
999 
1000     static const hittest_test_t title_hits[] = {
1001         /* Start is the same everywhere */
1002         { MCHT_TITLE,        FALSE },
1003         { MCHT_TITLEBTNPREV, FALSE },
1004         /* The middle piece is only tested for presence of items */
1005         /* End is the same everywhere */
1006         { MCHT_TITLEBTNNEXT, FALSE },
1007         { MCHT_TITLE,        FALSE },
1008         { MCHT_NOWHERE,      TRUE }
1009     };
1010 
1011     MCHITTESTINFO mchit;
1012     UINT res, old_res;
1013     SYSTEMTIME st;
1014     LONG x;
1015     UINT title_index;
1016     HWND hwnd;
1017     RECT r;
1018     char yearmonth[80], *locale_month, *locale_year;
1019     int month_count, year_count;
1020     BOOL in_the_middle;
1021 
1022     memset(&mchit, 0, sizeof(MCHITTESTINFO));
1023 
1024     hwnd = create_monthcal_control(0);
1025 
1026     /* test with invalid structure size */
1027     mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
1028     mchit.pt.x = 0;
1029     mchit.pt.y = 0;
1030     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1031     expect(0, mchit.pt.x);
1032     expect(0, mchit.pt.y);
1033     expect(~0u, res);
1034     expect(0, mchit.uHit);
1035     /* test with invalid pointer */
1036     res = SendMessageA(hwnd, MCM_HITTEST, 0, 0);
1037     expect(~0u, res);
1038 
1039     /* resize control to display single Calendar */
1040     res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1041     if (res == 0)
1042     {
1043         win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1044         DestroyWindow(hwnd);
1045         return;
1046     }
1047     MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1048 
1049     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1050 
1051     st.wYear = 2007;
1052     st.wMonth = 4;
1053     st.wDay = 11;
1054     st.wHour = 1;
1055     st.wMinute = 0;
1056     st.wSecond = 0;
1057     st.wMilliseconds = 0;
1058     st.wDayOfWeek = 0;
1059 
1060     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1061     expect(1,res);
1062 
1063     /* (0, 0) is the top left of the control - title */
1064     mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1065     mchit.pt.x = 0;
1066     mchit.pt.y = 0;
1067     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1068     expect(0, mchit.pt.x);
1069     expect(0, mchit.pt.y);
1070     expect(mchit.uHit, res);
1071     expect_hex(MCHT_TITLE, res);
1072 
1073     /* bottom right of the control and should not be active */
1074     mchit.pt.x = r.right;
1075     mchit.pt.y = r.bottom;
1076     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1077     expect(r.right,  mchit.pt.x);
1078     expect(r.bottom, mchit.pt.y);
1079     expect(mchit.uHit, res);
1080     todo_wine expect_hex(MCHT_NOWHERE, res);
1081 
1082     /* completely out of the control, should not be active */
1083     mchit.pt.x = 2 * r.right;
1084     mchit.pt.y = 2 * r.bottom;
1085     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1086     expect(2 * r.right, mchit.pt.x);
1087     expect(2 * r.bottom, mchit.pt.y);
1088     expect(mchit.uHit, res);
1089     todo_wine expect_hex(MCHT_NOWHERE, res);
1090 
1091     /* in active area - day of the week */
1092     mchit.pt.x = r.right / 2;
1093     mchit.pt.y = r.bottom / 2;
1094     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1095     expect(r.right / 2, mchit.pt.x);
1096     expect(r.bottom / 2, mchit.pt.y);
1097     expect(mchit.uHit, res);
1098     expect_hex(MCHT_CALENDARDATE, res);
1099 
1100     /* in active area - day of the week #2 */
1101     mchit.pt.x = r.right / 14; /* half of first day rect */
1102     mchit.pt.y = r.bottom / 2;
1103     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1104     expect(r.right / 14, mchit.pt.x);
1105     expect(r.bottom / 2, mchit.pt.y);
1106     expect(mchit.uHit, res);
1107     expect_hex(MCHT_CALENDARDATE, res);
1108 
1109     /* in active area - date from prev month */
1110     mchit.pt.x = r.right / 14; /* half of first day rect */
1111     mchit.pt.y = 6 * r.bottom / 19;
1112     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1113     expect(r.right / 14, mchit.pt.x);
1114     expect(6 * r.bottom / 19, mchit.pt.y);
1115     expect(mchit.uHit, res);
1116     expect_hex(MCHT_CALENDARDATEPREV, res);
1117 
1118 if (0)
1119 {
1120     /* (125, 115) is in active area - date from this month */
1121     mchit.pt.x = 125;
1122     mchit.pt.y = 115;
1123     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1124     expect(125, mchit.pt.x);
1125     expect(115, mchit.pt.y);
1126     expect(mchit.uHit, res);
1127     expect(MCHT_CALENDARDATE, res);
1128 }
1129 
1130     /* in active area - date from next month */
1131     mchit.pt.x = 11 * r.right / 14;
1132     mchit.pt.y = 16 * r.bottom / 19;
1133     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1134     expect(11 * r.right / 14, mchit.pt.x);
1135     expect(16 * r.bottom / 19, mchit.pt.y);
1136     expect(mchit.uHit, res);
1137     expect_hex(MCHT_CALENDARDATENEXT, res);
1138 
1139     /* in active area - today link */
1140     mchit.pt.x = r.right / 14;
1141     mchit.pt.y = 18 * r.bottom / 19;
1142     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1143     expect(r.right / 14, mchit.pt.x);
1144     expect(18 * r.bottom / 19, mchit.pt.y);
1145     expect(mchit.uHit, res);
1146     expect_hex(MCHT_TODAYLINK, res);
1147 
1148     /* in active area - today link */
1149     mchit.pt.x = r.right / 2;
1150     mchit.pt.y = 18 * r.bottom / 19;
1151     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1152     expect(r.right / 2, mchit.pt.x);
1153     expect(18 * r.bottom / 19, mchit.pt.y);
1154     expect(mchit.uHit, res);
1155     expect_hex(MCHT_TODAYLINK, res);
1156 
1157     /* in active area - today link */
1158     mchit.pt.x = r.right / 10;
1159     mchit.pt.y = 18 * r.bottom / 19;
1160     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1161     expect(r.right / 10, mchit.pt.x);
1162     expect(18 * r.bottom / 19, mchit.pt.y);
1163     expect(mchit.uHit, res);
1164     expect_hex(MCHT_TODAYLINK, res);
1165 
1166     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1167 
1168     /* The horizontal position of title bar elements depends on locale (y pos
1169        is constant), so we sample across a horizontal line and make sure we
1170        find all elements. */
1171 
1172     /* Get the format of the title */
1173     GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1174     /* Find out if we have a month and/or year */
1175     locale_year = strstr(yearmonth, "y");
1176     locale_month = strstr(yearmonth, "M");
1177 
1178     mchit.pt.x = 0;
1179     mchit.pt.y = (5/2) * r.bottom / 19;
1180     title_index = 0;
1181     old_res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1182     expect_hex(title_hits[title_index].ht, old_res);
1183 
1184     in_the_middle = FALSE;
1185     month_count = year_count = 0;
1186     for (x = 0; x < r.right; x++){
1187         mchit.pt.x = x;
1188         res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1189         expect(x, mchit.pt.x);
1190         expect((5/2) * r.bottom / 19, mchit.pt.y);
1191         expect(mchit.uHit, res);
1192         if (res != old_res) {
1193 
1194             if (old_res == MCHT_TITLEBTNPREV)
1195                 in_the_middle = TRUE;
1196 
1197             if (res == MCHT_TITLEBTNNEXT)
1198                 in_the_middle = FALSE;
1199 
1200             if (in_the_middle) {
1201                 if (res == MCHT_TITLEMONTH)
1202                     month_count++;
1203                 else if (res == MCHT_TITLEYEAR)
1204                     year_count++;
1205             } else {
1206                 title_index++;
1207 
1208                 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1209                     break;
1210 
1211                 todo_wine_if(title_hits[title_index].todo)
1212                     ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1213                                                           title_hits[title_index].ht, res, x);
1214             }
1215             old_res = res;
1216         }
1217     }
1218 
1219     /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1220      * or no month/year indicators at all */
1221     if (locale_month)
1222         todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1223     else
1224         ok(month_count <= 1, "Too many month items: %d\n", month_count);
1225 
1226     if (locale_year)
1227         todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1228     else
1229         ok(year_count <= 1, "Too many year items: %d\n", year_count);
1230 
1231     todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1232 
1233     ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1234        "Wrong title layout\n");
1235 
1236     DestroyWindow(hwnd);
1237 }
1238 
1239 static void test_todaylink(void)
1240 {
1241     MCHITTESTINFO mchit;
1242     SYSTEMTIME st_test, st_new;
1243     UINT res;
1244     HWND hwnd;
1245     RECT r;
1246 
1247     memset(&mchit, 0, sizeof(MCHITTESTINFO));
1248 
1249     hwnd = create_monthcal_control(0);
1250 
1251     res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1252     expect(1, res);
1253     MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1254 
1255     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1256 
1257     /* hit active area - today link */
1258     mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1259     mchit.pt.x = r.right / 14;
1260     mchit.pt.y = 18 * r.bottom / 19;
1261     res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1262     expect(r.right / 14, mchit.pt.x);
1263     expect(18 * r.bottom / 19, mchit.pt.y);
1264     expect(mchit.uHit, res);
1265     expect(MCHT_TODAYLINK, res);
1266 
1267     st_test.wDay = 1;
1268     st_test.wMonth = 1;
1269     st_test.wYear = 2005;
1270 
1271     res = SendMessageA(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1272     expect(0, res);
1273 
1274     memset(&st_new, 0, sizeof(st_new));
1275     res = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1276     expect(1, res);
1277     expect(1, st_new.wDay);
1278     expect(1, st_new.wMonth);
1279     expect(2005, st_new.wYear);
1280 
1281     res = SendMessageA(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1282     expect(0, res);
1283 
1284     memset(&st_new, 0, sizeof(st_new));
1285     res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1286     expect(1, res);
1287     expect(1, st_new.wDay);
1288     expect(1, st_new.wMonth);
1289     expect(2005, st_new.wYear);
1290 
1291     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1292 
1293     DestroyWindow(hwnd);
1294 }
1295 
1296 static void test_today(void)
1297 {
1298     SYSTEMTIME st_test, st_new;
1299     int res;
1300     HWND hwnd;
1301 
1302     hwnd = create_monthcal_control(0);
1303 
1304     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1305 
1306     /* Setter and Getters for "today" information */
1307 
1308     /* check for overflow, should be ok */
1309     memset(&st_test, 0, sizeof(st_test));
1310     st_test.wDay = 38;
1311     st_test.wMonth = 38;
1312 
1313     st_new.wDay = 27;
1314     st_new.wMonth = 27;
1315 
1316     res = SendMessageA(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1317     expect(0, res);
1318 
1319     res = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1320     expect(1, res);
1321 
1322     /* st_test should not change */
1323     expect(38, st_test.wDay);
1324     expect(38, st_test.wMonth);
1325 
1326     /* st_new should change, overflow does not matter */
1327     expect(38, st_new.wDay);
1328     expect(38, st_new.wMonth);
1329 
1330     /* check for zero, should be ok*/
1331     st_test.wDay = 0;
1332     st_test.wMonth = 0;
1333 
1334     res = SendMessageA(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1335     expect(0, res);
1336 
1337     res = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1338     expect(1, res);
1339 
1340     /* st_test should not change */
1341     expect(0, st_test.wDay);
1342     expect(0, st_test.wMonth);
1343 
1344     /* st_new should change to zero*/
1345     expect(0, st_new.wDay);
1346     expect(0, st_new.wMonth);
1347 
1348     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1349 
1350     DestroyWindow(hwnd);
1351 }
1352 
1353 static void test_scroll(void)
1354 {
1355     int res;
1356     HWND hwnd;
1357 
1358     hwnd = create_monthcal_control(0);
1359 
1360     res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1361     expect(2, res);
1362 
1363     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1364 
1365     /* Setter and Getters for scroll rate */
1366     res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 2, 0);
1367     expect(0, res);
1368 
1369     res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 3, 0);
1370     expect(2, res);
1371     res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1372     expect(3, res);
1373 
1374     res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 12, 0);
1375     expect(3, res);
1376     res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1377     expect(12, res);
1378 
1379     res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 15, 0);
1380     expect(12, res);
1381     res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1382     expect(15, res);
1383 
1384     res = SendMessageA(hwnd, MCM_SETMONTHDELTA, -5, 0);
1385     expect(15, res);
1386     res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1387     expect(-5, res);
1388 
1389     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1390 
1391     DestroyWindow(hwnd);
1392 }
1393 
1394 static void test_monthrange(void)
1395 {
1396     int res;
1397     SYSTEMTIME st_visible[2], st_daystate[2], st;
1398     HWND hwnd;
1399     RECT r;
1400 
1401     hwnd = create_monthcal_control(0);
1402 
1403     memset(&st_visible, 0, sizeof(st_visible));
1404     memset(&st_daystate, 0, sizeof(st_daystate));
1405 
1406     st.wYear = 2000;
1407     st.wMonth = 11;
1408     st.wDay = 28;
1409     st.wHour = 11;
1410     st.wMinute = 59;
1411     st.wSecond = 30;
1412     st.wMilliseconds = 0;
1413     st.wDayOfWeek = 0;
1414 
1415     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1416     expect(1,res);
1417 
1418     /* to be locale independent */
1419     SendMessageA(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1420 
1421     res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1422     expect(TRUE, res);
1423     /* resize control to display two Calendars */
1424     MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1425 
1426     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1427 
1428     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1429     expect(2, res);
1430     expect(2000, st_visible[0].wYear);
1431     expect(11, st_visible[0].wMonth);
1432     expect(1, st_visible[0].wDay);
1433     expect(2000, st_visible[1].wYear);
1434     expect(12, st_visible[1].wMonth);
1435     expect(31, st_visible[1].wDay);
1436 
1437     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1438     expect(4, res);
1439     expect(2000, st_daystate[0].wYear);
1440     expect(10, st_daystate[0].wMonth);
1441     expect(29, st_daystate[0].wDay);
1442     expect(2001, st_daystate[1].wYear);
1443     expect(1, st_daystate[1].wMonth);
1444     expect(6, st_daystate[1].wDay);
1445 
1446     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1447 
1448     /* with null date array parameter */
1449     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1450     expect(2, res);
1451 
1452     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1453     expect(4, res);
1454 
1455     /* resize control to display single Calendar */
1456     MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1457 
1458     memset(&st, 0, sizeof(st));
1459     st.wMonth = 9;
1460     st.wYear  = 1752;
1461     st.wDay   = 14;
1462 
1463     res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1464     expect(1, res);
1465 
1466     /* September 1752 has 19 days */
1467     res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1468     expect(1, res);
1469 
1470     expect(1752, st_visible[0].wYear);
1471     expect(9, st_visible[0].wMonth);
1472     ok(14 == st_visible[0].wDay ||
1473        broken(1 == st_visible[0].wDay), /* comctl32 <= 4.72 */
1474        "Expected 14, got %d\n", st_visible[0].wDay);
1475 
1476     expect(1752, st_visible[1].wYear);
1477     expect(9, st_visible[1].wMonth);
1478     expect(19, st_visible[1].wDay);
1479 
1480     DestroyWindow(hwnd);
1481 }
1482 
1483 static void test_maxselday(void)
1484 {
1485     int res;
1486     HWND hwnd;
1487     DWORD style;
1488 
1489     hwnd = create_monthcal_control(0);
1490     /* if no style specified default to 1 */
1491     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1492     expect(1, res);
1493     res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1494     expect(0, res);
1495     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1496     expect(1, res);
1497 
1498     /* try to set style */
1499     style = GetWindowLongA(hwnd, GWL_STYLE);
1500     SetWindowLongA(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1501     style = GetWindowLongA(hwnd, GWL_STYLE);
1502     ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1503     DestroyWindow(hwnd);
1504 
1505     hwnd = create_monthcal_control(MCS_MULTISELECT);
1506     /* try to remove style */
1507     style = GetWindowLongA(hwnd, GWL_STYLE);
1508     SetWindowLongA(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1509     style = GetWindowLongA(hwnd, GWL_STYLE);
1510     ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1511     DestroyWindow(hwnd);
1512 
1513     hwnd = create_monthcal_control(MCS_MULTISELECT);
1514 
1515     /* default width is a week */
1516     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1517     expect(7, res);
1518 
1519     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1520 
1521     /* Setter and Getters for max selected days */
1522     res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1523     expect(1, res);
1524     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1525     expect(5, res);
1526 
1527     res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1528     expect(1, res);
1529     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1530     expect(15, res);
1531 
1532     /* test invalid value */
1533     res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1534     expect(0, res);
1535     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1536     expect(15, res);
1537 
1538     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1539 
1540     /* zero value is invalid too */
1541     res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1542     expect(0, res);
1543     res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1544     expect(15, res);
1545 
1546     DestroyWindow(hwnd);
1547 }
1548 
1549 static void test_size(void)
1550 {
1551     int res;
1552     RECT r1, r2;
1553     HFONT hFont1, hFont2;
1554     LOGFONTA logfont;
1555     HWND hwnd;
1556 
1557     hwnd = create_monthcal_control(0);
1558 
1559     lstrcpyA(logfont.lfFaceName, "Arial");
1560     memset(&logfont, 0, sizeof(logfont));
1561     logfont.lfHeight = 12;
1562     hFont1 = CreateFontIndirectA(&logfont);
1563 
1564     logfont.lfHeight = 24;
1565     hFont2 = CreateFontIndirectA(&logfont);
1566 
1567     /* initialize to a font we can compare against */
1568     SendMessageA(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1569     res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1570     ok(res, "SendMessageA(MCM_GETMINREQRECT) failed\n");
1571 
1572     /* check that setting a larger font results in an larger rect */
1573     SendMessageA(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1574     res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1575     ok(res, "SendMessageA(MCM_GETMINREQRECT) failed\n");
1576 
1577     OffsetRect(&r1, -r1.left, -r1.top);
1578     OffsetRect(&r2, -r2.left, -r2.top);
1579 
1580     ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1581 
1582     DestroyWindow(hwnd);
1583 }
1584 
1585 static void test_create(void)
1586 {
1587     HWND hwnd;
1588 
1589     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1590 
1591     hwnd = create_monthcal_control(0);
1592     ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1593 
1594     DestroyWindow(hwnd);
1595 
1596     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1597     hwnd = create_monthcal_control(MCS_MULTISELECT);
1598     ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1599     DestroyWindow(hwnd);
1600 }
1601 
1602 static void test_destroy(void)
1603 {
1604     HWND hwnd;
1605 
1606     hwnd = create_monthcal_control(0);
1607     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1608     DestroyWindow(hwnd);
1609     ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1610     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1611 
1612     /* MCS_MULTISELECT */
1613     hwnd = create_monthcal_control(MCS_MULTISELECT);
1614     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1615     DestroyWindow(hwnd);
1616     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1617 }
1618 
1619 static void test_selrange(void)
1620 {
1621     HWND hwnd;
1622     SYSTEMTIME st, range[2], range2[2];
1623     BOOL ret, old_comctl32 = FALSE;
1624 
1625     hwnd = create_monthcal_control(MCS_MULTISELECT);
1626 
1627     /* just after creation selection should start and end today */
1628     ret = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1629     expect(TRUE, ret);
1630 
1631     memset(range, 0xcc, sizeof(range));
1632     ret = SendMessageA(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1633     expect(TRUE, ret);
1634     expect(st.wYear,      range[0].wYear);
1635     expect(st.wMonth,     range[0].wMonth);
1636     expect(st.wDay,       range[0].wDay);
1637     if (range[0].wDayOfWeek != st.wDayOfWeek)
1638     {
1639         win_skip("comctl32 <= 4.70 doesn't set some values\n");
1640         old_comctl32 = TRUE;
1641     }
1642     else
1643     {
1644         expect(st.wDayOfWeek, range[0].wDayOfWeek);
1645         expect(st.wHour,      range[0].wHour);
1646         expect(st.wMinute,    range[0].wMinute);
1647         expect(st.wSecond,    range[0].wSecond);
1648         expect(st.wMilliseconds, range[0].wMilliseconds);
1649     }
1650 
1651     expect(st.wYear,      range[1].wYear);
1652     expect(st.wMonth,     range[1].wMonth);
1653     expect(st.wDay,       range[1].wDay);
1654     if (!old_comctl32)
1655     {
1656         expect(st.wDayOfWeek, range[1].wDayOfWeek);
1657         expect(st.wHour,      range[1].wHour);
1658         expect(st.wMinute,    range[1].wMinute);
1659         expect(st.wSecond,    range[1].wSecond);
1660         expect(st.wMilliseconds, range[1].wMilliseconds);
1661     }
1662 
1663     /* bounds are swapped if min > max */
1664     memset(&range[0], 0, sizeof(range[0]));
1665     range[0].wYear  = 2009;
1666     range[0].wMonth = 10;
1667     range[0].wDay   = 5;
1668     range[1] = range[0];
1669     range[1].wDay   = 3;
1670 
1671     ret = SendMessageA(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1672     expect(TRUE, ret);
1673 
1674     ret = SendMessageA(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1675     expect(TRUE, ret);
1676 
1677     expect(range[1].wYear,      range2[0].wYear);
1678     expect(range[1].wMonth,     range2[0].wMonth);
1679     expect(range[1].wDay,       range2[0].wDay);
1680     expect(6, range2[0].wDayOfWeek);
1681     expect(range[1].wHour,      range2[0].wHour);
1682     expect(range[1].wMinute,    range2[0].wMinute);
1683     expect(range[1].wSecond,    range2[0].wSecond);
1684     expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1685 
1686     expect(range[0].wYear,      range2[1].wYear);
1687     expect(range[0].wMonth,     range2[1].wMonth);
1688     expect(range[0].wDay,       range2[1].wDay);
1689     expect(1, range2[1].wDayOfWeek);
1690     expect(range[0].wHour,      range2[1].wHour);
1691     expect(range[0].wMinute,    range2[1].wMinute);
1692     expect(range[0].wSecond,    range2[1].wSecond);
1693     expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1694 
1695     /* try with range larger than maximum configured */
1696     memset(&range[0], 0, sizeof(range[0]));
1697     range[0].wYear  = 2009;
1698     range[0].wMonth = 10;
1699     range[0].wDay   = 1;
1700     range[1] = range[0];
1701 
1702     ret = SendMessageA(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1703     expect(TRUE, ret);
1704 
1705     range[1] = range[0];
1706     /* default max. range is 7 days */
1707     range[1].wDay = 8;
1708 
1709     ret = SendMessageA(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1710     expect(FALSE, ret);
1711 
1712     ret = SendMessageA(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1713     expect(TRUE, ret);
1714 
1715     expect(range[0].wYear,  range2[0].wYear);
1716     expect(range[0].wMonth, range2[0].wMonth);
1717     expect(range[0].wDay,   range2[0].wDay);
1718     expect(range[0].wYear,  range2[1].wYear);
1719     expect(range[0].wMonth, range2[1].wMonth);
1720     expect(range[0].wDay,   range2[1].wDay);
1721 
1722     DestroyWindow(hwnd);
1723 }
1724 
1725 static void test_killfocus(void)
1726 {
1727     HWND hwnd;
1728     DWORD style;
1729 
1730     hwnd = create_monthcal_control(0);
1731 
1732     /* make parent invisible */
1733     style = GetWindowLongA(parent_wnd, GWL_STYLE);
1734     SetWindowLongA(parent_wnd, GWL_STYLE, style & ~WS_VISIBLE);
1735 
1736     SendMessageA(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1737 
1738     style = GetWindowLongA(hwnd, GWL_STYLE);
1739     ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1740 
1741     style = GetWindowLongA(parent_wnd, GWL_STYLE);
1742     SetWindowLongA(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1743 
1744     DestroyWindow(hwnd);
1745 }
1746 
1747 static void test_hittest_v6(void)
1748 {
1749     MCHITTESTINFO mchit;
1750     DWORD ret;
1751     HWND hwnd;
1752     RECT r;
1753 
1754     hwnd = create_monthcal_control(0);
1755     SendMessageA(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1756 
1757     SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1758     /* reserving some area around calendar */
1759     MoveWindow(hwnd, 0, 0, r.right * 3 / 2, r.bottom * 3 / 2, FALSE);
1760     mchit.cbSize = sizeof(MCHITTESTINFO);
1761     mchit.pt.x = mchit.pt.y = 0;
1762     mchit.iOffset = -1;
1763     mchit.iRow = -1;
1764     mchit.iCol = -1;
1765     ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1766     if (ret == ~0u)
1767     {
1768         win_skip("Only MCHITTESTINFO_V1 supported\n");
1769         DestroyWindow(hwnd);
1770         return;
1771     }
1772     todo_wine expect_hex(MCHT_NOWHERE, ret);
1773     expect(-1, mchit.iOffset);
1774     expect(-1, mchit.iRow);
1775     expect(-1, mchit.iCol);
1776 
1777     MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1778     mchit.pt.x = r.right / 2;
1779     mchit.pt.y = r.bottom / 2;
1780     mchit.iOffset = -1;
1781     ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1782     expect_hex(MCHT_CALENDARDATE, ret);
1783     expect(0, mchit.iOffset);
1784 
1785     /* over day area */
1786     mchit.pt.x = r.right / (7*2);
1787     mchit.pt.y = r.bottom / 2;
1788     mchit.iOffset = -1;
1789     mchit.iCol = mchit.iRow = -1;
1790     mchit.uHit = 0;
1791     mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1792     ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1793     expect_hex(MCHT_CALENDARDATE, ret);
1794     expect_hex(MCHT_CALENDARDATE, mchit.uHit);
1795     expect(0, mchit.iOffset);
1796     expect(2, mchit.iRow);
1797     expect(0, mchit.iCol);
1798     /* returned a one day rectangle */
1799     expect_d(r.right / 7, mchit.rc.right - mchit.rc.left);
1800     expect_d(r.bottom / 10, mchit.rc.bottom - mchit.rc.top);
1801 
1802     /* title */
1803     mchit.pt.x = 1;
1804     mchit.pt.y = 1;
1805     mchit.iOffset = -1;
1806     mchit.iCol = mchit.iRow = -1;
1807     mchit.uHit = 0;
1808     mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1809     ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1810     expect_hex(MCHT_TITLE, ret);
1811     expect_hex(MCHT_TITLE, mchit.uHit);
1812     expect(0, mchit.iOffset);
1813     expect(-1, mchit.iRow);
1814     expect(-1, mchit.iCol);
1815     expect(0, mchit.rc.left);
1816     expect(0, mchit.rc.top);
1817     expect_d(r.right, mchit.rc.right);
1818     ok(mchit.rc.bottom > 0, "got %d\n", mchit.rc.bottom);
1819 
1820     /* between two calendars */
1821     MoveWindow(hwnd, 0, 0, r.right * 5/2, r.bottom, FALSE);
1822     mchit.pt.x = r.right / (5*4);
1823     mchit.pt.y = r.bottom / 2;
1824     mchit.iOffset = -2;
1825     mchit.iCol = mchit.iRow = -2;
1826     mchit.uHit = ~0;
1827     mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1828     ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1829     todo_wine expect_hex(MCHT_NOWHERE, ret);
1830     todo_wine expect_hex(MCHT_NOWHERE, mchit.uHit);
1831     expect(-2, mchit.iOffset);
1832     expect(-2, mchit.iRow);
1833     expect(-2, mchit.iCol);
1834     todo_wine expect(0, mchit.rc.left);
1835     todo_wine expect(0, mchit.rc.top);
1836     todo_wine expect_d(r.right * 5/2, mchit.rc.right);
1837     todo_wine expect_d(r.bottom, mchit.rc.bottom);
1838 
1839     DestroyWindow(hwnd);
1840 }
1841 
1842 static void test_get_set_border(void)
1843 {
1844     HWND hwnd;
1845     DWORD ret;
1846 
1847     hwnd = create_monthcal_control(0);
1848 
1849     /* a non-default value */
1850     ret = SendMessageA(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1851     expect(0, ret);
1852 
1853     ret = SendMessageA(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1854 
1855     if (ret != 10)
1856     {
1857         skip("MCM_GET/SETCALENDARBORDER not supported\n");
1858         DestroyWindow(hwnd);
1859         return;
1860     }
1861 
1862     expect(10, ret);
1863 
1864     DestroyWindow(hwnd);
1865 }
1866 
1867 static void test_MCM_SIZERECTTOMIN(void)
1868 {
1869     HWND hwnd;
1870     DWORD ret;
1871     RECT r, r2;
1872 
1873     hwnd = create_monthcal_control(0);
1874 
1875     ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1876     if (ret == 0)
1877     {
1878         win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1879         DestroyWindow(hwnd);
1880         return;
1881     }
1882 
1883     ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1884     ok(ret == 0, "got %d\n", ret);
1885 
1886     SetRectEmpty(&r);
1887     ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1888     if (ret == 0)
1889     {
1890         skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1891         DestroyWindow(hwnd);
1892         return;
1893     }
1894     ok(ret == 1, "got %d\n", ret);
1895     ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1896 
1897     r = r2;
1898     ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1899     ok(ret == 1, "got %d\n", ret);
1900 
1901     r2.right = (r2.right - r2.left) * 3;
1902     r2.bottom = (r2.bottom - r2.top) * 3;
1903     r2.left = r2.top = 0;
1904     ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r2);
1905     ok(ret == 1, "got %d\n", ret);
1906 
1907     DestroyWindow(hwnd);
1908 }
1909 
1910 static void test_MCM_GETCALENDARCOUNT(void)
1911 {
1912     HWND hwnd;
1913     DWORD ret;
1914 
1915     hwnd = create_monthcal_control(0);
1916 
1917     ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1918     if (ret == 0)
1919     {
1920         win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1921         DestroyWindow(hwnd);
1922         return;
1923     }
1924 
1925     expect(2, ret);
1926 
1927     DestroyWindow(hwnd);
1928 }
1929 
1930 static void test_daystate(void)
1931 {
1932     MONTHDAYSTATE state[4];
1933     DWORD ret, style;
1934     HWND hwnd;
1935     RECT r;
1936 
1937     /* without MCS_DAYSTATE */
1938     hwnd = create_monthcal_control(0);
1939 
1940     ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1941     expect(TRUE, ret);
1942 
1943     /* resize control to display two Calendars */
1944     MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1945 
1946     ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1947     expect(4, ret);
1948 
1949     ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1950     expect(0, ret);
1951 
1952     ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1953     expect(0, ret);
1954 
1955     ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1956     expect(0, ret);
1957 
1958     /* try to switch on */
1959     SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | MCS_DAYSTATE);
1960     style = GetWindowLongA(hwnd, GWL_STYLE);
1961     ok((style & MCS_DAYSTATE) == 0, "got 0x%08x\n", style);
1962 
1963     DestroyWindow(hwnd);
1964 
1965     /* with MCS_DAYSTATE */
1966     hwnd = create_monthcal_control(MCS_DAYSTATE);
1967 
1968     ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1969     expect(4, ret);
1970 
1971     ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1972     expect(1, ret);
1973 
1974     ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1975     expect(0, ret);
1976 
1977     ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1978     expect(0, ret);
1979 
1980     /* try to switch off */
1981     SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~MCS_DAYSTATE);
1982     style = GetWindowLongA(hwnd, GWL_STYLE);
1983     ok((style & MCS_DAYSTATE) == MCS_DAYSTATE, "got 0x%08x\n", style);
1984 
1985     DestroyWindow(hwnd);
1986 }
1987 
1988 static void test_sel_notify(void)
1989 {
1990     typedef struct
1991     {
1992         DWORD       val;
1993         const char* name;
1994     } Monthcal_style;
1995 
1996     HWND hwnd;
1997     RECT rc;
1998     MCHITTESTINFO mchit = {sizeof(MCHITTESTINFO)};
1999     SYSTEMTIME st;
2000     Monthcal_style styles[] = {
2001         {MCS_NOTODAY,                    "MCS_NOTODAY"},
2002         {MCS_NOTODAY | MCS_MULTISELECT,  "MCS_NOTODAY | MCS_MULTISELECT"},
2003         {MCS_DAYSTATE,                   "MCS_DAYSTATE"},
2004         {MCS_DAYSTATE | MCS_MULTISELECT, "MCS_DAYSTATE | MCS_MULTISELECT"}
2005     };
2006     int i;
2007 
2008     for(i = 0; i < sizeof styles / sizeof styles[0]; i++)
2009     {
2010         hwnd = create_monthcal_control(styles[i].val);
2011         SetWindowLongPtrA(hwnd, GWLP_ID, SEL_NOTIFY_TEST_ID);
2012         SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&rc);
2013         MoveWindow(hwnd, 0, 0, rc.right, rc.bottom, FALSE);
2014         /* Simulate mouse click on some unselected day to generate
2015             MCN_SELECT and MCN_SELCHANGE notifications */
2016         mchit.pt.x = rc.right / 2;
2017         mchit.pt.y = rc.bottom / 2;
2018         SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
2019         SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st);
2020         while(st.wDay == mchit.st.wDay) /* Ensure that mchit.pt points to unselected day */
2021         {
2022             mchit.pt.y++;
2023             SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
2024         }
2025         SendMessageA(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
2026         SendMessageA(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
2027         DestroyWindow(hwnd);
2028     }
2029 }
2030 
2031 START_TEST(monthcal)
2032 {
2033     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2034     INITCOMMONCONTROLSEX iccex;
2035     HMODULE hComctl32;
2036 
2037     ULONG_PTR ctx_cookie;
2038     HANDLE hCtx;
2039 
2040     hComctl32 = GetModuleHandleA("comctl32.dll");
2041     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2042     if (!pInitCommonControlsEx)
2043     {
2044         win_skip("InitCommonControlsEx() is missing. Skipping the tests\n");
2045         return;
2046     }
2047     iccex.dwSize = sizeof(iccex);
2048     iccex.dwICC  = ICC_DATE_CLASSES;
2049     pInitCommonControlsEx(&iccex);
2050 
2051     test_monthcal();
2052 
2053     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2054 
2055     parent_wnd = create_parent_window();
2056 
2057     test_create();
2058     test_destroy();
2059     test_color();
2060     test_currdate();
2061     test_firstDay();
2062     test_unicode();
2063     test_today();
2064     test_scroll();
2065     test_monthrange();
2066     test_hittest();
2067     test_todaylink();
2068     test_size();
2069     test_maxselday();
2070     test_selrange();
2071     test_killfocus();
2072     test_daystate();
2073     test_sel_notify();
2074 
2075     if (!load_v6_module(&ctx_cookie, &hCtx))
2076     {
2077         DestroyWindow(parent_wnd);
2078         return;
2079     }
2080 
2081     test_hittest_v6();
2082     test_get_set_border();
2083     test_MCM_SIZERECTTOMIN();
2084     test_MCM_GETCALENDARCOUNT();
2085 
2086     unload_v6_module(ctx_cookie, hCtx);
2087 
2088     DestroyWindow(parent_wnd);
2089 }
2090