日历控件的效果如下所示:
实现这样的效果方法如下所示:
1、vs中拖入picture Control控件:
2、头文件中声明
CBCGPCalendar m_wndCalendarCtrl;
3、实现文件中:
BOOL CBCGCalendarDlg::OnInitDialog()
{
CBCGPDialog::OnInitDialog();
// TODO: Add extra initialization here
m_wndCalendarCtrl.CreateOnPlaceHolder(this, IDC_CALENDARLOCATION, (UINT)-1, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP);
m_wndCalendarCtrl.EnableVisualManagerStyle(IsVisualManagerStyle());
m_wndCalendarCtrl.SetSingleMonthMode();
COleDateTime today = COleDateTime::GetCurrentTime();
//设置颜色
{
int i = 0;
static int daysMarked[] = { 1, 8, 10, 15, 25, 28 };
CArray<DATE, DATE&> arMarkedDates;
for (i = 0; i < sizeof(daysMarked) / sizeof(int); i++)
{
COleDateTime dayBold(today.GetYear(), today.GetMonth(), daysMarked[i], 0, 0, 0);
arMarkedDates.Add(dayBold.m_dt);
}
m_wndCalendarCtrl.MarkDates(arMarkedDates);
static int daysColor1[] = { 4, 5, 6 };
for (i = 0; i < sizeof(daysColor1) / sizeof(int); i++)
{
COleDateTime dayColor(today.GetYear(), today.GetMonth(), daysColor1[i], 0, 0, 0);
m_wndCalendarCtrl.SetDateColor(dayColor, RGB(255, 69, 0));
}
static int daysColor2[] = { 19, 20, 23 };
for (i = 0; i < sizeof(daysColor2) / sizeof(int); i++)
{
COleDateTime dayColor(today.GetYear(), today.GetMonth(), daysColor2[i], 0, 0, 0);
m_wndCalendarCtrl.SetDateColor(dayColor, RGB(30, 144, 255));
}
}
m_wndCalendarCtrl.EnableTodayButton(true);
m_wndCalendarCtrl.EnableWeekNumbers(true);
return TRUE; // return TRUE unless you set the focus to a control
}
具体点击选择之类的请具体参见类