⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendar_framewnd.h

📁 一个完整的桌面日历程序
💻 H
字号:
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																					-
// - File:			calendar_framewnd.h.																												-
// -																																					-
// - Contents: 		Interface of class CCalFrameWnd.																									-
// -																																					-
// - Purpose:  		-																																	-
// -																																					-
// - Remarks:    	-																																	-
// -																																					-
// - Originator: 	Michael Mogensen, MM-IT Consult 2003.																								-
// -																																					-
// - Compiler:		MS Visual C++ ver6.0.																											    -
// -																																					-
// - Period:		29.04.03 - 00.00.00.																											    -
// -																																					-
// - Version:		1.21. 																																-
// -																																					-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
#define _UNICODE

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Header(s).																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "afxtemplex.h"

#include "calendar.rh"
#include "fileinfo.hpp"
#include "generic.h"
#include "geometryex.hpp"
#include "keyboard.hpp"
#include "timeex.hpp"
#include "windowex.hpp"

#include "menuxp.h"

#include "calendar_btn.h"
#include "calendar_edit.h"

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - CNote.																																				-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
class CNote
{
	protected:
		// 0. Data. (alphabetical).
		CString m_cstrName;
		// 4. Slaves. (alphabetical).
		inline const int GetYear() const
		{
			try
			{
				const CString cstrSub(m_cstrName.Left(4));
				return(_ttoi((LPCTSTR)cstrSub));
			}
			catch(...)
			{
				TRACE(_T("Bad inline const int CNote::GetYear(...)\n"));
			}
			// Error.
			return 0;
		}
		inline const int GetMonth() const
		{
			try
			{
				const CString cstrSub(m_cstrName.Mid(((m_cstrName[5] == TCHAR('0')) ? 6 : 5), 2));
				return(_ttoi((LPCTSTR)cstrSub));
			}
			catch(...)
			{
				TRACE(_T("Bad inline const int CNote::GetMonth(...)\n"));
			}
			// Error.
			return 0;
		}
		inline const int GetDay() const
		{
			try
			{
				const CString cstrSub(m_cstrName.Right(((m_cstrName[8] == TCHAR('0')) ? 1 : 2)));
				return(_ttoi((LPCTSTR)cstrSub));
			}
			catch(...)
			{
				TRACE(_T("Bad inline const int CNote::GetDay(...)\n"));
			}
			// Error.
			return 0;
		}
	public:
		// 1. Object. (alphabetical).
		inline CNote() : 
			m_cstrName(_T("0000.00.00"))
			{}
		inline CNote(const CString &cstrName)
		{ m_cstrName = cstrName; }
		inline CNote(const CNote &Note)
		{ m_cstrName = Note.m_cstrName; }
		// 4. Slaves. (alphabetical).
		inline const CNote& operator=(const CNote &Note)
		{
			m_cstrName = Note.m_cstrName;
			return *this;
		}
		// Operator <.
		inline const bool operator<(const CNote &Note) const
		{ return(m_cstrName < Note.m_cstrName); }
		// Operator <=.
		inline const bool operator<=(const CNote &Note) const
		{ return(m_cstrName <= Note.m_cstrName); }
		// Operator ==.
		inline const bool operator==(const CNote &Note) const
		{ return(m_cstrName == Note.m_cstrName); }
		// Operator >=.
		inline const bool operator>=(const CNote &Note) const
		{ return(m_cstrName >= Note.m_cstrName); }
		// Operator >.
		inline const bool operator>(const CNote &Note) const
		{ return(m_cstrName > Note.m_cstrName); }
		//
		inline const CString GetName() const
		{ return m_cstrName; }
		inline const CTimeEx GetTime() const
		// Return time after extracting year, month and day from name string (YYYY.MM.DD).
		{
			try
			{
				// Establish time.
				return(CTimeEx(GetYear(), GetMonth(), GetDay()));
			}
			catch(...)
			{
				TRACE(_T("Bad inline const CTimeEx CNote::GetTime(...)\n"));
				return(CTimeEx());
			}
		}
		inline const bool IsValid() const
		{
			bool bResult = false;
			try
			{
				if(m_cstrName.GetLength() == 10 && 
				   m_cstrName.CompareNoCase(_T("0000.00.00")) != 0)
				{
					const int iYear = GetYear(), 
							  iMonth = GetMonth(), 
							  iDay = GetDay();
					if((iYear >= I_YEAR2DISPLAY_MIN) && 
					   (iYear <= I_YEAR2DISPLAY_MAX) && 
					   (iMonth >= 1) && 
					   (iMonth <= 12))
					{
						CTimeEx t(iYear, iMonth, 1); // Must be an OK date.
						if((iDay >= 1) && 
						   (iDay <= t.GetMonth_Length(iMonth)))
							bResult = true;
					}
				}
			}
			catch(...)
			{
				TRACE(_T("Bad inline const bool IsValid() const\n"));
			}
			//TRACE(_T("Date: %s is %s\n"), m_cstrName, (bResult ? _T("valid") : _T("invalid")));
			return bResult;
		}
};

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - CCalFrameWnd.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
class CCalFrameWnd : public CFrameWnd
{
	public:
		// 1. Object. (alphabetical).
		CCalFrameWnd(LPCTSTR lpszTitleEx = I_CONST_TITLE);
		virtual ~CCalFrameWnd();
		// 4. Slaves. (alphabetical).
		const CRectEx CalcDimension();
		const CRectEx CalcDimension_Inner();
		const CSizeEx CalcEdgeDimension();
	protected:
		// 0. Data. (alphabetical).
		bool m_bDoAutoHide, 
			 m_bDoAutoUpdateTime, 
			 m_bShowHints;
		class CCalendar
		{
			public:
				// 0. Data. (alphabetical).
				enum EAction { eNothing, eSave, eLoad };
				CSingletonArrayEx<CNote, CNote> *m_pArray_Notes;
				// 1. Object. (alphabetical).
				CCalendar(CCalFrameWnd*);
				virtual ~CCalendar();
				// 4. Slaves. (alphabetical).
				inline CCalBtn_Radio* GetActiveBtn_DayNew()
				{ return m_pBtn_Active_DayNew; }
				inline CCalBtn_Radio* GetActiveBtn_DayOld()
				{ return m_pBtn_Active_DayOld; }
				const bool BrowseBtn_EnableNote_Next();
				const bool BrowseBtn_EnableNote_Previous();
				const CString GetCopyrightText();
				const void GetRepresentation(CShadowDC&);
				const void Go2_SpecificDay();
				const void Go2_Today();
				const bool Hint_PFTag_CF(const CString&);
				const void Hint_PFTag_Remove(CString&);
				const void Hint_PFTag_Set(CString&, BOOL);
				const bool 
					Note_Delete(const CString &cstrFileEx = CString(_T("")));
				const void 
					Note_EditChange();
				const void 
					Note_EditUpdate();
				const bool 
					Note_Exist(const CString &cstrFileEx = CString(_T("")));
				const CString 
					Note_GetBeginning(const CString&, const int iChars2GrabEx = 30);
				const CString 
					Note_GetName(CCalBtn_Radio *const);
				const CString 
					Note_GetNameCardinal();
				const bool 
					Note_Load(const CString&);
				const void 
					Note_Lookup(const enum CSingletonArrayEx<CNote, CNote>::EDirection);
				const bool 
					Note_Save(const CString&);
				const void 
					Notes_CreateDir();
				const CString 
					Notes_GetDir();
				const CString 
					Notes_GetDirCardinal();
				const void 
					Notes_DirSpan();
				const bool 
					Notes_Exist();
				const void 
					Notes_Maintain(const enum EAction);
				const void 
					Notes_Maintain_Cardinal(const enum EAction);
				const void 
					Notes_Remove();
				const void 
					Note_Scroll(const short);
				const void Offset(const CTimeSpanEx&);
				const void Offset_Days(const int);
				const void Offset_Months(const int);
				const void Offset_Years(const int);
				const void SetActiveBtn_OldAndNew(CCalBtn_Radio*, CCalBtn_Radio*);
				const void SetFocus();
				const void ShowHint(CString &cstrHintEx = CString(_T("")));
			protected:
				// 0. Data. (alphabetical).
				CCalFrameWnd *m_pParent;
				CTimeEx m_tDisplay;
				// 4. Slaves. (alphabetical).
				const void Ask(const CString &cstrQuestionEx = _T(""));
				const int GetDay(CCalBtn_Radio*);
				const void Init();
				const bool IsDayInMonth(CCalBtn_Radio*); // Not used anymore.
				const bool IsQuestionAsked(const CString &cstrQuestionEx = _T(""));
				const void Refresh();
				const void ResourcesCreate();
				const void ResourcesDestroy();
				const void UnInit();
			private:
				// 0. Data. (alphabetical).
				bool m_bIsCardinalNoteVisible;
				CCalBtn *m_pBtn[BTN_ID_LAST + 1];
				CCalBtn_Radio *m_pBtnDay[BTN_RADIO_ID_DAY_LAST + 1], 
							  *m_pBtn_Active_DayNew, // No alloc just ptr.
							  *m_pBtn_Active_DayOld, // No alloc just ptr.
							  *m_pBtn_NoteCardinal;
				CCalEdit *m_pEdit_Note;
				// 4. Slaves. (alphabetical).
				CCalBtn_Radio* GetPtr2DisplayTime();
				inline const CTimeEx& GetTime()
				{ return m_tDisplay; }
				const void SetTime(const CTime&);
			// 5. Other. (alphabetical).
			friend class CCalFrameWnd;
		} *m_pCalendar;
		CMenuXP *m_pMenu;
		CRectEx m_irTBCurrent;
		enum EShortcutAction { eSA_Create, eSA_Delete, eSA_Edit, eSA_Exist };
		enum EWndInsertAfter { eWIA_BottomMost = 1, eWIA_Normal, eWIA_TopMost } m_iWndInsertAfter;
		ETBLocWindow m_iTBLocCurrent;
		HHOOK m_hHook; // Not used in this. ver.
		UINT m_uId_TrayIconActive;
		static CCalFrameWnd *m_pWnd_This;
		// 2. Event's. (alphabetical).
		LRESULT OnBtnHovered(WPARAM, LPARAM);
		LRESULT OnBtnInfo(WPARAM, LPARAM);
		LRESULT OnBtnInfo_Radio(WPARAM, LPARAM);
		virtual afx_msg void OnClose();
		virtual afx_msg int OnCreate(LPCREATESTRUCT);
		virtual afx_msg void OnDestroy();
		virtual afx_msg void OnEditNote_Change();
		virtual afx_msg void OnEditNote_SetFocus();
		virtual afx_msg void OnEditNote_Update();
		virtual afx_msg void OnEnterMenuLoop(BOOL);
		virtual afx_msg void OnExitMenuLoop(BOOL);
		virtual afx_msg void OnInitMenuPopup(CMenu*, UINT, BOOL);
		virtual afx_msg void OnKeyDown(UINT, UINT, UINT);
		virtual afx_msg void OnMeasureItem(int, LPMEASUREITEMSTRUCT);
		virtual afx_msg BOOL OnMouseWheel(UINT, short, CPoint);
		LRESULT OnMouseHookNotification(WPARAM, LPARAM); // Not used in this. ver.
		static LRESULT CALLBACK OnMouseTrapNotification(int, WPARAM, LPARAM); // Not used in this. ver.
		virtual afx_msg void OnPaint();
		virtual afx_msg void OnTimer(UINT);
		LRESULT OnTrayIconNotification(WPARAM, LPARAM);
		virtual afx_msg BOOL PreCreateWindow(CREATESTRUCT&);
		// 3.0. Menu choice. (menu order).
		virtual afx_msg void OnClicked_BrowseBtn_PreviousMonthOrYear();
		virtual afx_msg void OnClicked_BrowseBtn_PreviousDayOrWeek();
		virtual afx_msg void OnClicked_BrowseBtn_Today();
		virtual afx_msg void OnClicked_BrowseBtn_NextDayOrWeek();
		virtual afx_msg void OnClicked_BrowseBtn_NextMonthOrYear();
		virtual afx_msg void OnClicked_BrowseBtn_Day();
		virtual afx_msg void OnClicked_BrowseBtn_PreviousNote();
		virtual afx_msg void OnClicked_BrowseBtn_PreviousNote_Enable(CCmdUI*); // Works to late! - why?
		virtual afx_msg void OnClicked_BrowseBtn_NextNote();
		virtual afx_msg void OnClicked_BrowseBtn_NextNote_Enable(CCmdUI*); // Works to late! - why?
		virtual afx_msg void OnClicked_Btn_Note_Cardinal();
		virtual afx_msg void OnClicked_Btn_Note_DeleteOrYes();
		virtual afx_msg void OnClicked_Btn_Note_DeleteAllOrNo();
		virtual afx_msg void OnMenu_ComeOn();
		virtual afx_msg void OnMenu_Go2Time_MMYear();
		virtual afx_msg void OnMenu_Go2Time_MMMonth();
		virtual afx_msg void OnMenu_Go2Time_MMWeek();
		virtual afx_msg void OnMenu_Go2Time_MMDay();
		virtual afx_msg void OnMenu_Go2Time_Today();
		virtual afx_msg void OnMenu_Go2Time_PPDay();
		virtual afx_msg void OnMenu_Go2Time_PPWeek();
		virtual afx_msg void OnMenu_Go2Time_PPMonth();
		virtual afx_msg void OnMenu_Go2Time_PPYear();
		virtual afx_msg void OnMenu_Go2Note_First();
		virtual afx_msg void OnMenu_Go2Note_Prior();
		virtual afx_msg void OnMenu_Go2Note_Next();
		virtual afx_msg void OnMenu_Go2Note_Last();
		virtual afx_msg void OnMenu_Wnd2Bottom();
		virtual afx_msg void OnMenu_Wnd2Normal();
		virtual afx_msg void OnMenu_Wnd2Top();
		virtual afx_msg void OnMenu_Autohide();
		virtual afx_msg void OnMenu_Hint();
		virtual afx_msg void OnMenu_Exit();
		virtual afx_msg void OnMenu_About();
		// 4. Slaves. (alphabetical).
		const CString GetBaloonInfo();
		const void Init();
		const void MatchWndState2CalendarState();
		const void MenuShow();
		const void MouseHookData_Create();
		const void MouseHookData_Destroy();
		const void ResourcesCreate();
		const void ResourcesDestroy();
		const void SetZOrder(const enum EWndInsertAfter iWndInsertAfterEx = (EWndInsertAfter)-1);
		const bool Shortcut(const enum EShortcutAction);
		const void Settings_Load();
		const void Settings_Save();
		const void SlideWindow2InVisible();
		const void SlideWindow2Visible();
		const void Timer_Create(UINT);
		const void Timer_Destroy(UINT);
		const void UnInit();
		// 5. Other. (alphabetical).
	DECLARE_MESSAGE_MAP()
};

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																				  	-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// 0. Data. (alphabetical).
// 1. Object. (alphabetical).
// 2. Event's. (alphabetical).
// 3.0. Menu choice. (menu order).
// 3.1. Menu choice, enablers. (menu order).
// 4. Slaves. (alphabetical).
// 5. Other. (alphabetical).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -