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

📄 staticnote.h

📁 一个提示软件
💻 H
字号:
// StaticNote.h: interface for the CStaticNote class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_STATICNOTE_H__7457B84E_63B8_41DB_9804_71830DCC1EFD__INCLUDED_)
#define AFX_STATICNOTE_H__7457B84E_63B8_41DB_9804_71830DCC1EFD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CStaticNote : public CWindowImpl<CStaticNote, CStatic>  
{
private:
	CMenu m_menuNotes;	// menu displayed when the user clicks on 'Note' icon
	bool m_bChecked;	// indicates if 'Always on top' menu item is checked or not

public:
	CStaticNote() 
	{
		ATLTRACE(_T("CStaticNote::CStaticNote()\n"));

		m_bChecked = false;		// 'Always on top' menu item initially is not checked
	}

	~CStaticNote() 
	{
		ATLTRACE(_T("CStaticNote::~CStaticNote()\n"));

		// Destroy the menu
		if (m_menuNotes.m_hMenu != NULL)
			m_menuNotes.DestroyMenu();
	}

	BEGIN_MSG_MAP(CStaticNote)
		MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
		MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
	END_MSG_MAP()

	LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		ATLTRACE(_T("CStaticNote::OnLButtonDown()\n"));

		// Always display the menu relative to the left bottom corner
		CPoint pt(0, 16);

		// Convert client coordinates to screen coordinates 
		ClientToScreen(&pt);

		// Load the menu resource 
		if (!m_menuNotes.LoadMenu(IDR_MENU_NOTES))
		{
			ATLTRACE(_T("Menu resource was not loaded successfully!\n"));
			return 0;
		}

		// Should 'Always on top' menu item be checked?
		if (m_bChecked)
			m_menuNotes.CheckMenuItem(IDR_MENU_ONTOP, MF_BYCOMMAND|MF_CHECKED);

		// TrackPopupMenu cannot display the menu bar so get 
		// a handle to the first shortcut menu. 
 		CMenuHandle menuPopup = m_menuNotes.GetSubMenu(0);
		if (menuPopup.m_hMenu == NULL)
		{
			ATLTRACE(_T("Submenu was not retrieved successfully!\n"));
			return 0;
		}

		// Display the shortcut menu, track the left mouse button,
		// and I want the Note dialog to receive all messages from the menu
 		if (!menuPopup.TrackPopupMenu(TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON,
								pt.x, pt.y, GetParent()))
		{
			ATLTRACE(_T("Shortcut menu was not displayed successfully!\n"));
			return 0;
		}		

		// Destroy the menu and free any memory that the menu occupies
		menuPopup.DestroyMenu();
		m_menuNotes.DestroyMenu();

		return 0;
	}

	// Retrieves 'Always on top' menu item state
	bool GetAlwaysOnTopState()
	{
		ATLTRACE(_T("CStaticNote::GetAlwaysOnTopState()\n"));

		return m_bChecked;
	}

	// Sets 'Always on top' menu item state
	void SetAlwaysOnTopState(bool bState)
	{
		ATLTRACE(_T("CStaticNote::SetAlwaysOnTopState()\n"));

		m_bChecked = bState;
	}

	LRESULT OnLButtonDblClk(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		ATLTRACE(_T("CStaticNote::OnLButtonDblClk()\n"));

		// Close the Note dialog
		// Can't use SendMessage(), because by the time SendMessage() returns
		// object's gone
		::PostMessage(GetParent(), WM_CLOSE, 0, 0);		return 0;	}
};

class CStaticClose : public CWindowImpl<CStaticClose, CStatic>
{
public:
	CStaticClose() 
	{
		ATLTRACE(_T("CStaticClose::CStaticClose()\n"));
	}

	~CStaticClose() 
	{
		ATLTRACE(_T("CStaticClose::~CStaticClose()\n"));
	}

	BEGIN_MSG_MAP(CStaticClose)
		MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
		// Take care of unhandled reflected messages
		DEFAULT_REFLECTION_HANDLER()
	END_MSG_MAP()

	LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		ATLTRACE(_T("CStaticClose::OnLButtonDown()\n"));

		// Close the Note dialog
		// Can't use SendMessage(), because by the time SendMessage() returns
		// object's gone
		::PostMessage(GetParent(), WM_CLOSE, 0, 0);		return 0;
	}
};

class CStaticDateTime : public CWindowImpl<CStaticDateTime, CStatic>  
{
private:
	COLORREF m_clrBkgnd;	// background color
	CBrush m_brBkgnd;		// brush for painting the background 

public:
	CStaticDateTime() 
	{
		ATLTRACE(_T("CStaticDateTime::CStaticDateTime()\n"));
	}

	~CStaticDateTime() 
	{
		ATLTRACE(_T("CStaticDateTime::~CStaticDateTime()\n"));

		if (m_brBkgnd.m_hBrush)
			m_brBkgnd.DeleteObject();
	}

	BEGIN_MSG_MAP(CStaticDateTime)
		// Uses message reflection: WM_* comes back as OCM_*
		MESSAGE_HANDLER(OCM_CTLCOLORSTATIC, OnCtlColor)
		// Take care of unhandled reflected messages
		DEFAULT_REFLECTION_HANDLER()
	END_MSG_MAP()

	// Sets the control's background color
	void SetBkgndColor(COLORREF clrColor)
	{
		ATLTRACE(_T("CStaticDateTime::SetBkgndColor()\n"));

		m_clrBkgnd = clrColor;
		m_brBkgnd.CreateSolidBrush(m_clrBkgnd);
		ATLASSERT(m_brBkgnd.m_hBrush);
	}

	LRESULT OnCtlColor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		ATLTRACE(_T("CStaticDateTime::OnCtlColor()\n"));
		ATLASSERT(m_brBkgnd.m_hBrush);

		HDC hDC = (HDC)wParam;

		// Set the text current background color to the specified color value
        SetBkColor(hDC, m_clrBkgnd);

		return (LRESULT)m_brBkgnd.m_hBrush;
	}

	// Changes the control's background color
	void ChangeBkgndColor(COLORREF clrColor)
	{
		ATLTRACE(_T("CStaticDateTime::ChangeBkgndColor()\n"));
		ATLASSERT(m_brBkgnd.m_hBrush);

		m_clrBkgnd = clrColor;
		m_brBkgnd.DeleteObject();
		m_brBkgnd.CreateSolidBrush(m_clrBkgnd);
		ATLASSERT(m_brBkgnd.m_hBrush);
	}

	// Displays the current date and time in the static control
	void SetCurrentDateTime(string strTimeStamp)
	{
		ATLTRACE(_T("CStaticDateTime::SetCurrentDateTime()\n"));

		// Set the new text of the static control
		SetWindowText(strTimeStamp.c_str());
	}
};

class CStaticBar : public CWindowImpl<CStaticBar, CStatic>  
{
private:
	COLORREF m_clrBkgnd;		// background color
	CBrush m_brBkgnd;			// brush for painting the background 

public:
	CStaticBar() 
	{
		ATLTRACE(_T("CStaticBar::CStaticBar()\n"));

		m_clrBkgnd = RED;		// always
		m_brBkgnd.CreateSolidBrush(m_clrBkgnd);	
		ATLASSERT(m_brBkgnd.m_hBrush);
	}

	~CStaticBar() 
	{
		ATLTRACE(_T("CStaticBar::~CStaticBar()\n"));

		if (m_brBkgnd.m_hBrush)
			m_brBkgnd.DeleteObject();
	}

	BEGIN_MSG_MAP(CStaticBar)
		// Uses message reflection: WM_* comes back as OCM_*
		MESSAGE_HANDLER(OCM_CTLCOLORSTATIC, OnCtlColor)
		// Take care of unhandled reflected messages
		DEFAULT_REFLECTION_HANDLER()
		MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
	END_MSG_MAP()

	LRESULT OnCtlColor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		ATLTRACE(_T("CStaticBar::OnCtlColor()\n"));
		ATLASSERT(m_brBkgnd.m_hBrush);

		// Set the current background color to the specified color value
		return (LRESULT)m_brBkgnd.m_hBrush;
	}

	LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		ATLTRACE(_T("CStaticBar::OnEraseBkgnd()\n"));

		// Eliminate the flicker during resizing
		return 1;
	}
};

#endif // !defined(AFX_STATICNOTE_H__7457B84E_63B8_41DB_9804_71830DCC1EFD__INCLUDED_)

⌨️ 快捷键说明

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