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

📄 note.cpp

📁 一个提示软件
💻 CPP
字号:
// Note.cpp: implementation of the CNote class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Note.h"

CNote::CNote() 
{
	ATLTRACE(_T("CNote::CNote()\n"));
	
	// Default font
	m_font = (HFONT)::GetStockObject(SYSTEM_FONT);
	ATLASSERT(m_font.m_hFont);
	
	// Retrieve LOGFONT structure
	memset(&m_lf, 0, sizeof(m_lf));
	
	if (!m_font.GetLogFont(&m_lf))
		ATLTRACE(_T("LOGFONT was not retrieved successfully!\n"));
	
	// Set up default values
	m_strNoteText = _T("");
	m_clrBkgnd = YELLOW;
	m_nID = GenerateID();
	m_strTimestamp = GenerateTimestamp();
	m_strFontName = m_lf.lfFaceName;
	m_bItalic = m_lf.lfItalic;
	m_lFontHeight = m_lf.lfHeight;
	m_lWeight = m_lf.lfWeight;
}

CNote::CNote(const CNote& rhs)
{
	ATLTRACE(_T("CNote::CNote(const CNote& rhs)\n"));
	
	m_strNoteText = rhs.m_strNoteText;	
	m_strFontName = rhs.m_strFontName;	
	m_lFontHeight = rhs.m_lFontHeight;
	m_bItalic = rhs.m_bItalic;
	m_strTimestamp = rhs.m_strTimestamp;	
	m_clrBkgnd = rhs.m_clrBkgnd;
	m_lWeight = rhs.m_lWeight;
	m_nID = rhs.m_nID;				
}

CNote::~CNote() 
{
	ATLTRACE(_T("CNote::~CNote()\n"));
	
	if (m_font.m_hFont)
		m_font.DeleteObject();
}

bool CNote::operator==(const CNote& rhs)
{
	ATLTRACE(_T("CNote::operator==()\n"));
	
	if ((m_strNoteText == rhs.m_strNoteText) && 
		(m_strFontName == rhs.m_strFontName) &&	
		(m_lFontHeight == rhs.m_lFontHeight) &&
		(m_bItalic == rhs.m_bItalic) &&
		(m_strTimestamp == rhs.m_strTimestamp) &&
		(m_clrBkgnd == rhs.m_clrBkgnd) &&
		(m_lWeight == rhs.m_lWeight) &&
		(m_nID == rhs.m_nID))
		return true;
	else
		return false;
}

CNote& CNote::operator=(const CNote& rhs)
{
	ATLTRACE(_T("CNote::operator=()\n"));
	
	if (this == &rhs)
		return *this;
	
	m_strNoteText = rhs.m_strNoteText;	
	m_strFontName = rhs.m_strFontName;	
	m_lFontHeight = rhs.m_lFontHeight;	
	m_bItalic = rhs.m_bItalic;
	m_strTimestamp = rhs.m_strTimestamp;	
	m_clrBkgnd = rhs.m_clrBkgnd;
	m_lWeight = rhs.m_lWeight;
	m_nID = rhs.m_nID;				
	
	return *this;
}

// Generates a timestamp
string CNote::GenerateTimestamp()
{
	ATLTRACE(_T("CNote::GenerateTimestamp()\n"));
	
	SYSTEMTIME csTime;
	TCHAR szTimeStamp[32];
	TCHAR szTemp[4];
	lstrcpy(szTemp, _T("AM"));
	
	// Get the local date and time, format and store it in a buffer
	::GetLocalTime(&csTime);
	
	// AM or PM?
	if (csTime.wHour > 12)
	{
		csTime.wHour = csTime.wHour - 12;
		lstrcpy(szTemp, _T("PM"));
	}
	
	::wsprintf(szTimeStamp, _T("%02d/%02d/%04d %02d:%02d %s"), 
				csTime.wMonth,
				csTime.wDay,
				csTime.wYear,
				csTime.wHour,
				csTime.wMinute,
				szTemp);
	
	return string(szTimeStamp);
}

// Generates a unique note's id
int CNote::GenerateID()
{
	ATLTRACE(_T("CNote::GenerateID()\n"));
	
	// Seed the random-number generator with current time so that
	// the numbers will be different every time we run.
	srand((unsigned)time(NULL));
	
	// Return a pseudorandom number
	return rand();
}

⌨️ 快捷键说明

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