📄 monthcalendar.c
字号:
{ *pWeekDay = GetWeekDay (year, month, day); *pline = (day + 6 - *pWeekDay - 1)/7; }*/// get rects of arrowsstatic void mcGetArrowRects (RECT* prcMonth, RECT* prcYear, RECT* prcAML, RECT* prcAMR, RECT* prcAYL, RECT* prcAYR){ prcAML->right = prcMonth->left - 1; prcAML->left = prcAML->right - ARROWRECT_W; prcAML->top = prcMonth->top; prcAML->bottom = prcMonth->bottom; prcAMR->left = prcMonth->right + 2; prcAMR->right = prcAMR->left + ARROWRECT_W; prcAMR->top = prcMonth->top; prcAMR->bottom = prcMonth->bottom; prcAYL->right = prcYear->left - 2; prcAYL->left = prcAYL->right - ARROWRECT_W; prcAYL->top = prcYear->top; prcAYL->bottom = prcYear->bottom; prcAYR->left = prcYear->right + 2; prcAYR->right = prcAYR->left + ARROWRECT_W; prcAYR->top = prcYear->top; prcAYR->bottom = prcYear->bottom;}// get rect of month day areastatic void mcGetMDayRect (HWND hwnd, RECT* prcClient, RECT* prcMDay){ prcMDay->left = prcClient->left + WEEK_BORDER; prcMDay->right = prcClient->right - WEEK_BORDER; prcMDay->top = prcClient->top + 2 + DATECAP_H(hwnd) + 2*WEEK_VBORDER2 + WEEKFIELD_H(hwnd); prcMDay->bottom = prcClient->bottom - WEEK_VBORDER2;}// get rects of ...static void mcGetRects (HWND hWnd, RECT* prcClient, RECT* prcMonth, RECT* prcYear, RECT* prcMDay){ if (prcClient) { GetClientRect (hWnd, prcClient); prcClient->right --; prcClient->bottom --; } if (prcMonth) SetRect (prcMonth, prcClient->left + MON_BORDER, //prcClient->top + 4, prcClient->top + 6, prcClient->left + MON_BORDER + MON_WIDTH, prcClient->top + 2 + DATECAP_H(hWnd) - 4); if (prcYear) SetRect (prcYear, prcClient->right - YEAR_BORDER - YEAR_WIDTH, //prcClient->top + 4, prcClient->top + 6, prcClient->right - YEAR_BORDER, prcClient->top + 2 + DATECAP_H(hWnd) - 4); if (prcMDay) mcGetMDayRect (hWnd, prcClient, prcMDay);}// get item rect from the x-y mouse positionstatic void mcGetItemRectFromPos (PMONCALDDATA mc_data, RECT* prcMDay, RECT* prcItem, int* pline, int* pweekday, int x, int y){ *pline = (y - prcMDay->top) / mc_data->item_h; *pweekday = (x - prcMDay->left) / mc_data->item_w; prcItem->left = prcMDay->left + *pweekday*mc_data->item_w; prcItem->right = prcItem->left + mc_data->item_w; prcItem->top = prcMDay->top + *pline*mc_data->item_h; prcItem->bottom = prcItem->top + mc_data->item_h;}// get current item rect from mc_datastatic void mcGetCurRect (RECT* prcMDay, RECT* prcItem, PMONCALDDATA mc_data){ prcItem->left = prcMDay->left + mc_data->cur_WeekDay*mc_data->item_w; prcItem->top = prcMDay->top + mc_data->cur_line*mc_data->item_h; prcItem->right = prcItem->left + mc_data->item_w; prcItem->bottom = prcItem->top + mc_data->item_h;}// textout in a rect center stylestatic void mcTextOutCenter (HDC hdc, RECT* prcText, const char* pchText){#if 0 int ch_w, ch_h, x, y; int bkMode; ch_w = GetSysCharWidth (); ch_h = GetSysCharHeight (); x = (prcText->right + prcText->left)/2 - strlen(pchText)*ch_w/2; y = (prcText->bottom + prcText->top)/2 - ch_h/2+1; if (pchText) { bkMode = SetBkMode (hdc, BM_TRANSPARENT); TextOut (hdc, x, y, pchText, -1); SetBkMode (hdc, bkMode); }#else if (pchText) { int bkMode; bkMode = SetBkMode (hdc, BM_TRANSPARENT); DrawText (hdc, pchText, -1, prcText, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOCLIP); SetBkMode (hdc, bkMode); }#endif}static void mcUnHilightRect (PMONCALDDATA mc_data, HDC hdc, RECT* prcItem, int day){ int item_w, item_h; char daytext[3]; PMCCOLORINFO pmcci; pmcci = (PMCCOLORINFO) mc_data->dwClrData; item_w = prcItem->right - prcItem->left; item_h = prcItem->bottom - prcItem->top; SetBrushColor (hdc, pmcci->clr_daybk); FillBox (hdc, prcItem->left, prcItem->top, item_w, item_h); if (day < 10) sprintf (daytext, " %d", day); else sprintf (daytext, "%d", day); SetBkColor(hdc, pmcci->clr_dayHibk); SetTextColor (hdc, pmcci->clr_daytext); mcTextOutCenter (hdc, prcItem, daytext);}static void mcHilightRect (PMONCALDDATA mc_data, HDC hdc, RECT* prcItem, int day){ int item_w, item_h; char daytext[3]; PMCCOLORINFO pmcci; pmcci = (PMCCOLORINFO) mc_data->dwClrData; SetBrushColor (hdc, pmcci->clr_dayHibk); item_w = prcItem->right - prcItem->left; item_h = prcItem->bottom - prcItem->top; FillBox (hdc, prcItem->left, prcItem->top, item_w, item_h); SetPenColor(hdc, GetWindowElementColor(FGC_MENUITEM_FRAME)); Rectangle (hdc, prcItem->left, prcItem->top, prcItem->left+item_w-1, prcItem->top+item_h-1); if (day < 10) sprintf (daytext, " %d", day); else sprintf (daytext, "%d", day); SetTextColor (hdc, pmcci->clr_dayHitext); mcTextOutCenter (hdc, prcItem, daytext);}// draw change daystatic void mcDrawDay (HDC hdc, PMONCALDDATA mc_data, RECT* prcMDay, int newday){ RECT rcPItemDay, rcItemDay; PMCCOLORINFO pmcci; pmcci = (PMCCOLORINFO) mc_data->dwClrData; mcGetCurRect (prcMDay, &rcPItemDay, mc_data); mcUnHilightRect (mc_data, hdc, &rcPItemDay, mc_data->cur_day); mc_data->cur_day = newday; mcGetCurDayPos (mc_data, mc_data->cur_day, &mc_data->cur_line, &mc_data->cur_WeekDay); mcGetCurRect (prcMDay, &rcItemDay, mc_data); mcHilightRect (mc_data, hdc, &rcItemDay, mc_data->cur_day); }// draw month day areastatic void mcDrawMonthDay (HDC hdc, RECT* prcMDay, PMONCALDDATA mc_data){ int i, WeekDayPM = 0, LineIndex = 0; int mdaypm = 0, MonLenPM, mdaynm; int iWeekDay = 0; char chMonthDay[3]; RECT rcMonthDay; PMCCOLORINFO pmcci; pmcci = (PMCCOLORINFO) mc_data->dwClrData; SetBkColor (hdc, pmcci->clr_daybk); SetTextColor (hdc, pmcci->clr_daytext); for (i = 1; i <= mc_data->monlen; i++) { if (i < 10) sprintf (chMonthDay, " %d", i); else sprintf (chMonthDay, "%d", i); iWeekDay = (mc_data->WeekDay1 + i - 1)%7; rcMonthDay.left = prcMDay->left + iWeekDay*mc_data->item_w; rcMonthDay.right = rcMonthDay.left + mc_data->item_w; LineIndex = (mc_data->WeekDay1 + i - 1)/7; rcMonthDay.top = prcMDay->top + mc_data->item_h*LineIndex; rcMonthDay.bottom = rcMonthDay.top + mc_data->item_h; if (i == mc_data->cur_day) { SetBkColor (hdc, pmcci->clr_dayHibk); SetTextColor (hdc, pmcci->clr_dayHitext); SetBrushColor (hdc, pmcci->clr_dayHibk); FillBox (hdc, rcMonthDay.left, rcMonthDay.top, mc_data->item_w, mc_data->item_h); SetPenColor(hdc, GetWindowElementColor(FGC_MENUITEM_FRAME)); Rectangle (hdc, rcMonthDay.left, rcMonthDay.top, rcMonthDay.left+mc_data->item_w-1 , rcMonthDay.top+mc_data->item_h-1); } mcTextOutCenter (hdc, &rcMonthDay, chMonthDay); if (i == mc_data->cur_day) { SetBkColor (hdc, pmcci->clr_daybk); SetTextColor (hdc, pmcci->clr_daytext); } } SetTextColor (hdc, pmcci->clr_trailingtext); LineIndex += (iWeekDay+1)/7; iWeekDay = (iWeekDay + 1)%7; mdaynm = 1; while (LineIndex <= 5) { if (mdaynm < 10) sprintf (chMonthDay, " %d", mdaynm); else sprintf (chMonthDay, "%d", mdaynm); rcMonthDay.left = prcMDay->left + iWeekDay*mc_data->item_w; rcMonthDay.right = rcMonthDay.left + mc_data->item_w; rcMonthDay.top = prcMDay->top + mc_data->item_h*LineIndex; rcMonthDay.bottom = rcMonthDay.top + mc_data->item_h; mcTextOutCenter (hdc, &rcMonthDay, chMonthDay); mdaynm++; iWeekDay++; if (iWeekDay == 7) { iWeekDay = 0; LineIndex++; } } WeekDayPM = mc_data->WeekDay1 - 1; if (WeekDayPM >= 0) { rcMonthDay.top = prcMDay->top; rcMonthDay.bottom = rcMonthDay.top + mc_data->item_h; rcMonthDay.left = prcMDay->left + WeekDayPM*mc_data->item_w; rcMonthDay.right = rcMonthDay.left + mc_data->item_w; MonLenPM = GetPMonLen (mc_data->cur_year, mc_data->cur_month); mdaypm = MonLenPM; } while (WeekDayPM >= 0) { sprintf (chMonthDay, "%d", mdaypm); mcTextOutCenter (hdc, &rcMonthDay, chMonthDay); OffsetRect(&rcMonthDay, -mc_data->item_w, 0); mdaypm--; WeekDayPM--; }}// draw change monthstatic void mcDrawMonth (HWND hWnd, HDC hdc, PMONCALDDATA mc_data, RECT* prcMDay, RECT* prcMonth, int newmonth){ if (newmonth > 12) mc_data->cur_month = 12; else if (newmonth < 1) { mc_data->cur_month = 1; } else mc_data->cur_month = newmonth; mc_data->monlen = GetMonLen (mc_data->cur_year, mc_data->cur_month); while (mc_data->cur_day > mc_data->monlen) { mc_data->cur_day--; } mc_data->WeekDay1 = GetWeekDay(mc_data->cur_year, mc_data->cur_month, 1); mcGetCurDayPos (mc_data, mc_data->cur_day, &mc_data->cur_line, &mc_data->cur_WeekDay); InvalidateRect (hWnd, prcMonth, FALSE); InvalidateRect (hWnd, prcMDay, FALSE);}static void mcDrawYear (HWND hWnd, HDC hdc, PMONCALDDATA mc_data, RECT* prcMDay, RECT* prcYear, int newyear){ if (newyear < 1902) mc_data->cur_year = 1902; else mc_data->cur_year = newyear; mc_data->monlen = GetMonLen (mc_data->cur_year, mc_data->cur_month); while (mc_data->cur_day > mc_data->monlen) { mc_data->cur_day--; } mc_data->WeekDay1 = GetWeekDay(mc_data->cur_year, mc_data->cur_month, 1); mcGetCurDayPos (mc_data, mc_data->cur_day, &mc_data->cur_line, &mc_data->cur_WeekDay); InvalidateRect (hWnd, prcYear, FALSE); InvalidateRect (hWnd, prcMDay, FALSE);}static const char *chMon_EL[] = {"January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};static const char *chMon_ES[] = {"Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec"};static const char *chMon_C[] = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};static const char *chWeek_C[] = {"日", "一", "二", "三", "四", "五", "六"}; static const char *chWeek_E[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};static const char *chWeek_E_S[] = {"S", "1", "2", "3", "4", "5", "6"};// draw the whole calendarstatic void mcDrawCalendar (HWND hWnd, HDC hdc, PMONCALDDATA mc_data){ RECT rcClient, rcMonth, rcYear, rcMDay; RECT rcAML, rcAMR, rcAYL, rcAYR; DWORD dwStyle;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -