⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monthcalendar.c

📁 minigui的开发程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/*** $Id: monthcalendar.c,v 1.26 2003/11/12 10:17:15 snig Exp $**** monthcalendar.c: the month calendar Control module.**** Copyright (C) 2001, Zhong Shuyi** Copyright (C) 2002, 2003 Feynman Software**** Create date: 2001/01/02*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//* Modify records:****   Who             When        Where       For What                Status**-----------------------------------------------------------------------------**  Wei Yongming    2001/02/07  BluePoint   Do some code clean up.  Done.**  snig            2001/02/22  BluePoint    Add tab month             Done.**  snig            2001/05/24  BluePoint   Fix lang style bug      Done.**** TODO:*/ #include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#ifdef __MINIGUI_LIB__    #include "common.h"    #include "minigui.h"    #include "gdi.h"    #include "window.h"    #include "control.h"#else    #include <minigui/common.h>    #include <minigui/minigui.h>    #include <minigui/gdi.h>    #include <minigui/window.h>    #include <minigui/control.h>#endif#ifdef _EXT_CTRL_MONTHCAL#include "mgext.h"#include "monthcalendar.h"#define MINWNDRECT_W    120#define MINWNDRECT_H    110#define DATECAP_H(hwnd)        (GetWindowFont(hwnd)->size+8)#define MONFIELD_W       50#define YEARFIELD_W      50#define WEEKFIELD_W      30#define WEEKFIELD_H(hwnd)      (GetWindowFont(hwnd)->size+4)#define WEEK_BORDER      5#define WEEK_VBORDER1    2#define WEEK_VBORDER2    3#define TEXT_BORDER      5#define LINE_D           2#define ARROW_H          7#define ARROW_W          (ARROW_H+1)/2#define ARROWRECT_W      (ARROW_W+4)#define HEIGHT_BORDER    6#define MON_WIDTH        60#define MON_HEIGHT       14#define MON_BORDER       15#define YEAR_WIDTH       40#define YEAR_HEIGHT      14//#define YEAR_HEIGHT    18#define YEAR_BORDER      15#define ARROW_BORDER     10// color info#define MCCLR_DF_TITLEBK        PIXEL_lightgray#define MCCLR_DF_TITLETEXT        PIXEL_black#define MCCLR_DF_ARROW            PIXEL_black#define MCCLR_DF_ARROWHIBK        PIXEL_lightwhite#define MCCLR_DF_DAYBK            PIXEL_lightwhite#define MCCLR_DF_DAYHIBK        GetWindowElementColor(BKC_MENUITEM_HILITE)#define MCCLR_DF_DAYTEXT        PIXEL_black#define MCCLR_DF_TRAILINGTEXT        PIXEL_lightwhite#define MCCLR_DF_DAYHITEXT        GetWindowElementColor(FGC_MENUITEM_HILITE)#define MCCLR_DF_WEEKCAPTBK        PIXEL_darkblue#define MCCLR_DF_WEEKCAPTTEXT        PIXEL_lightwhitestatic int MonthCalendarCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam);BOOL RegisterMonthCalendarControl (void){    WNDCLASS WndClass;    WndClass.spClassName     = "monthcalendar";    WndClass.dwStyle        = WS_NONE;    WndClass.dwExStyle        = WS_EX_NONE;    WndClass.hCursor        = GetSystemCursor (IDC_ARROW);    WndClass.iBkColor        = PIXEL_lightwhite;    WndClass.WinProc        = MonthCalendarCtrlProc;#if 0    return AddNewControlClass (&WndClass) == ERR_OK;#else    return RegisterWindowClass (&WndClass);#endif}void MonthCalendarControlCleanup (void){#if 0    // do nothing#else    UnregisterWindowClass (CTRL_MONTHCALENDAR);#endif    return;}// -----------------------------------------------------------------------------------// draw 3D frame#if 0static void mcDraw3DMCDownFrame (HDC hdc, int x0, int y0, int x1, int y1,             int fillc){    int left, top, right, bottom;    left = MIN (x0, x1);    top  = MIN (y0, y1);    right = MAX (x0, x1);    bottom = MAX (y0, y1);            SetPenColor (hdc, PIXEL_lightwhite);        MoveTo (hdc, left, bottom);        LineTo (hdc, right, bottom);        LineTo (hdc, right, top);        SetPenColor (hdc, PIXEL_black);        MoveTo (hdc, left, bottom);        LineTo (hdc, left, top);        LineTo (hdc, right+1, top);        left++; top++; right--; bottom--;        SetPenColor (hdc, PIXEL_lightwhite);        MoveTo (hdc, left, bottom);        LineTo (hdc, right, bottom);        LineTo (hdc, right, top);        SetPenColor (hdc, PIXEL_black);        MoveTo (hdc, left, bottom);        LineTo (hdc, left, top);        LineTo (hdc, right+1, top);    if (fillc > 0) {        SetBrushColor (hdc, fillc);        FillBox (hdc, left + 1, top + 1, right - left - 1 , bottom - top - 1);     }}#endif// draw page arrowstatic void mcDrawPageArrow (PMONCALDDATA mc_data, HDC hdc, RECT* prcArrow,                                 BOOL bFaceR, BOOL bHilight){    int arrow_w, arrow_h = ARROW_H;    int line_x, line_h, line_y;    int stepx;    int rc_w, rc_h;    PMCCOLORINFO pmcci;    pmcci = (PMCCOLORINFO) mc_data->dwClrData;    arrow_w = (arrow_h + 1)/2;    rc_w = prcArrow->right - prcArrow->left;    rc_h = prcArrow->bottom - prcArrow->top;    SetPenColor (hdc, pmcci->clr_arrow);    if (bHilight) {        SetBrushColor (hdc, pmcci->clr_arrowHibk);        FillBox (hdc, prcArrow->left, prcArrow->top, rc_w, rc_h);    }    else {        SetBrushColor (hdc, pmcci->clr_titlebk);        FillBox (hdc, prcArrow->left, prcArrow->top, rc_w, rc_h);    }    line_y = prcArrow->top + (rc_h-arrow_h)/2;    line_h = arrow_h;    if (bFaceR) {        stepx = 1;        line_x = prcArrow->left + (rc_w - arrow_w)/2;    }    else {        stepx = -1;        line_x = prcArrow->right - (rc_w - arrow_w)/2 - 1;    }    while (line_h > 0) {        MoveTo (hdc, line_x, line_y);        LineTo (hdc, line_x, line_y+line_h);        line_x += stepx;        line_y ++;        line_h -= 2;    }}// --------------------------------------------------------------------------static void mcMonthCalendarCleanUp (MONCALDDATA* mc_data){    free ((PMCCOLORINFO) mc_data->dwClrData);    return;}// --------------------------------------------------------------------------// find out whether a year is a leap yearstatic BOOL IsLeapYear (int year){    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return TRUE;    else return FALSE;}// get month length from year and monthstatic int GetMonLen (int year, int month){    int mon_len;    if (month < 1 || month > 12) return -1;    if ((month <= 7 && month % 2 == 1) || (month >= 8 && month % 2 == 0))        mon_len = 31;    else if (month == 2)         if (IsLeapYear (year)) mon_len = 29;        else mon_len = 28;    else        mon_len = 30;    return mon_len;}static int GetYearLen (int year){    int i, year_len = 0;    for (i = 1; i <= 12; i++) {        year_len += GetMonLen (year, i);        }    return year_len;}// get previous month length from year and monthstatic int GetPMonLen (int year, int month){    if (month > 1 && month <= 12) return GetMonLen (year, month - 1);    else if (month == 1) return GetMonLen (year - 1, 12);    else return -1;}static int MyGetWeekDay (int year, int month, int day){    // days from 2036/12/31    int weekday, weekday1 = 3, daylen = 0, i;    if (year < 2037) return -1;    for (i = 2037; i < year; i++) {        daylen += GetYearLen (i);    }    for (i = 1; i < month; i++)    {        daylen += GetMonLen (year, i);    }        daylen += day;    weekday = (weekday1 + daylen) - (int)((weekday1 + daylen) / 7)*7;    return weekday;    }// get weekday from datestatic int GetWeekDay (int year, int month, int day){    struct tm nowday;    if (year < 1902) return -1;    if (month < 1 || month > 12) return -1;    if (day < 1 || day > 31) return -1;        if (year >= 2037) return MyGetWeekDay (year, month, day);    nowday.tm_sec = 0;    nowday.tm_min = 0;    nowday.tm_hour = 0;    nowday.tm_mday = day;    nowday.tm_mon = month-1;    nowday.tm_year = year-1900;    if (mktime(&nowday) == -1) {        fprintf (stderr, "mktime error\n"); //test        return -1;    }    else        return nowday.tm_wday;    }// get line and weekday from date according to weekday1static void mcGetCurDayPos (PMONCALDDATA mc_data, int day, int* pline, int* pWeekDay){    *pWeekDay = (mc_data->WeekDay1 + day - 1) % 7;    *pline = (day + 6 - *pWeekDay - 1)/7;}/*// get line and weekday from datestatic void mcGetDayPos (int year, int month, int day, int* pline, int* pWeekDay)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -