1 /* Month calendar control
4 * Copyright 1998, 1999 Eric Kohl (ekohl@abo.rhein-zeitung.de)
5 * Copyright 1999 Alex Priem (alexp@sci.kun.nl)
6 * Copyright 1999 Chris Morgan <cmorgan@wpi.edu> and
7 * James Abbatiello <abbeyj@wpi.edu>
8 * Copyright 2000 Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * This code was audited for completeness against the documented features
27 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
29 * Unless otherwise noted, we believe this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
34 * -- MCM_[GS]ETUNICODEFORMAT
35 * -- MONTHCAL_GetMonthRange
36 * -- handle resources better (doesn't work now);
37 * -- take care of internationalization.
38 * -- keyboard handling.
39 * -- GetRange: At the moment, we copy ranges anyway, regardless of
40 * infoPtr->rangeValid; an invalid range is simply filled
41 * with zeros in SetRange. Is this the right behavior?
58 #include "wine/unicode.h"
59 #include "wine/debug.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
63 #define MC_SEL_LBUTUP 1 /* Left button released */
64 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
65 #define MC_PREVPRESSED 4 /* Prev month button pressed */
66 #define MC_NEXTPRESSED 8 /* Next month button pressed */
67 #define MC_NEXTMONTHDELAY 350 /* when continuously pressing `next */
68 /* month', wait 500 ms before going */
69 /* to the next month */
70 #define MC_NEXTMONTHTIMER 1 /* Timer ID's */
71 #define MC_PREVMONTHTIMER 2
73 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
90 int firstDayplace; /* place of the first day of the current month */
91 int delta; /* scroll rate; # of months that the */
92 /* control moves when user clicks a scroll button */
93 int visible; /* # of months visible */
94 int firstDay; /* Start month calendar with firstDay's day */
96 MONTHDAYSTATE *monthdayState;
97 SYSTEMTIME todaysDate;
100 int status; /* See MC_SEL flags */
101 int curSelDay; /* current selected day */
102 int firstSelDay; /* first selected day */
110 RECT title; /* rect for the header above the calendar */
111 RECT titlebtnnext; /* the `next month' button in the header */
112 RECT titlebtnprev; /* the `prev month' button in the header */
113 RECT titlemonth; /* the `month name' txt in the header */
114 RECT titleyear; /* the `year number' txt in the header */
115 RECT wdays; /* week days at top */
116 RECT days; /* calendar area */
117 RECT weeknums; /* week numbers at left side */
118 RECT todayrect; /* `today: xx/xx/xx' text rect */
119 HWND hwndNotify; /* Window to receive the notifications */
120 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
121 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
122 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
125 /* Offsets of days in the week to the weekday of january 1. */
126 static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
129 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0))
131 /* helper functions */
133 /* returns the number of days in any given month, checking for leap days */
134 /* january is 1, december is 12 */
135 int MONTHCAL_MonthLength(int month, int year)
137 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
138 /*Wrap around, this eases handling*/
144 /* if we have a leap year add 1 day to February */
145 /* a leap year is a year either divisible by 400 */
146 /* or divisible by 4 and not by 100 */
147 if(month == 2) { /* February */
148 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
149 (year%4 == 0)) ? 1 : 0);
152 return mdays[month - 1];
157 /* make sure that time is valid */
158 static int MONTHCAL_ValidateTime(SYSTEMTIME time)
160 if(time.wMonth > 12) return FALSE;
161 if(time.wDayOfWeek > 6) return FALSE;
162 if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
164 if(time.wHour > 23) return FALSE;
165 if(time.wMinute > 59) return FALSE;
166 if(time.wSecond > 59) return FALSE;
167 if(time.wMilliseconds > 999) return FALSE;
173 void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
175 to->wYear = from->wYear;
176 to->wMonth = from->wMonth;
177 to->wDayOfWeek = from->wDayOfWeek;
178 to->wDay = from->wDay;
179 to->wHour = from->wHour;
180 to->wMinute = from->wMinute;
181 to->wSecond = from->wSecond;
182 to->wMilliseconds = from->wMilliseconds;
186 /* Note:Depending on DST, this may be offset by a day.
187 Need to find out if we're on a DST place & adjust the clock accordingly.
188 Above function assumes we have a valid data.
189 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
193 /* returns the day in the week(0 == monday, 6 == sunday) */
194 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
195 static int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
199 return((year + year/4 - year/100 + year/400 +
200 DayOfWeekTable[month-1] + day - 1 ) % 7);
203 /* From a given point, calculate the row (weekpos), column(daypos)
204 and day in the calendar. day== 0 mean the last day of tha last month
206 static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO *infoPtr, int x, int y,
207 int *daypos,int *weekpos)
209 int retval, firstDay;
212 GetClientRect(infoPtr->hwndSelf, &rcClient);
214 /* if the point is outside the x bounds of the window put
216 if (x > rcClient.right)
220 *daypos = (x - infoPtr->days.left ) / infoPtr->width_increment;
221 *weekpos = (y - infoPtr->days.top ) / infoPtr->height_increment;
223 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear)+6 - infoPtr->firstDay)%7;
224 retval = *daypos + (7 * *weekpos) - firstDay;
228 /* day is the day of the month, 1 == 1st day of the month */
229 /* sets x and y to be the position of the day */
230 /* x == day, y == week where(0,0) == firstDay, 1st week */
231 static void MONTHCAL_CalcDayXY(MONTHCAL_INFO *infoPtr, int day, int month,
234 int firstDay, prevMonth;
236 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear) +6 - infoPtr->firstDay)%7;
238 if(month==infoPtr->currentMonth) {
239 *x = (day + firstDay) % 7;
240 *y = (day + firstDay - *x) / 7;
243 if(month < infoPtr->currentMonth) {
244 prevMonth = month - 1;
248 *x = (MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay) % 7;
253 *y = MONTHCAL_MonthLength(month, infoPtr->currentYear - 1) / 7;
254 *x = (day + firstDay + MONTHCAL_MonthLength(month,
255 infoPtr->currentYear)) % 7;
259 /* x: column(day), y: row(week) */
260 static void MONTHCAL_CalcDayRect(MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
262 r->left = infoPtr->days.left + x * infoPtr->width_increment;
263 r->right = r->left + infoPtr->width_increment;
264 r->top = infoPtr->days.top + y * infoPtr->height_increment;
265 r->bottom = r->top + infoPtr->textHeight;
269 /* sets the RECT struct r to the rectangle around the day and month */
270 /* day is the day value of the month(1 == 1st), month is the month */
271 /* value(january == 1, december == 12) */
272 static inline void MONTHCAL_CalcPosFromDay(MONTHCAL_INFO *infoPtr,
273 int day, int month, RECT *r)
277 MONTHCAL_CalcDayXY(infoPtr, day, month, &x, &y);
278 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
282 /* day is the day in the month(1 == 1st of the month) */
283 /* month is the month value(1 == january, 12 == december) */
284 static void MONTHCAL_CircleDay(MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month)
286 HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
287 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
293 MONTHCAL_CalcPosFromDay(infoPtr, day, month, &day_rect);
300 points[1].x = x + 0.8 * infoPtr->width_increment;
302 points[2].x = x + 0.9 * infoPtr->width_increment;
304 points[3].x = x + infoPtr->width_increment;
305 points[3].y = y + 0.5 * infoPtr->height_increment;
307 points[4].x = x + infoPtr->width_increment;
308 points[4].y = y + 0.9 * infoPtr->height_increment;
309 points[5].x = x + 0.6 * infoPtr->width_increment;
310 points[5].y = y + 0.9 * infoPtr->height_increment;
311 points[6].x = x + 0.5 * infoPtr->width_increment;
312 points[6].y = y + 0.9 * infoPtr->height_increment; /* bring the bottom up just
313 a hair to fit inside the day rectangle */
315 points[7].x = x + 0.2 * infoPtr->width_increment;
316 points[7].y = y + 0.8 * infoPtr->height_increment;
317 points[8].x = x + 0.1 * infoPtr->width_increment;
318 points[8].y = y + 0.8 * infoPtr->height_increment;
320 points[9].y = y + 0.5 * infoPtr->height_increment;
322 points[10].x = x + 0.1 * infoPtr->width_increment;
323 points[10].y = y + 0.2 * infoPtr->height_increment;
324 points[11].x = x + 0.2 * infoPtr->width_increment;
325 points[11].y = y + 0.3 * infoPtr->height_increment;
326 points[12].x = x + 0.4 * infoPtr->width_increment;
327 points[12].y = y + 0.2 * infoPtr->height_increment;
329 PolyBezier(hdc, points, 13);
330 DeleteObject(hRedPen);
331 SelectObject(hdc, hOldPen2);
335 static void MONTHCAL_DrawDay(MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month,
336 int x, int y, int bold)
338 static const WCHAR fmtW[] = { '%','d',0 };
341 static int haveBoldFont, haveSelectedDay = FALSE;
346 wsprintfW(buf, fmtW, day);
348 /* No need to check styles: when selection is not valid, it is set to zero.
349 * 1<day<31, so evertyhing's OK.
352 MONTHCAL_CalcDayRect(infoPtr, &r, x, y);
354 if((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
355 && (month==infoPtr->currentMonth)) {
359 TRACE("%d %d %d\n",day, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
360 TRACE("%ld %ld %ld %ld\n", r.left, r.top, r.right, r.bottom);
361 oldCol = SetTextColor(hdc, infoPtr->monthbk);
362 oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
363 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
364 hrgn = CreateEllipticRgn(r.left, r.top, r.right, r.bottom);
365 FillRgn(hdc, hrgn, hbr);
367 /* FIXME: this may need to be changed now b/c of the other
368 drawing changes 11/3/99 CMM */
369 r2.left = r.left - 0.25 * infoPtr->textWidth;
371 r2.right = r.left + 0.5 * infoPtr->textWidth;
372 r2.bottom = r.bottom;
373 if(haveSelectedDay) FillRect(hdc, &r2, hbr);
374 haveSelectedDay = TRUE;
376 haveSelectedDay = FALSE;
379 /* need to add some code for multiple selections */
381 if((bold) &&(!haveBoldFont)) {
382 SelectObject(hdc, infoPtr->hBoldFont);
385 if((!bold) &&(haveBoldFont)) {
386 SelectObject(hdc, infoPtr->hFont);
387 haveBoldFont = FALSE;
390 if(haveSelectedDay) {
391 SetTextColor(hdc, oldCol);
392 SetBkColor(hdc, oldBk);
395 SetBkMode(hdc,TRANSPARENT);
396 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
398 /* draw a rectangle around the currently selected days text */
399 if((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth))
400 DrawFocusRect(hdc, &r);
404 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
406 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
407 static const WCHAR fmt1W[] = { '%','s',' ','%','l','d',0 };
408 static const WCHAR fmt2W[] = { '%','s',' ','%','s',0 };
409 static const WCHAR fmt3W[] = { '%','d',0 };
410 RECT *title=&infoPtr->title;
411 RECT *prev=&infoPtr->titlebtnprev;
412 RECT *next=&infoPtr->titlebtnnext;
413 RECT *titlemonth=&infoPtr->titlemonth;
414 RECT *titleyear=&infoPtr->titleyear;
418 int i, j, m, mask, day, firstDay, weeknum, weeknum1,prevMonth;
419 int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
426 COLORREF oldTextColor, oldBkColor;
427 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
429 RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
430 SYSTEMTIME localtime;
433 oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
435 /* fill background */
436 hbr = CreateSolidBrush (infoPtr->bk);
437 FillRect(hdc, &ps->rcPaint, hbr);
441 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
443 hbr = CreateSolidBrush(infoPtr->titlebk);
444 FillRect(hdc, title, hbr);
448 /* if the previous button is pressed draw it depressed */
449 if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
451 if((infoPtr->status & MC_PREVPRESSED))
452 DrawFrameControl(hdc, prev, DFC_SCROLL,
453 DFCS_SCROLLLEFT | DFCS_PUSHED |
454 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
455 else /* if the previous button is pressed draw it depressed */
456 DrawFrameControl(hdc, prev, DFC_SCROLL,
457 DFCS_SCROLLLEFT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
460 /* if next button is depressed draw it depressed */
461 if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
463 if((infoPtr->status & MC_NEXTPRESSED))
464 DrawFrameControl(hdc, next, DFC_SCROLL,
465 DFCS_SCROLLRIGHT | DFCS_PUSHED |
466 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
467 else /* if the next button is pressed draw it depressed */
468 DrawFrameControl(hdc, next, DFC_SCROLL,
469 DFCS_SCROLLRIGHT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
472 oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
473 SetTextColor(hdc, infoPtr->titletxt);
474 currentFont = SelectObject(hdc, infoPtr->hBoldFont);
476 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
477 titlemonth->left = title->left;
478 titlemonth->right = title->right;
480 GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
482 wsprintfW(buf, fmt1W, buf1, infoPtr->currentYear);
484 if(IntersectRect(&rcTemp, &(ps->rcPaint), titlemonth))
486 DrawTextW(hdc, buf, strlenW(buf), titlemonth,
487 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
490 SelectObject(hdc, infoPtr->hFont);
492 /* titlemonth left/right contained rect for whole titletxt('June 1999')
493 * MCM_HitTestInfo wants month & year rects, so prepare these now.
494 *(no, we can't draw them separately; the whole text is centered)
496 GetTextExtentPoint32W(hdc, buf, strlenW(buf), &size);
497 titlemonth->left = title->right / 2 - size.cx / 2;
498 titleyear->right = title->right / 2 + size.cx / 2;
499 GetTextExtentPoint32W(hdc, buf1, strlenW(buf1), &size);
500 titlemonth->right = titlemonth->left + size.cx;
501 titleyear->left = titlemonth->right;
503 /* draw month area */
504 rcTemp.top=infoPtr->wdays.top;
505 rcTemp.left=infoPtr->wdays.left;
506 rcTemp.bottom=infoPtr->todayrect.bottom;
507 rcTemp.right =infoPtr->todayrect.right;
508 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcTemp))
510 hbr = CreateSolidBrush(infoPtr->monthbk);
511 FillRect(hdc, &rcTemp, hbr);
515 /* draw line under day abbreviatons */
517 MoveToEx(hdc, infoPtr->days.left + 3, title->bottom + textHeight + 1, NULL);
518 LineTo(hdc, infoPtr->days.right - 3, title->bottom + textHeight + 1);
520 prevMonth = infoPtr->currentMonth - 1;
521 if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
522 prevMonth = 12; /* december(12) of the previous year */
524 infoPtr->wdays.left = infoPtr->days.left = infoPtr->weeknums.right;
525 /* draw day abbreviations */
527 SetBkColor(hdc, infoPtr->monthbk);
528 SetTextColor(hdc, infoPtr->trailingtxt);
530 /* copy this rect so we can change the values without changing */
531 /* the original version */
532 days->left = infoPtr->wdays.left;
533 days->right = days->left + infoPtr->width_increment;
534 days->top = infoPtr->wdays.top;
535 days->bottom = infoPtr->wdays.bottom;
537 i = infoPtr->firstDay;
540 GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i +j)%7, buf, countof(buf));
541 DrawTextW(hdc, buf, strlenW(buf), days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
542 days->left+=infoPtr->width_increment;
543 days->right+=infoPtr->width_increment;
546 /* draw day numbers; first, the previous month */
548 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
550 day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) +
551 (infoPtr->firstDay + 7 - firstDay)%7 + 1;
552 if (day > MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear))
554 startofprescal = day;
559 while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
560 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
561 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
563 MONTHCAL_DrawDay(infoPtr, hdc, day, prevMonth, i, 0,
564 infoPtr->monthdayState[m] & mask);
572 /* draw `current' month */
574 day = 1; /* start at the beginning of the current month */
576 infoPtr->firstDayplace = i;
577 SetTextColor(hdc, infoPtr->txt);
581 /* draw the first week of the current month */
583 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
584 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
587 MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->currentMonth, i, 0,
588 infoPtr->monthdayState[m] & mask);
590 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
591 (day==infoPtr->todaysDate.wDay) &&
592 (infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
593 if(!(dwStyle & MCS_NOTODAYCIRCLE))
594 MONTHCAL_CircleDay(infoPtr, hdc, day, infoPtr->currentMonth);
603 j = 1; /* move to the 2nd week of the current month */
604 i = 0; /* move back to sunday */
605 while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
606 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
607 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
609 MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->currentMonth, i, j,
610 infoPtr->monthdayState[m] & mask);
612 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
613 (day==infoPtr->todaysDate.wDay) &&
614 (infoPtr->currentYear == infoPtr->todaysDate.wYear))
615 if(!(dwStyle & MCS_NOTODAYCIRCLE))
616 MONTHCAL_CircleDay(infoPtr, hdc, day, infoPtr->currentMonth);
621 if(i>6) { /* past saturday, goto the next weeks sunday */
627 /* draw `next' month */
629 day = 1; /* start at the first day of the next month */
633 SetTextColor(hdc, infoPtr->trailingtxt);
634 while((i<7) &&(j<6)) {
635 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
636 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
638 MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->currentMonth + 1, i, j,
639 infoPtr->monthdayState[m] & mask);
645 if(i==7) { /* past saturday, go to next week's sunday */
650 SetTextColor(hdc, infoPtr->txt);
653 /* draw `today' date if style allows it, and draw a circle before today's
654 * date if necessary */
656 if(!(dwStyle & MCS_NOTODAY)) {
658 if(!(dwStyle & MCS_NOTODAYCIRCLE)) {
659 /*day is the number of days from nextmonth we put on the calendar */
660 MONTHCAL_CircleDay(infoPtr, hdc,
661 day+MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear),
662 infoPtr->currentMonth);
665 if (!LoadStringW(COMCTL32_hModule,IDM_TODAY,buf1,countof(buf1)))
667 WARN("Can't load resource\n");
668 strcpyW(buf1, todayW);
670 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
671 MONTHCAL_CopyTime(&infoPtr->todaysDate,&localtime);
672 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,countof(buf2));
673 wsprintfW(buf, fmt2W, buf1, buf2);
674 SelectObject(hdc, infoPtr->hBoldFont);
676 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
678 DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
679 DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
681 SelectObject(hdc, infoPtr->hFont);
684 /*eventually draw week numbers*/
685 if(dwStyle & MCS_WEEKNUMBERS) {
686 /* display weeknumbers*/
689 /* Rules what week to call the first week of a new year:
690 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
691 The week containing Jan 1 is the first week of year
692 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
693 First week of year must contain 4 days of the new year
694 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
695 The first week of the year must contain only days of the new year
697 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
698 weeknum = atoiW(buf);
709 if (infoPtr->currentMonth < 2)
711 /* calculate all those exceptions for january */
712 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
713 if ((infoPtr->firstDay +7 - weeknum1)%7 > mindays)
719 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear-1);
720 weeknum +=startofprescal+ 7;
722 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear-1);
723 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
730 for(i=0; i<prevMonth-1; i++)
731 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear);
732 weeknum +=startofprescal+ 7;
734 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
735 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
738 days->left = infoPtr->weeknums.left;
739 days->right = infoPtr->weeknums.right;
740 days->top = infoPtr->weeknums.top;
741 days->bottom = days->top +infoPtr->height_increment;
743 if((i==0)&&(weeknum>50))
745 wsprintfW(buf, fmt3W, weeknum);
748 else if((i==5)&&(weeknum>47))
750 wsprintfW(buf, fmt3W, 1);
753 wsprintfW(buf, fmt3W, weeknum + i);
754 DrawTextW(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
755 days->top+=infoPtr->height_increment;
756 days->bottom+=infoPtr->height_increment;
759 MoveToEx(hdc, infoPtr->weeknums.right, infoPtr->weeknums.top + 3 , NULL);
760 LineTo(hdc, infoPtr->weeknums.right, infoPtr->weeknums.bottom );
763 /* currentFont was font at entering Refresh */
765 SetBkColor(hdc, oldBkColor);
766 SelectObject(hdc, currentFont);
767 SetTextColor(hdc, oldTextColor);
772 MONTHCAL_GetMinReqRect(MONTHCAL_INFO *infoPtr, LPARAM lParam)
774 LPRECT lpRect = (LPRECT) lParam;
776 TRACE("rect %p\n", lpRect);
778 /* validate parameters */
780 if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
782 lpRect->left = infoPtr->title.left;
783 lpRect->top = infoPtr->title.top;
784 lpRect->right = infoPtr->title.right;
785 lpRect->bottom = infoPtr->todayrect.bottom;
786 AdjustWindowRect(lpRect, GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE), FALSE);
788 TRACE("%s\n", wine_dbgstr_rect(lpRect));
795 MONTHCAL_GetColor(MONTHCAL_INFO *infoPtr, WPARAM wParam)
799 switch((int)wParam) {
800 case MCSC_BACKGROUND:
805 return infoPtr->titlebk;
807 return infoPtr->titletxt;
809 return infoPtr->monthbk;
810 case MCSC_TRAILINGTEXT:
811 return infoPtr->trailingtxt;
819 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
823 TRACE("%d: color %08lx\n", wParam, lParam);
825 switch((int)wParam) {
826 case MCSC_BACKGROUND:
828 infoPtr->bk = (COLORREF)lParam;
832 infoPtr->txt = (COLORREF)lParam;
835 prev = infoPtr->titlebk;
836 infoPtr->titlebk = (COLORREF)lParam;
839 prev=infoPtr->titletxt;
840 infoPtr->titletxt = (COLORREF)lParam;
843 prev = infoPtr->monthbk;
844 infoPtr->monthbk = (COLORREF)lParam;
846 case MCSC_TRAILINGTEXT:
847 prev = infoPtr->trailingtxt;
848 infoPtr->trailingtxt = (COLORREF)lParam;
852 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
858 MONTHCAL_GetMonthDelta(MONTHCAL_INFO *infoPtr)
863 return infoPtr->delta;
865 return infoPtr->visible;
870 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, WPARAM wParam)
872 int prev = infoPtr->delta;
874 TRACE("delta %d\n", wParam);
876 infoPtr->delta = (int)wParam;
882 MONTHCAL_GetFirstDayOfWeek(MONTHCAL_INFO *infoPtr)
884 return infoPtr->firstDay;
888 /* sets the first day of the week that will appear in the control */
889 /* 0 == Monday, 6 == Sunday */
890 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
891 /* FIXME: we need more error checking here */
893 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, LPARAM lParam)
895 int prev = infoPtr->firstDay;
898 TRACE("day %ld\n", lParam);
900 if((lParam >= 0) && (lParam < 7)) {
901 infoPtr->firstDay = (int)lParam;
905 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
906 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
907 infoPtr->firstDay = atoiW(buf);
914 MONTHCAL_GetMonthRange(MONTHCAL_INFO *infoPtr)
918 return infoPtr->monthRange;
923 MONTHCAL_GetMaxTodayWidth(MONTHCAL_INFO *infoPtr)
925 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
929 /* FIXME: are validated times taken from current date/time or simply
931 * FIXME: check whether MCM_GETMONTHRANGE shows correct result after
932 * adjusting range with MCM_SETRANGE
936 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
938 SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *)lParam;
941 TRACE("%x %lx\n", wParam, lParam);
943 if(wParam & GDTR_MAX) {
944 if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
945 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
946 infoPtr->rangeValid|=GDTR_MAX;
948 GetSystemTime(&infoPtr->todaysDate);
949 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
952 if(wParam & GDTR_MIN) {
953 if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
954 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minDate);
955 infoPtr->rangeValid|=GDTR_MIN;
957 GetSystemTime(&infoPtr->todaysDate);
958 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
962 prev = infoPtr->monthRange;
963 infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;
965 if(infoPtr->monthRange!=prev) {
966 infoPtr->monthdayState = ReAlloc(infoPtr->monthdayState,
967 infoPtr->monthRange * sizeof(MONTHDAYSTATE));
975 MONTHCAL_GetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
977 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
978 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *)lParam;
980 /* validate parameters */
982 if((infoPtr==NULL) || (lprgSysTimeArray==NULL)) return FALSE;
984 MONTHCAL_CopyTime(&infoPtr->maxDate, &lprgSysTimeArray[1]);
985 MONTHCAL_CopyTime(&infoPtr->minDate, &lprgSysTimeArray[0]);
987 return infoPtr->rangeValid;
992 MONTHCAL_SetDayState(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
995 int i, iMonths = (int)wParam;
996 MONTHDAYSTATE *dayStates = (LPMONTHDAYSTATE)lParam;
998 TRACE("%x %lx\n", wParam, lParam);
999 if(iMonths!=infoPtr->monthRange) return 0;
1001 for(i=0; i<iMonths; i++)
1002 infoPtr->monthdayState[i] = dayStates[i];
1007 MONTHCAL_GetCurSel(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1009 SYSTEMTIME *lpSel = (SYSTEMTIME *) lParam;
1011 TRACE("%lx\n", lParam);
1012 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
1013 if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
1015 MONTHCAL_CopyTime(&infoPtr->minSel, lpSel);
1016 TRACE("%d/%d/%d\n", lpSel->wYear, lpSel->wMonth, lpSel->wDay);
1020 /* FIXME: if the specified date is not visible, make it visible */
1021 /* FIXME: redraw? */
1023 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1025 SYSTEMTIME *lpSel = (SYSTEMTIME *)lParam;
1027 TRACE("%lx\n", lParam);
1028 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
1029 if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
1031 infoPtr->currentMonth=lpSel->wMonth;
1032 infoPtr->currentYear=lpSel->wYear;
1034 MONTHCAL_CopyTime(lpSel, &infoPtr->minSel);
1035 MONTHCAL_CopyTime(lpSel, &infoPtr->maxSel);
1037 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1044 MONTHCAL_GetMaxSelCount(MONTHCAL_INFO *infoPtr)
1046 return infoPtr->maxSelCount;
1051 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, WPARAM wParam)
1053 TRACE("%x\n", wParam);
1055 if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & MCS_MULTISELECT) {
1056 infoPtr->maxSelCount = wParam;
1064 MONTHCAL_GetSelRange(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1066 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
1068 TRACE("%lx\n", lParam);
1070 /* validate parameters */
1072 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
1074 if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & MCS_MULTISELECT)
1076 MONTHCAL_CopyTime(&infoPtr->maxSel, &lprgSysTimeArray[1]);
1077 MONTHCAL_CopyTime(&infoPtr->minSel, &lprgSysTimeArray[0]);
1078 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1087 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1089 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
1091 TRACE("%lx\n", lParam);
1093 /* validate parameters */
1095 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
1097 if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & MCS_MULTISELECT)
1099 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxSel);
1100 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minSel);
1101 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1110 MONTHCAL_GetToday(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1112 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1114 TRACE("%lx\n", lParam);
1116 /* validate parameters */
1118 if((infoPtr==NULL) || (lpToday==NULL)) return FALSE;
1119 MONTHCAL_CopyTime(&infoPtr->todaysDate, lpToday);
1125 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1127 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1129 TRACE("%lx\n", lParam);
1131 /* validate parameters */
1133 if((infoPtr==NULL) ||(lpToday==NULL)) return FALSE;
1134 MONTHCAL_CopyTime(lpToday, &infoPtr->todaysDate);
1135 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1141 MONTHCAL_HitTest(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1143 PMCHITTESTINFO lpht = (PMCHITTESTINFO)lParam;
1151 retval = MCHT_NOWHERE;
1153 ZeroMemory(&lpht->st, sizeof(lpht->st));
1155 /* Comment in for debugging...
1156 TRACE("%d %d wd[%d %d %d %d] d[%d %d %d %d] t[%d %d %d %d] wn[%d %d %d %d]\n", x, y,
1157 infoPtr->wdays.left, infoPtr->wdays.right,
1158 infoPtr->wdays.top, infoPtr->wdays.bottom,
1159 infoPtr->days.left, infoPtr->days.right,
1160 infoPtr->days.top, infoPtr->days.bottom,
1161 infoPtr->todayrect.left, infoPtr->todayrect.right,
1162 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1163 infoPtr->weeknums.left, infoPtr->weeknums.right,
1164 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1167 /* are we in the header? */
1169 if(PtInRect(&infoPtr->title, lpht->pt)) {
1170 if(PtInRect(&infoPtr->titlebtnprev, lpht->pt)) {
1171 retval = MCHT_TITLEBTNPREV;
1174 if(PtInRect(&infoPtr->titlebtnnext, lpht->pt)) {
1175 retval = MCHT_TITLEBTNNEXT;
1178 if(PtInRect(&infoPtr->titlemonth, lpht->pt)) {
1179 retval = MCHT_TITLEMONTH;
1182 if(PtInRect(&infoPtr->titleyear, lpht->pt)) {
1183 retval = MCHT_TITLEYEAR;
1187 retval = MCHT_TITLE;
1191 day = MONTHCAL_CalcDayFromPos(infoPtr,x,y,&wday,&wnum);
1192 if(PtInRect(&infoPtr->wdays, lpht->pt)) {
1193 retval = MCHT_CALENDARDAY;
1194 lpht->st.wYear = infoPtr->currentYear;
1195 lpht->st.wMonth = (day < 1)? infoPtr->currentMonth -1 : infoPtr->currentMonth;
1196 lpht->st.wDay = (day < 1)?
1197 MONTHCAL_MonthLength(infoPtr->currentMonth-1,infoPtr->currentYear) -day : day;
1200 if(PtInRect(&infoPtr->weeknums, lpht->pt)) {
1201 retval = MCHT_CALENDARWEEKNUM;
1202 lpht->st.wYear = infoPtr->currentYear;
1203 lpht->st.wMonth = (day < 1) ? infoPtr->currentMonth -1 :
1204 (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear)) ?
1205 infoPtr->currentMonth +1 :infoPtr->currentMonth;
1206 lpht->st.wDay = (day < 1 ) ?
1207 MONTHCAL_MonthLength(infoPtr->currentMonth-1,infoPtr->currentYear) -day :
1208 (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear)) ?
1209 day - MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear) : day;
1212 if(PtInRect(&infoPtr->days, lpht->pt))
1214 lpht->st.wYear = infoPtr->currentYear;
1217 retval = MCHT_CALENDARDATEPREV;
1218 lpht->st.wMonth = infoPtr->currentMonth - 1;
1219 if (lpht->st.wMonth <1)
1221 lpht->st.wMonth = 12;
1224 lpht->st.wDay = MONTHCAL_MonthLength(lpht->st.wMonth,lpht->st.wYear) -day;
1226 else if (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear))
1228 retval = MCHT_CALENDARDATENEXT;
1229 lpht->st.wMonth = infoPtr->currentMonth + 1;
1230 if (lpht->st.wMonth <12)
1232 lpht->st.wMonth = 1;
1235 lpht->st.wDay = day - MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear) ;
1238 retval = MCHT_CALENDARDATE;
1239 lpht->st.wMonth = infoPtr->currentMonth;
1240 lpht->st.wDay = day;
1244 if(PtInRect(&infoPtr->todayrect, lpht->pt)) {
1245 retval = MCHT_TODAYLINK;
1250 /* Hit nothing special? What's left must be background :-) */
1252 retval = MCHT_CALENDARBK;
1254 lpht->uHit = retval;
1259 static void MONTHCAL_GoToNextMonth(MONTHCAL_INFO *infoPtr)
1261 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
1263 TRACE("MONTHCAL_GoToNextMonth\n");
1265 infoPtr->currentMonth++;
1266 if(infoPtr->currentMonth > 12) {
1267 infoPtr->currentYear++;
1268 infoPtr->currentMonth = 1;
1271 if(dwStyle & MCS_DAYSTATE) {
1275 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1276 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1277 nmds.nmhdr.code = MCN_GETDAYSTATE;
1278 nmds.cDayState = infoPtr->monthRange;
1279 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1281 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
1282 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1283 for(i=0; i<infoPtr->monthRange; i++)
1284 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1289 static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO *infoPtr)
1291 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
1295 infoPtr->currentMonth--;
1296 if(infoPtr->currentMonth < 1) {
1297 infoPtr->currentYear--;
1298 infoPtr->currentMonth = 12;
1301 if(dwStyle & MCS_DAYSTATE) {
1305 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1306 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1307 nmds.nmhdr.code = MCN_GETDAYSTATE;
1308 nmds.cDayState = infoPtr->monthRange;
1309 nmds.prgDayState = Alloc
1310 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1312 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
1313 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1314 for(i=0; i<infoPtr->monthRange; i++)
1315 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1320 MONTHCAL_RButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1322 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1327 hMenu = CreatePopupMenu();
1328 if (!LoadStringW(COMCTL32_hModule,IDM_GOTODAY,buf,countof(buf)))
1330 WARN("Can't load resource\n");
1331 strcpyW(buf, todayW);
1333 AppendMenuW(hMenu, MF_STRING|MF_ENABLED,1, buf);
1334 menupoint.x=(INT)LOWORD(lParam);
1335 menupoint.y=(INT)HIWORD(lParam);
1336 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1337 if( TrackPopupMenu(hMenu,TPM_RIGHTBUTTON| TPM_NONOTIFY|TPM_RETURNCMD,
1338 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1340 infoPtr->currentMonth=infoPtr->todaysDate.wMonth;
1341 infoPtr->currentYear=infoPtr->todaysDate.wYear;
1342 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1348 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1350 static const WCHAR EditW[] = { 'E','D','I','T',0 };
1354 RECT rcDay; /* used in determining area to invalidate */
1359 TRACE("%lx\n", lParam);
1361 if (infoPtr->hWndYearUpDown)
1363 infoPtr->currentYear=SendMessageW( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)0);
1364 if(!DestroyWindow(infoPtr->hWndYearUpDown))
1366 FIXME("Can't destroy Updown Control\n");
1369 infoPtr->hWndYearUpDown=0;
1370 if(!DestroyWindow(infoPtr->hWndYearEdit))
1372 FIXME("Can't destroy Updown Control\n");
1375 infoPtr->hWndYearEdit=0;
1376 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1379 ht.pt.x = (INT)LOWORD(lParam);
1380 ht.pt.y = (INT)HIWORD(lParam);
1381 hit = MONTHCAL_HitTest(infoPtr, (LPARAM)&ht);
1383 /* FIXME: these flags should be checked by */
1384 /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
1386 if(hit ==MCHT_TITLEBTNNEXT) {
1387 MONTHCAL_GoToNextMonth(infoPtr);
1388 infoPtr->status = MC_NEXTPRESSED;
1389 SetTimer(infoPtr->hwndSelf, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1390 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1393 if(hit == MCHT_TITLEBTNPREV){
1394 MONTHCAL_GoToPrevMonth(infoPtr);
1395 infoPtr->status = MC_PREVPRESSED;
1396 SetTimer(infoPtr->hwndSelf, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1397 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1401 if(hit == MCHT_TITLEMONTH) {
1402 hMenu = CreatePopupMenu();
1406 GetLocaleInfoW(LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+i, buf,countof(buf));
1407 AppendMenuW(hMenu, MF_STRING|MF_ENABLED,i+1, buf);
1409 menupoint.x=infoPtr->titlemonth.right;
1410 menupoint.y=infoPtr->titlemonth.bottom;
1411 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1412 i= TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
1413 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
1414 if ((i>0) && (i<13))
1416 infoPtr->currentMonth=i;
1417 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1420 if(hit == MCHT_TITLEYEAR) {
1421 infoPtr->hWndYearEdit=CreateWindowExW(0,
1424 WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT,
1425 infoPtr->titleyear.left+3,infoPtr->titlebtnnext.top,
1426 infoPtr->titleyear.right-infoPtr->titleyear.left,
1427 infoPtr->textHeight,
1432 infoPtr->hWndYearUpDown=CreateWindowExW(0,
1435 WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT|UDS_NOTHOUSANDS|UDS_ARROWKEYS,
1436 infoPtr->titleyear.right+6,infoPtr->titlebtnnext.top,
1438 infoPtr->textHeight,
1443 SendMessageW( infoPtr->hWndYearUpDown, UDM_SETRANGE, (WPARAM) 0, MAKELONG (9999, 1753));
1444 SendMessageW( infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM) infoPtr->hWndYearEdit, (LPARAM)0 );
1445 SendMessageW( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)infoPtr->currentYear );
1449 if(hit == MCHT_TODAYLINK) {
1450 infoPtr->currentMonth=infoPtr->todaysDate.wMonth;
1451 infoPtr->currentYear=infoPtr->todaysDate.wYear;
1452 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1455 if(hit == MCHT_CALENDARDATE) {
1456 SYSTEMTIME selArray[2];
1459 MONTHCAL_CopyTime(&ht.st, &selArray[0]);
1460 MONTHCAL_CopyTime(&ht.st, &selArray[1]);
1461 MONTHCAL_SetSelRange(infoPtr, (LPARAM)&selArray);
1462 MONTHCAL_SetCurSel(infoPtr, (LPARAM)&selArray);
1463 TRACE("MCHT_CALENDARDATE\n");
1464 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
1465 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1466 nmsc.nmhdr.code = MCN_SELCHANGE;
1467 MONTHCAL_CopyTime(&infoPtr->minSel,&nmsc.stSelStart);
1468 MONTHCAL_CopyTime(&infoPtr->maxSel,&nmsc.stSelEnd);
1470 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
1471 (WPARAM)nmsc.nmhdr.idFrom,(LPARAM)&nmsc);
1474 /* redraw both old and new days if the selected day changed */
1475 if(infoPtr->curSelDay != ht.st.wDay) {
1476 MONTHCAL_CalcPosFromDay(infoPtr, ht.st.wDay, ht.st.wMonth, &rcDay);
1477 InvalidateRect(infoPtr->hwndSelf, &rcDay, TRUE);
1479 MONTHCAL_CalcPosFromDay(infoPtr, infoPtr->curSelDay, infoPtr->currentMonth, &rcDay);
1480 InvalidateRect(infoPtr->hwndSelf, &rcDay, TRUE);
1483 infoPtr->firstSelDay = ht.st.wDay;
1484 infoPtr->curSelDay = ht.st.wDay;
1485 infoPtr->status = MC_SEL_LBUTDOWN;
1494 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1498 BOOL redraw = FALSE;
1504 if(infoPtr->status & MC_NEXTPRESSED) {
1505 KillTimer(infoPtr->hwndSelf, MC_NEXTMONTHTIMER);
1506 infoPtr->status &= ~MC_NEXTPRESSED;
1509 if(infoPtr->status & MC_PREVPRESSED) {
1510 KillTimer(infoPtr->hwndSelf, MC_PREVMONTHTIMER);
1511 infoPtr->status &= ~MC_PREVPRESSED;
1515 ht.pt.x = (INT)LOWORD(lParam);
1516 ht.pt.y = (INT)HIWORD(lParam);
1517 hit = MONTHCAL_HitTest(infoPtr, (LPARAM)&ht);
1519 infoPtr->status = MC_SEL_LBUTUP;
1521 if(hit ==MCHT_CALENDARDATENEXT) {
1522 MONTHCAL_GoToNextMonth(infoPtr);
1523 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1526 if(hit == MCHT_CALENDARDATEPREV){
1527 MONTHCAL_GoToPrevMonth(infoPtr);
1528 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1531 nmhdr.hwndFrom = infoPtr->hwndSelf;
1532 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1533 nmhdr.code = NM_RELEASEDCAPTURE;
1534 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
1536 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1537 /* redraw if necessary */
1539 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1540 /* only send MCN_SELECT if currently displayed month's day was selected */
1541 if(hit == MCHT_CALENDARDATE) {
1542 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
1543 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1544 nmsc.nmhdr.code = MCN_SELECT;
1545 MONTHCAL_CopyTime(&infoPtr->minSel, &nmsc.stSelStart);
1546 MONTHCAL_CopyTime(&infoPtr->maxSel, &nmsc.stSelEnd);
1548 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1556 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM wParam)
1558 BOOL redraw = FALSE;
1560 TRACE("%d\n", wParam);
1563 case MC_NEXTMONTHTIMER:
1565 MONTHCAL_GoToNextMonth(infoPtr);
1567 case MC_PREVMONTHTIMER:
1569 MONTHCAL_GoToPrevMonth(infoPtr);
1572 ERR("got unknown timer\n");
1576 /* redraw only if necessary */
1578 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1585 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1588 int oldselday, selday, hit;
1591 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
1593 ht.pt.x = LOWORD(lParam);
1594 ht.pt.y = HIWORD(lParam);
1596 hit = MONTHCAL_HitTest(infoPtr, (LPARAM)&ht);
1598 /* not on the calendar date numbers? bail out */
1599 TRACE("hit:%x\n",hit);
1600 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE) return 0;
1602 selday = ht.st.wDay;
1603 oldselday = infoPtr->curSelDay;
1604 infoPtr->curSelDay = selday;
1605 MONTHCAL_CalcPosFromDay(infoPtr, selday, ht.st. wMonth, &r);
1607 if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & MCS_MULTISELECT) {
1608 SYSTEMTIME selArray[2];
1611 MONTHCAL_GetSelRange(infoPtr, (LPARAM)&selArray);
1613 if(infoPtr->firstSelDay==selArray[0].wDay) i=1;
1614 TRACE("oldRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1615 if(infoPtr->firstSelDay==selArray[1].wDay) {
1616 /* 1st time we get here: selArray[0]=selArray[1]) */
1617 /* if we're still at the first selected date, return */
1618 if(infoPtr->firstSelDay==selday) goto done;
1619 if(selday<infoPtr->firstSelDay) i = 0;
1622 if(abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
1623 if(selday>infoPtr->firstSelDay)
1624 selday = infoPtr->firstSelDay + infoPtr->maxSelCount;
1626 selday = infoPtr->firstSelDay - infoPtr->maxSelCount;
1629 if(selArray[i].wDay!=selday) {
1630 TRACE("newRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1632 selArray[i].wDay = selday;
1634 if(selArray[0].wDay>selArray[1].wDay) {
1636 tempday = selArray[1].wDay;
1637 selArray[1].wDay = selArray[0].wDay;
1638 selArray[0].wDay = tempday;
1641 MONTHCAL_SetSelRange(infoPtr, (LPARAM)&selArray);
1647 /* only redraw if the currently selected day changed */
1648 /* FIXME: this should specify a rectangle containing only the days that changed */
1649 /* using InvalidateRect */
1650 if(oldselday != infoPtr->curSelDay)
1651 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1658 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, WPARAM wParam)
1665 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
1669 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
1671 MONTHCAL_Refresh(infoPtr, hdc, &ps);
1672 if (!wParam) EndPaint(infoPtr->hwndSelf, &ps);
1678 MONTHCAL_KillFocus(MONTHCAL_INFO *infoPtr)
1682 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1689 MONTHCAL_SetFocus(MONTHCAL_INFO *infoPtr)
1693 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1698 /* sets the size information */
1699 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
1701 static const WCHAR SunW[] = { 'S','u','n',0 };
1702 static const WCHAR O0W[] = { '0','0',0 };
1703 HDC hdc = GetDC(infoPtr->hwndSelf);
1704 RECT *title=&infoPtr->title;
1705 RECT *prev=&infoPtr->titlebtnprev;
1706 RECT *next=&infoPtr->titlebtnnext;
1707 RECT *titlemonth=&infoPtr->titlemonth;
1708 RECT *titleyear=&infoPtr->titleyear;
1709 RECT *wdays=&infoPtr->wdays;
1710 RECT *weeknumrect=&infoPtr->weeknums;
1711 RECT *days=&infoPtr->days;
1712 RECT *todayrect=&infoPtr->todayrect;
1715 DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
1717 int xdiv, left_offset;
1720 GetClientRect(infoPtr->hwndSelf, &rcClient);
1722 currentFont = SelectObject(hdc, infoPtr->hFont);
1724 /* get the height and width of each day's text */
1725 GetTextMetricsW(hdc, &tm);
1726 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
1727 GetTextExtentPoint32W(hdc, SunW, 3, &size);
1728 infoPtr->textWidth = size.cx + 2;
1730 /* recalculate the height and width increments and offsets */
1731 GetTextExtentPoint32W(hdc, O0W, 2, &size);
1733 xdiv = (dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
1735 infoPtr->width_increment = size.cx * 2;
1736 infoPtr->height_increment = infoPtr->textHeight;
1737 left_offset = (rcClient.right - rcClient.left) - (infoPtr->width_increment * xdiv);
1739 /* calculate title area */
1740 title->top = rcClient.top;
1741 title->bottom = title->top + 3 * infoPtr->height_increment / 2;
1742 title->left = left_offset;
1743 title->right = rcClient.right;
1745 /* set the dimensions of the next and previous buttons and center */
1746 /* the month text vertically */
1747 prev->top = next->top = title->top + 4;
1748 prev->bottom = next->bottom = title->bottom - 4;
1749 prev->left = title->left + 4;
1750 prev->right = prev->left + (title->bottom - title->top) ;
1751 next->right = title->right - 4;
1752 next->left = next->right - (title->bottom - title->top);
1754 /* titlemonth->left and right change based upon the current month */
1755 /* and are recalculated in refresh as the current month may change */
1756 /* without the control being resized */
1757 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
1758 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
1760 /* setup the dimensions of the rectangle we draw the names of the */
1761 /* days of the week in */
1762 weeknumrect->left = left_offset;
1763 if(dwStyle & MCS_WEEKNUMBERS)
1764 weeknumrect->right=prev->right;
1766 weeknumrect->right=weeknumrect->left;
1767 wdays->left = days->left = weeknumrect->right;
1768 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
1769 wdays->top = title->bottom ;
1770 wdays->bottom = wdays->top + infoPtr->height_increment;
1772 days->top = weeknumrect->top = wdays->bottom ;
1773 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
1775 todayrect->left = rcClient.left;
1776 todayrect->right = rcClient.right;
1777 todayrect->top = days->bottom;
1778 todayrect->bottom = days->bottom + infoPtr->height_increment;
1780 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
1781 infoPtr->width_increment,infoPtr->height_increment,
1782 wine_dbgstr_rect(&rcClient),
1783 wine_dbgstr_rect(title),
1784 wine_dbgstr_rect(wdays),
1785 wine_dbgstr_rect(days),
1786 wine_dbgstr_rect(todayrect));
1788 /* restore the originally selected font */
1789 SelectObject(hdc, currentFont);
1791 ReleaseDC(infoPtr->hwndSelf, hdc);
1794 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
1796 TRACE("(width=%d, height=%d)\n", Width, Height);
1798 MONTHCAL_UpdateSize(infoPtr);
1800 /* invalidate client area and erase background */
1801 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1806 static LRESULT MONTHCAL_GetFont(MONTHCAL_INFO *infoPtr)
1808 return (LRESULT)infoPtr->hFont;
1811 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
1816 if (!hFont) return 0;
1818 hOldFont = infoPtr->hFont;
1819 infoPtr->hFont = hFont;
1821 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
1822 lf.lfWeight = FW_BOLD;
1823 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
1826 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1828 return (LRESULT)hOldFont;
1831 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1833 MONTHCAL_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
1835 MONTHCAL_INFO *infoPtr;
1837 /* allocate memory for info structure */
1838 infoPtr =(MONTHCAL_INFO*)Alloc(sizeof(MONTHCAL_INFO));
1839 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
1841 if(infoPtr == NULL) {
1842 ERR( "could not allocate info memory!\n");
1846 infoPtr->hwndSelf = hwnd;
1847 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1849 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
1851 /* initialize info structure */
1852 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1854 GetSystemTime(&infoPtr->todaysDate);
1855 MONTHCAL_SetFirstDayOfWeek(infoPtr, (LPARAM)-1);
1856 infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
1857 infoPtr->currentYear = infoPtr->todaysDate.wYear;
1858 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
1859 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
1860 infoPtr->maxDate.wYear=2050;
1861 infoPtr->minDate.wYear=1950;
1862 infoPtr->maxSelCount = 7;
1863 infoPtr->monthRange = 3;
1864 infoPtr->monthdayState = Alloc
1865 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1866 infoPtr->titlebk = GetSysColor(COLOR_ACTIVECAPTION);
1867 infoPtr->titletxt = GetSysColor(COLOR_WINDOW);
1868 infoPtr->monthbk = GetSysColor(COLOR_WINDOW);
1869 infoPtr->trailingtxt = GetSysColor(COLOR_GRAYTEXT);
1870 infoPtr->bk = GetSysColor(COLOR_WINDOW);
1871 infoPtr->txt = GetSysColor(COLOR_WINDOWTEXT);
1873 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1874 /* of the control */
1875 MONTHCAL_UpdateSize(infoPtr);
1882 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
1884 /* free month calendar info data */
1885 if(infoPtr->monthdayState)
1886 Free(infoPtr->monthdayState);
1887 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1893 static LRESULT WINAPI
1894 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1896 MONTHCAL_INFO *infoPtr;
1898 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1900 infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1901 if (!infoPtr && (uMsg != WM_CREATE))
1902 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
1906 return MONTHCAL_GetCurSel(infoPtr, lParam);
1909 return MONTHCAL_SetCurSel(infoPtr, lParam);
1911 case MCM_GETMAXSELCOUNT:
1912 return MONTHCAL_GetMaxSelCount(infoPtr);
1914 case MCM_SETMAXSELCOUNT:
1915 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
1917 case MCM_GETSELRANGE:
1918 return MONTHCAL_GetSelRange(infoPtr, lParam);
1920 case MCM_SETSELRANGE:
1921 return MONTHCAL_SetSelRange(infoPtr, lParam);
1923 case MCM_GETMONTHRANGE:
1924 return MONTHCAL_GetMonthRange(infoPtr);
1926 case MCM_SETDAYSTATE:
1927 return MONTHCAL_SetDayState(infoPtr, wParam, lParam);
1929 case MCM_GETMINREQRECT:
1930 return MONTHCAL_GetMinReqRect(infoPtr, lParam);
1933 return MONTHCAL_GetColor(infoPtr, wParam);
1936 return MONTHCAL_SetColor(infoPtr, wParam, lParam);
1939 return MONTHCAL_GetToday(infoPtr, lParam);
1942 return MONTHCAL_SetToday(infoPtr, lParam);
1945 return MONTHCAL_HitTest(infoPtr, lParam);
1947 case MCM_GETFIRSTDAYOFWEEK:
1948 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
1950 case MCM_SETFIRSTDAYOFWEEK:
1951 return MONTHCAL_SetFirstDayOfWeek(infoPtr, lParam);
1954 return MONTHCAL_GetRange(hwnd, wParam, lParam);
1957 return MONTHCAL_SetRange(infoPtr, wParam, lParam);
1959 case MCM_GETMONTHDELTA:
1960 return MONTHCAL_GetMonthDelta(infoPtr);
1962 case MCM_SETMONTHDELTA:
1963 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
1965 case MCM_GETMAXTODAYWIDTH:
1966 return MONTHCAL_GetMaxTodayWidth(infoPtr);
1969 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1972 return MONTHCAL_KillFocus(infoPtr);
1974 case WM_RBUTTONDOWN:
1975 return MONTHCAL_RButtonDown(infoPtr, lParam);
1977 case WM_LBUTTONDOWN:
1978 return MONTHCAL_LButtonDown(infoPtr, lParam);
1981 return MONTHCAL_MouseMove(infoPtr, wParam, lParam);
1984 return MONTHCAL_LButtonUp(infoPtr, lParam);
1987 return MONTHCAL_Paint(infoPtr, wParam);
1990 return MONTHCAL_SetFocus(infoPtr);
1993 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1996 return MONTHCAL_Create(hwnd, wParam, lParam);
1999 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2002 return MONTHCAL_GetFont(infoPtr);
2005 return MONTHCAL_Timer(infoPtr, wParam);
2008 return MONTHCAL_Destroy(infoPtr);
2011 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2012 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
2013 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2019 MONTHCAL_Register(void)
2023 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2024 wndClass.style = CS_GLOBALCLASS;
2025 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2026 wndClass.cbClsExtra = 0;
2027 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2028 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2029 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2030 wndClass.lpszClassName = MONTHCAL_CLASSW;
2032 RegisterClassW(&wndClass);
2037 MONTHCAL_Unregister(void)
2039 UnregisterClassW(MONTHCAL_CLASSW, NULL);