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

📄 monthcal.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 3 页
字号:
                if (MonthCalGetDayRect(infoPtr,
                                       sc.NewDay,
                                       &rcUpdate))
                {
                    InvalidateRect(infoPtr->hSelf,
                                   &rcUpdate,
                                   TRUE);
                }
            }

            Ret = TRUE;
        }
    }

    return Ret;
}

static VOID
MonthCalSetLocalTime(IN PMONTHCALWND infoPtr,
                     OUT SYSTEMTIME *Time)
{
    NMMCCAUTOUPDATE au;
    SYSTEMTIME LocalTime = {0};

    GetLocalTime(&LocalTime);

    au.SystemTime = LocalTime;
    if (!MonthCalNotifyControlParent(infoPtr,
                                     MCCN_AUTOUPDATE,
                                     &au))
    {
        if (MonthCalSetDate(infoPtr,
                            LocalTime.wDay,
                            LocalTime.wMonth,
                            LocalTime.wYear))
        {
            infoPtr->Changed = FALSE;
        }
    }

    /* kill the day timer */
    if (infoPtr->DayTimerSet)
    {
        KillTimer(infoPtr->hSelf,
                  ID_DAYTIMER);
        infoPtr->DayTimerSet = FALSE;
    }

    /* setup the new day timer */
    MonthCalSetupDayTimer(infoPtr);

    if (Time != NULL)
    {
        *Time = LocalTime;
    }
}

static VOID
MonthCalRepaintDay(IN PMONTHCALWND infoPtr,
                   IN WORD Day)
{
    RECT rcCell;

    if (MonthCalGetDayRect(infoPtr,
                           Day,
                           &rcCell))
    {
        InvalidateRect(infoPtr->hSelf,
                       &rcCell,
                       TRUE);
    }
}

static VOID
MonthCalPaint(IN PMONTHCALWND infoPtr,
              IN HDC hDC,
              IN LPRECT prcUpdate)
{
    LONG x, y;
    RECT rcCell;
    COLORREF crOldText, crOldCtrlText = CLR_INVALID;
    HFONT hOldFont;
    INT iOldBkMode;

#if MONTHCAL_CTRLBG != MONTHCAL_DISABLED_CTRLBG
    if (!infoPtr->Enabled)
    {
        FillRect(hDC,
                 prcUpdate,
                 GetSysColorBrush(MONTHCAL_DISABLED_CTRLBG));
    }
#endif

    iOldBkMode = SetBkMode(hDC,
                           TRANSPARENT);
    hOldFont = (HFONT)SelectObject(hDC,
                                   infoPtr->hFont);

    for (y = prcUpdate->top / infoPtr->CellSize.cy;
         y <= prcUpdate->bottom / infoPtr->CellSize.cy && y < 7;
         y++)
    {
        rcCell.top = y * infoPtr->CellSize.cy;
        rcCell.bottom = rcCell.top + infoPtr->CellSize.cy;

        if (y == 0)
        {
            RECT rcHeader;

            /* paint the header */
            rcHeader.left = prcUpdate->left;
            rcHeader.top = rcCell.top;
            rcHeader.right = prcUpdate->right;
            rcHeader.bottom = rcCell.bottom;

            FillRect(hDC,
                     &rcHeader,
                     infoPtr->hbHeader);

            crOldText = SetTextColor(hDC,
                                     GetSysColor(infoPtr->Enabled ? MONTHCAL_HEADERFG : MONTHCAL_DISABLED_HEADERFG));

            for (x = prcUpdate->left / infoPtr->CellSize.cx;
                 x <= prcUpdate->right / infoPtr->CellSize.cx && x < 7;
                 x++)
            {
                rcCell.left = x * infoPtr->CellSize.cx;
                rcCell.right = rcCell.left + infoPtr->CellSize.cx;

                /* write the first letter of each weekday */
                DrawTextW(hDC,
                          &infoPtr->Week[x],
                          1,
                          &rcCell,
                          DT_SINGLELINE | DT_NOPREFIX | DT_CENTER | DT_VCENTER);
            }

            SetTextColor(hDC,
                         crOldText);
        }
        else
        {
            if (crOldCtrlText == CLR_INVALID)
            {
                crOldCtrlText = SetTextColor(hDC,
                                             infoPtr->Enabled ? MONTHCAL_CTRLFG : MONTHCAL_DISABLED_CTRLFG);
            }

            for (x = prcUpdate->left / infoPtr->CellSize.cx;
                 x <= prcUpdate->right / infoPtr->CellSize.cx && x < 7;
                 x++)
            {
                UINT Day = infoPtr->Days[y - 1][x];

                rcCell.left = x * infoPtr->CellSize.cx;
                rcCell.right = rcCell.left + infoPtr->CellSize.cx;

                /* write the day number */
                if (Day != 0 && Day < 100)
                {
                    WCHAR szDay[3];
                    INT szDayLen;
                    RECT rcText;
                    SIZE TextSize;

                    szDayLen = swprintf(szDay,
                                         L"%lu",
                                         Day);

                    if (GetTextExtentPoint32W(hDC,
                                              szDay,
                                              szDayLen,
                                              &TextSize))
                    {
                        RECT rcHighlight = {0};

                        rcText.left = rcCell.left + (infoPtr->CellSize.cx / 2) - (TextSize.cx / 2);
                        rcText.top = rcCell.top + (infoPtr->CellSize.cy / 2) - (TextSize.cy / 2);
                        rcText.right = rcText.left + TextSize.cx;
                        rcText.bottom = rcText.top + TextSize.cy;

                        if (Day == infoPtr->Day)
                        {
                            rcHighlight = rcText;

                            InflateRect(&rcHighlight,
                                        GetSystemMetrics(SM_CXFOCUSBORDER),
                                        GetSystemMetrics(SM_CYFOCUSBORDER));

                            if (!FillRect(hDC,
                                          &rcHighlight,
                                          infoPtr->hbSelection))
                            {
                                goto FailNoHighlight;
                            }

                            /* highlight the selected day */
                            crOldText = SetTextColor(hDC,
                                                     GetSysColor(infoPtr->Enabled ? MONTHCAL_SELFG : MONTHCAL_DISABLED_SELFG));
                        }
                        else
                        {
FailNoHighlight:
                            /* don't change the text color, we're not highlighting it... */
                            crOldText = CLR_INVALID;
                        }

                        TextOutW(hDC,
                                 rcText.left,
                                 rcText.top,
                                 szDay,
                                 szDayLen);

                        if (Day == infoPtr->Day && crOldText != CLR_INVALID)
                        {
                            if (infoPtr->HasFocus && infoPtr->Enabled && !(infoPtr->UIState & UISF_HIDEFOCUS))
                            {
                                COLORREF crOldBk;

                                crOldBk = SetBkColor(hDC,
                                                     GetSysColor(infoPtr->Enabled ? MONTHCAL_SELBG : MONTHCAL_DISABLED_SELBG));

                                DrawFocusRect(hDC,
                                              &rcHighlight);

                                SetBkColor(hDC,
                                           crOldBk);
                            }

                            SetTextColor(hDC,
                                         crOldText);
                        }
                    }
                }
            }
        }
    }

    if (crOldCtrlText != CLR_INVALID)
    {
        SetTextColor(hDC,
                     crOldCtrlText);
    }

    SetBkMode(hDC,
              iOldBkMode);
    SelectObject(hDC,
                 (HGDIOBJ)hOldFont);
}

static HFONT
MonthCalChangeFont(IN PMONTHCALWND infoPtr,
                   IN HFONT hFont,
                   IN BOOL Redraw)
{
    HFONT hOldFont = infoPtr->hFont;
    infoPtr->hFont = hFont;

    if (Redraw)
    {
        InvalidateRect(infoPtr->hSelf,
                       NULL,
                       TRUE);
    }

    return hOldFont;
}

static WORD
MonthCalPtToDay(IN PMONTHCALWND infoPtr,
                IN INT x,
                IN INT y)
{
    WORD Ret = 0;

    if (infoPtr->CellSize.cx != 0 && infoPtr->CellSize.cy != 0 &&
        x >= 0 && y >= 0)
    {
        x /= infoPtr->CellSize.cx;
        y /= infoPtr->CellSize.cy;

        if (x < 7 && y != 0 && y < 7)
        {
            Ret = (WORD)infoPtr->Days[y - 1][x];
        }
    }

    return Ret;
}

static LRESULT CALLBACK
MonthCalWndProc(IN HWND hwnd,
                IN UINT uMsg,
                IN WPARAM wParam,
                IN LPARAM lParam)
{
    PMONTHCALWND infoPtr;
    LRESULT Ret = 0;

    infoPtr = (PMONTHCALWND)GetWindowLongPtrW(hwnd,
                                              0);

    if (infoPtr == NULL && uMsg != WM_CREATE)
    {
        goto HandleDefaultMessage;
    }

    switch (uMsg)
    {
#if MONTHCAL_CTRLBG != MONTHCAL_DISABLED_CTRLBG
        case WM_ERASEBKGND:
            Ret = !infoPtr->Enabled;
            break;
#endif

        case WM_PAINT:
        case WM_PRINTCLIENT:
        {
            if (infoPtr->CellSize.cx != 0 && infoPtr->CellSize.cy != 0)
            {
                PAINTSTRUCT ps;
                HDC hDC;

                if (wParam != 0)
                {
                    if (!GetUpdateRect(hwnd,
                                       &ps.rcPaint,
                                       TRUE))
                    {
                        break;
                    }
                    hDC = (HDC)wParam;
                }
                else
                {
                    hDC = BeginPaint(hwnd,
                                     &ps);
                    if (hDC == NULL)
                    {
                        break;
                    }
                }

                MonthCalPaint(infoPtr,
                              hDC,
                              &ps.rcPaint);

                if (wParam == 0)
                {
                    EndPaint(hwnd,
                             &ps);
                }
            }
            break;
        }

        case WM_LBUTTONDBLCLK:
        case WM_LBUTTONDOWN:
        {
            WORD SelDay;

⌨️ 快捷键说明

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