Win32 DateTime_SetMonthCalColor 似乎不起作用 [英] Win32 DateTime_SetMonthCalColor seems not work

查看:24
本文介绍了Win32 DateTime_SetMonthCalColor 似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改日期时间选择器控件的日历的背景颜色.根据 windows SDK,有一个 marco DateTime_SetMonthCalColor.

DateTime_SetMonthCalColor(hwnd,MSC_BACKGROUND,RGB(0,120,250));

但是不行.我在 windows control spy 上这样做,发送相同的消息 DTM_SETMCCOLOR ,也没有效果.怎么了?

解决方案

MCSC_BACKGROUND 设置

每次打开下拉菜单时都会创建月历控件.为了调整它的大小,日期时间选择器控件的父窗口必须处理 DTN_DROPDOWN 通知,就像下面的最小示例一样.

HWND CreateDTC(HWND hWnd){INITCOMMONCONTROLSEX icex = { sizeof(icex), ICC_DATE_CLASSES };InitCommonControlsEx(&icex);return CreateWindowExW(0, DATETIMEPICK_CLASS, LDateTime",WS_BORDER |WS_CHILD |WS_VISIBLE |DTS_SHOWNONE,10, 10, 150, 25, hWnd, nullptr, hInst, nullptr);}LRESULT 回调 WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){静态 HWND hDTC = nullptr;开关(味精){案例 WM_CREATE:hDTC = CreateDTC(hWnd);DateTime_SetMonthCalColor(hDTC, MCSC_BACKGROUND, RGB(0, 120, 250));//蓝色DateTime_SetMonthCalColor(hDTC, MCSC_MONTHBK, RGB(120, 250, 0));//绿色休息;案例 WM_NOTIFY:开关(((LPNMHDR)lParam)->代码){案例 DTN_DROPDOWN:HWND hMC = DateTime_GetMonthCal(hDTC);矩形 rc;MonthCal_GetMinReqRect(hMC, &rc);移动窗口(hMC, 0, 0, (5 * rc.right)/2, (3 * rc.bottom)/2, FALSE);休息;}休息;//...}返回0;}

I want to change the background color of a datetimepicker contorl's calender. According windows SDK ,there's a marco DateTime_SetMonthCalColor.

DateTime_SetMonthCalColor(hwnd,MSC_BACKGROUND,RGB(0,120,250));

But not work. I do this on windows control spy,send the same message DTM_SETMCCOLOR , no effect either. So what's wrong ?

解决方案

MCSC_BACKGROUND sets the background color of the month calendar control itself, which only shows when the dropdown is resized to more than the default single month. The background of individual months is set with MCSC_MONTHBK instead.

The month calendar control gets created each time the dropdown is opened. In order to resize it, the parent window of the date-time picker control must process the DTN_DROPDOWN notification, like in the minimal example below.

HWND CreateDTC(HWND hWnd)
{
    INITCOMMONCONTROLSEX icex = { sizeof(icex), ICC_DATE_CLASSES };
    InitCommonControlsEx(&icex);

    return CreateWindowExW(0, DATETIMEPICK_CLASS, L"DateTime",
                           WS_BORDER | WS_CHILD | WS_VISIBLE | DTS_SHOWNONE,
                           10, 10, 150, 25, hWnd, nullptr, hInst, nullptr);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HWND hDTC = nullptr;

    switch(msg)
    {
    case WM_CREATE:
        hDTC = CreateDTC(hWnd);
        DateTime_SetMonthCalColor(hDTC, MCSC_BACKGROUND, RGB(0, 120, 250)); // blue
        DateTime_SetMonthCalColor(hDTC, MCSC_MONTHBK, RGB(120, 250, 0));    // green
        break;

    case WM_NOTIFY:
        switch(((LPNMHDR)lParam)->code)
        {
        case DTN_DROPDOWN:
            HWND hMC = DateTime_GetMonthCal(hDTC);
            RECT rc;
            MonthCal_GetMinReqRect(hMC, &rc);
            MoveWindow(hMC, 0, 0, (5 * rc.right) / 2, (3 * rc.bottom) / 2, FALSE);
            break;
        }
        break;
    //...
    }
    return 0;
}

这篇关于Win32 DateTime_SetMonthCalColor 似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆