// Calendar.cpp : implementation file #include "stdafx.h" #include "Calendar.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif BEGIN_MESSAGE_MAP(CCalendar, CButton) //{{AFX_MSG_MAP(CCalendar) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() const BYTE CCalendar::GapWidth =4; const BYTE CCalendar::GapHeight =4; const BYTE CCalendar::ButtonsAcross=7; const BYTE CCalendar::ButtonsDown =6; const BYTE CCalendar::MaxButtons =ButtonsAcross*ButtonsDown; void CCalendar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC& dc=*CDC::FromHandle(lpDrawItemStruct->hDC); CRect Rect(lpDrawItemStruct->rcItem); dc.DrawEdge(&Rect, EDGE_SUNKEN, BF_RECT); TitleHeight=2*dc.GetTextExtent("_^~g").cy; CRect TitleRect(Rect); Rect.top+=TitleHeight+GapHeight; //Rect is now the Button space TitleRect.bottom=Rect.top; TitleRect.top+=GapHeight; if(!Rects) { Rects=new CRect[MaxButtons]; ButtonWidth =(Rect.Width ()-(ButtonsAcross+1)*GapWidth )/ButtonsAcross; ButtonHeight=(Rect.Height()-(ButtonsDown +1)*GapHeight)/ButtonsDown; for(BYTE i=0; iScreenToClient(&Wnd); Wnd.right =Rect.left+Wnd.left+ButtonsAcross*(ButtonWidth +GapWidth )+GapWidth ; Wnd.bottom=Rect.top +Wnd.top +ButtonsDown *(ButtonHeight+GapHeight)+GapHeight; MoveWindow(&Wnd); return; //The MoveWindow will force a Redraw so we don't need to go on. } const CString Days[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; for(BYTE i=0; i<7; ++i) { CRect Rect(Rects[i]); Rect.top =TitleRect.top; Rect.bottom=TitleRect.bottom; dc.DrawText(Days[i], &Rect, DT_CENTER | DT_NOCLIP | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE); dc.DrawEdge(&Rect, EDGE_ETCHED, BF_RECT); } CString S; for(i=0; i