Recently I want to make a calendar control, so I use BCG (www.ttdown.com) CBCGPCalendarbar. However, when you want to make a mouse on the date, the prompt information is a lunar calendar. But very strange, BCG's date control does not support datetimes. The reason, the original: BOOL CBCGPCALENDARBUTTON :: ONTOOLHITTEST (const cwnd * / * pwnd * /, toolinfo * / * pti * /) {return false;} It is also easy to change, and the source code of BCG is changed. But once the BCG is updated, it is necessary to recompile it. It is really trouble. So I want to expand this class through the inheritance of OO.
class CLunarCalendarButton: public CBCGPCalendarButton {DECLARE_SERIAL (CLunarCalendarButton) public: CLunarCalendarButton (): CBCGPCalendarButton () {} CLunarCalendarButton (const COleDateTime & date, BOOL bHighlight = FALSE): CBCGPCalendarButton (date, bHighlight) {} protected: virtual BOOL OnToolHitTest (const CWnd * / * PWND * /, TOOLINFO * PTI);
Implement_serial (Clunarcalendarbutton, Cbcgpcalendarbutton, 1)
Bool Clunarcalendarbutton :: ONTOOLHITTEST (Const CWND * / * PWND * /, ToolInfo * PTI) {IF (PTI == NULL) Return False;
Cstring str; str = _t ("Lunar Calendar:"); Clunarcalendarbar :: FormatLunardate (m_calendar, str);
PTI-> lpsztext = (lptstr) :: Calloc ((str.getLength () 1), sizeof (tchar)); _TCSCPY (PTI-> LPSZTEXT, STR);
Return True;}
But what is the problem? Replacing this Button to CBCGPCALENDARBUTTON on the original control? Cbcgpcalendarbar has no interface to make users build their own Button. Comparative finally to "dirty" method, by covering the virtual function: class CLunarCalendarBar: public CBCGPCalendarBar {...... protected: virtual void Rebuild (); virtual CBCGPToolbarButton * createDateButton (void);}; CBCGPToolbarButton * CLunarCalendarBar :: CreateDateButton (void) {return new clunarcalendarbutton ();
Void Clunarcalendarbar :: rebuild () {cbcgpcalendarbar :: rebuild ();
INT i = 0; for (i = 0;! m_buttons.isempty () && i <42; i) {cbcgptoolbarbutton * Pbutton = (cbcgptoolbarbutton *) m_buttons.removetail (); assert_valid (pbutton); if (Pbutton! = NULL) {pbutton-> oncancelmode (); delete pbutton;}} for (i = 0; i <42; i ) INSERTBUTTON (CREATEDATEBUTTON ());
Setdate (m_dateselected);} The 42 buttons established by the original CbcGpcalendarbar are removed, replace it with your own button.