图一、日历控件显示效果 |
图二、显示多个月份的日历控件 |
图三、显示月份列表 |
图四、更改日历控件的年份 |
// Exercise1Dlg.h : header file class CExercise1Dlg : public CDialog { // Construction public: CExercise1Dlg(CWnd* pParent = NULL); // standard constructor private: CMonthCalCtrl *ctlCalendar; }; |
CExercise1Dlg::CExercise1Dlg(CWnd* pParent /*=NULL*/) : CDialog(CExercise1Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CExercise1Dlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); ctlCalendar = new CMonthCalCtrl; } ///////////////////////////////////////////////////////////////////////////// // CExercise1Dlg message handlers BOOL CExercise1Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here ctlCalendar->Create(WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_BORDER,CPoint(20, 20), this, 0x224); return TRUE; // return TRUE unless you set the focus to a control } |
COLORREF SetColor(int nRegion, COLORREF ref); |
图五、更改控件的标题条颜色 |
BOOL SetFirstDayOfWeek(int iDay, int* lpnOld = NULL); |
Value | Weekday |
0 | Monday |
1 | Tuesday |
2 | Wednesday |
3 | Thursday |
4 | Friday |
5 | Saturday |
6 | Sunday |
int GetFirstDayOfWeek(BOOL* pbLocal = NULL) const; |
图六、更改日历控件的日期显示颜色 |
图七、不显示"今日"标签的日历控件 |
BOOL CExercise1Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here ctlCalendar->Create(WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_BORDER | MCS_NOTODAY, CPoint(20, 20), this, 0x224); return TRUE; // return TRUE unless you set the focus to a control } |
BOOL CExercise1Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here ctlCalendar->Create(WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_BORDER | MCS_NOTODAYCIRCLE, CPoint(20, 20), this, 0x224); return TRUE; // return TRUE unless you set the focus to a control } |
BOOL GetCurSel(COleDateTime& refDateTime) const; BOOL GetCurSel(CTime& refDateTime) const; BOOL GetCurSel(LPSYSTEMTIME pDateTime) const; |
void CExercise1Dlg::OnRetrieveBtn() { // TODO: Add your control notification handler code here UpdateData(); CTime tme = this->m_dtpCurrent.GetCurrentTime(); this->m_Result.Format("%s", tme.Format("%A, %B %d, %Y")); UpdateData(FALSE); } |
BOOL CExercise1Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here ctlCalendar->Create(WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_BORDER | MCS_NOTODAYCIRCLE | MCS_MULTISELECT, CPoint(20, 20), this, 0x224); return TRUE; // return TRUE unless you set the focus to a control } |
图八、显示多选择日期的日历控件 |
BOOL SetSelRange(const COleDateTime& pMinRange, const COleDateTime& pMaxRange); BOOL SetSelRange(const CTime& pMinRange, const CTime& pMaxRange); BOOL SetSelRange(const LPSYSTEMTIME pMinRange, const LPSYSTEMTIME pMaxRange); |
BOOL SetRange(const COleDateTime* pMinRange, const COleDateTime* pMaxRange); BOOL SetRange(const CTime* pMinRange, const CTime* pMaxRange); BOOL SetRange(const LPSYSTEMTIME pMinRange, const LPSYSTEMTIME pMaxRange); |