📄 calendar_btn.cpp
字号:
const CString CCalBtn::GetCaption()
// Return the btn. caption.
{
CString cstrCaption(_T(""));
GetWindowText(cstrCaption);
return cstrCaption;
}
const int CCalBtn::GetCheck()
// Return the btn. check state.
{ return m_iCheckState; }
const void CCalBtn::GetColors( // For a better understanding see SetColors(...).
HBRUSH *phbrBtn_Externals_Background, // Color of background.
COLORREF *pcrBtn_Externals_Raised_LeftTop, // Color of edge raised.
COLORREF *pcrBtn_Externals_Raised_RightBottom, // Color of edge raiseed.
COLORREF *pcrBtn_Externals_Pressed_LeftTop, // Color of edge pressed.
COLORREF *pcrBtn_Externals_Pressed_RightBottom, // Color of edge pressed.
COLORREF *pcrBtn_Externals_Sleeping_LeftTop, // Color of edge sleeping.
COLORREF *pcrBtn_Externals_Sleeping_RightBottom, // Color of edge sleeping.
COLORREF *pcrBtn_Externals_Disabled, // Color of (left, top, right, bottom)-edge disabled.
COLORREF *pcrBtn_Internals_Raised, // Color of deco. hovered.
COLORREF *pcrBtn_Internals_Pressed, // Color of deco. pressed.
COLORREF *pcrBtn_Internals_Sleeping, // Color of deco. sleeping.
COLORREF *pcrBtn_Internals_Disabled, // Color of deco. disabled.
COLORREF *pcrBtn_Internals_Checkmark) // Color of checkmark.
// Get full color matrix of this.
{
if(phbrBtn_Externals_Background)
*phbrBtn_Externals_Background = m_hbrBtn_Externals_Background;
if(pcrBtn_Externals_Raised_LeftTop)
*pcrBtn_Externals_Raised_LeftTop = m_crBtn_Externals_Raised_LeftTop;
if(pcrBtn_Externals_Raised_RightBottom)
*pcrBtn_Externals_Raised_RightBottom = m_crBtn_Externals_Raised_RightBottom;
if(pcrBtn_Externals_Pressed_LeftTop)
*pcrBtn_Externals_Pressed_LeftTop = m_crBtn_Externals_Pressed_LeftTop;
if(pcrBtn_Externals_Pressed_RightBottom)
*pcrBtn_Externals_Pressed_RightBottom = m_crBtn_Externals_Pressed_RightBottom;
if(pcrBtn_Externals_Sleeping_LeftTop)
*pcrBtn_Externals_Sleeping_LeftTop = m_crBtn_Externals_Sleeping_LeftTop;
if(pcrBtn_Externals_Sleeping_RightBottom)
*pcrBtn_Externals_Sleeping_RightBottom = m_crBtn_Externals_Sleeping_RightBottom;
if(pcrBtn_Externals_Disabled)
*pcrBtn_Externals_Disabled = m_crBtn_Externals_Disabled;
if(pcrBtn_Internals_Raised)
*pcrBtn_Internals_Raised = m_crBtn_Internals_Raised;
if(pcrBtn_Internals_Pressed)
*pcrBtn_Internals_Pressed = m_crBtn_Internals_Pressed;
if(pcrBtn_Internals_Sleeping)
*pcrBtn_Internals_Sleeping = m_crBtn_Internals_Sleeping;
if(pcrBtn_Internals_Disabled)
*pcrBtn_Internals_Disabled = m_crBtn_Internals_Disabled;
if(pcrBtn_Internals_Checkmark)
*pcrBtn_Internals_Checkmark = m_crBtn_Internals_Checkmark;
}
const void CCalBtn::GetRepresentation(CShadowDC &dc_shadow)
// Draw btn. on this shadow dc.
{
register CRectEx irClient(::GetClientRectEx(this));
irClient.MoveTo(m_ipTopLeft.x, m_ipTopLeft.y);
Draw_Button_Externals(dc_shadow, irClient);
Draw_Button_Internals(dc_shadow, irClient);
}
const CCalBtn::EState CCalBtn::GetState()
// Return the btn. state.
{ return m_iState; }
const CCalBtn::EStyle CCalBtn::GetStyle()
// Return the btn. style.
{ return m_iStyle; }
const int CCalBtn::GetPos_Left()
// Return left pos. of btn.
{ return m_ipTopLeft.x; }
const int CCalBtn::GetPos_Top()
// Return top pos. of btn.
{ return m_ipTopLeft.y; }
const int CCalBtn::GetPos_Right()
// Return right pos. of btn.
{ return(m_ipTopLeft.x + CRectEx(GetWindowRectEx(this)).Width()); }
const int CCalBtn::GetPos_Bottom()
// Return bottom pos. of btn.
{ return(m_ipTopLeft.y + CRectEx(GetWindowRectEx(this)).Height()); }
const CCalBtn::EGraph CCalBtn::GetType()
// Return the btn. type.
{ return m_iType; }
const bool CCalBtn::HasCaption()
// Return T if btn. has a caption and F if not.
{ return(GetWindowTextLength() > 0); }
const void CCalBtn::Init()
// Init.
{
SetColors();
}
const bool CCalBtn::IsHovered()
// Return T in case the mouse is inside rect. of this and F of not.
{
CPointEx ipMouse;
GetCursorPos((LPPOINT)&ipMouse);
CRectEx irWindow(::GetWindowRectEx(this));
return(irWindow.IsPtInsideRect(ipMouse));
}
const void CCalBtn::SetAutorepeat(const bool bDoAutorepeat)
// Set autorepeat (meaning repeat function when held down).
{
if(bDoAutorepeat)
// Use auto repeat with this count down.
m_iAutoRepeat = I_COUNTDOWN_AUTOREPEAT;
else
// Don't use auto repeat.
m_iAutoRepeat = -1;
}
const void CCalBtn::SetBehaviour(const enum EBehaviour iBehaviour, const bool bDoInvalidate)
// Alter behaviour of btn.
{
if(m_iBehaviour == iBehaviour)
return;
m_iBehaviour = iBehaviour;
if(bDoInvalidate)
Invalidate();
}
const void CCalBtn::SetCaption(const int iCaption)
// Set btn. text based on a integer.
{
CString cstrCaption(_T(""));
cstrCaption.Format(TEXT("%2d"), iCaption);
SetCaption(cstrCaption);
}
const void CCalBtn::SetCaption(const CString &cstrCaption)
// Set btn. text based on a text.
{ SetWindowText(cstrCaption); }
const void CCalBtn::SetHint(const CString &cstrHint)
// Set btn. hint.
{ m_cstrHint = cstrHint; }
const void CCalBtn::Pos_Set(const int iX, const int iY)
// Set left/top pos. of btn.
{ m_ipTopLeft.Set(iX, iY); }
const void CCalBtn::SetCheck(const int iCheckState, const bool bDoInvalidate)
// Add/remove the checkmark in the top/right corner of the btn.
{
if(iCheckState != I_MF_CHECKED && iCheckState != I_MF_UNCHECKED)
return;
if(m_iCheckState == iCheckState)
return;
m_iCheckState = iCheckState;
if(bDoInvalidate)
Invalidate();
}
const void CCalBtn::SetState(const enum EState iState, const bool bDoInvalidate)
// Alter state of btn.
{
if(m_iState == iState)
return;
m_iState = iState;
if(bDoInvalidate)
Invalidate();
}
const void CCalBtn::SetStyle(const enum EStyle iStyle, const bool bDoInvalidate)
// Alter style of btn.
{
if(m_iStyle == iStyle)
return;
m_iStyle = iStyle;
if(bDoInvalidate)
Invalidate();
}
const void CCalBtn::ResourcesCreate()
// Create all resources associated with this object.
{
TRACE(_T("CCalBtn::ResourcesCreate()\n"));
// Create font.
if(!m_pFont)
CreateFont();
}
const void CCalBtn::ResourcesDestroy()
// Destroy all resources associated with this object.
{
TRACE(_T("CCalBtn::ResourcesDestroy()\n"));
// Kill font.
if(m_pFont)
{
m_pFont->DeleteObject();
delete m_pFont;
m_pFont = NULL;
}
// Be sure that the time are destroyed.
Timer_Destroy(1);
}
const void CCalBtn::SetColors(
const HBRUSH hbrBtn_Externals_Background, // Color of background.
const COLORREF crBtn_Externals_Raised_LeftTop, // Color of edge raised.
const COLORREF crBtn_Externals_Raised_RightBottom, // Color of edge raiseed.
const COLORREF crBtn_Externals_Pressed_LeftTop, // Color of edge pressed.
const COLORREF crBtn_Externals_Pressed_RightBottom, // Color of edge pressed.
const COLORREF crBtn_Externals_Sleeping_LeftTop, // Color of edge sleeping.
const COLORREF crBtn_Externals_Sleeping_RightBottom, // Color of edge sleeping.
const COLORREF crBtn_Externals_Disabled, // Color of (left, top, right, bottom)-edge disabled.
const COLORREF crBtn_Internals_Raised, // Color of deco. hovered.
const COLORREF crBtn_Internals_Pressed, // Color of deco. pressed.
const COLORREF crBtn_Internals_Sleeping, // Color of deco. sleeping.
const COLORREF crBtn_Internals_Disabled, // Color of deco. disabled.
const COLORREF crBtn_Internals_Checkmark) // Color of checkmark.
// Set full color setup for btn.
{
// Background.
m_hbrBtn_Externals_Background = (hbrBtn_Externals_Background ? hbrBtn_Externals_Background : I_DEFAULT_COLORBR_BACKGROUND);
// Externals.
//
// LT-edge when hovered.
m_crBtn_Externals_Raised_LeftTop = (crBtn_Externals_Raised_LeftTop ? crBtn_Externals_Raised_LeftTop : I_DEFAULT_COLOR_RAISED_LT);
// RB-edge when hovered.
m_crBtn_Externals_Raised_RightBottom = (crBtn_Externals_Raised_RightBottom ? crBtn_Externals_Raised_RightBottom : I_DEFAULT_COLOR_RAISED_RB);
// LT-edge when pressed.
m_crBtn_Externals_Pressed_LeftTop = (crBtn_Externals_Pressed_LeftTop ? crBtn_Externals_Pressed_LeftTop : I_DEFAULT_COLOR_PRESSED_LT);
// RB-edge when pressed.
m_crBtn_Externals_Pressed_RightBottom = (crBtn_Externals_Pressed_RightBottom ? crBtn_Externals_Pressed_RightBottom : I_DEFAULT_COLOR_PRESSED_RB);
// LT-edge when sleeping.
m_crBtn_Externals_Sleeping_LeftTop = (crBtn_Externals_Sleeping_LeftTop ? crBtn_Externals_Sleeping_LeftTop : I_DEFAULT_COLOR_SLEEPING_LT);
// RB-edge when sleeping.
m_crBtn_Externals_Sleeping_RightBottom = (crBtn_Externals_Sleeping_RightBottom ? crBtn_Externals_Sleeping_RightBottom : I_DEFAULT_COLOR_SLEEPING_RB);
// LT-RB-edge disabled.
m_crBtn_Externals_Disabled = (crBtn_Externals_Disabled ? crBtn_Externals_Disabled : I_DEFAULT_COLOR_DISABLED_LTRB);
// Internals.
m_crBtn_Internals_Raised = (crBtn_Internals_Raised ? crBtn_Internals_Raised : I_DEFAULT_COLOR_RAISED);
m_crBtn_Internals_Pressed = (crBtn_Internals_Pressed ? crBtn_Internals_Pressed : I_DEFAULT_COLOR_PRESSED);
m_crBtn_Internals_Sleeping = (crBtn_Internals_Sleeping ? crBtn_Internals_Sleeping : I_DEFAULT_COLOR_SLEEPING);
m_crBtn_Internals_Disabled = (crBtn_Internals_Disabled ? crBtn_Internals_Disabled : I_DEFAULT_COLOR_DISABLED);
m_crBtn_Internals_Checkmark = (crBtn_Internals_Checkmark ? crBtn_Internals_Checkmark : I_DEFAULT_COLOR_CHECKMARK);
}
const void CCalBtn::SetTextAlign(CONST UINT uTextAlign)
// Overridden base.
{ m_uTextAlign = uTextAlign; }
const void CCalBtn::Timer_Create(CONST UINT uIdTimer, CONST UINT uPeriod)
// Create timer.
{
switch(uIdTimer)
{
case ID_TIMER_AUTOHIDE:
if(!m_bIsHovered)
SetTimer(uIdTimer, uPeriod, NULL);
break;
case ID_TIMER_AUTOUPDATE:
SetTimer(uIdTimer, uPeriod, NULL);
break;
}
}
const void CCalBtn::Timer_Destroy(CONST UINT uIdTimer)
// Kill timer.
{
KillTimer(uIdTimer);
}
const void CCalBtn::UnInit()
// UnInit.
{
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - CCalBtn_Radio. -
// ------------------------------------------------------------------------------------------------------------------------------------------------------
IMPLEMENT_DYNCREATE(CCalBtn_Radio, CCalBtn)
BEGIN_MESSAGE_MAP(CCalBtn_Radio, CCalBtn)
// System.
ON_WM_LBUTTONDOWN()
// Reflect radio btn. clicked.
ON_CONTROL_REFLECT(BN_CLICKED, OnClickedRadio)
END_MESSAGE_MAP()
// 1. Object. (alphabetical).
CCalBtn_Radio::CCalBtn_Radio(
const enum CCalBtn::EGraph iType,
const enum CCalBtn::EStyle iStyle,
const enum CCalBtn::EBehaviour iBehaviour) :
m_pWnd_RadioGroupMember_Last(NULL),
m_pWnd_RadioGroupMember_Previous(NULL),
CCalBtn(iType, iStyle, iBehaviour)
// Create.
{
}
CCalBtn_Radio::~CCalBtn_Radio()
// Kill.
{
}
// 2. Event's. (alphabetical).
void CCalBtn_Radio::OnClickedRadio()
// Btn. was pressed.
{
if(m_iState == eST_Disabled || m_iBehaviour == eBE_Static)
return;
CFrameWnd *pParent = static_cast<CFrameWnd*>(GetParent());
if(pParent)
pParent->SendMessage(WM_BTN_RADIO, (WPARAM)this, 0L);
}
void CCalBtn_Radio::OnLButtonDown(UINT uFlag, CPoint ipMouse)
{
if(m_iState != eST_Disabled && m_iBehaviour != eBE_Static)
Draw_ReleaseRadioGroup();
CCalBtn::OnLButtonDown(uFlag, ipMouse);
}
// 4. Slaves. (alphabetical).
const void CCalBtn_Radio::Draw_ReleaseRadioGroup()
// Redraw all (other) members in radio group to get all members in right state (one pressed and
// rest de-pressed). In other words - release the old pressed.
{
if(!m_pWnd_RadioGroupMember_Last)
return;
CCalBtn_Radio *pWnd = m_pWnd_RadioGroupMember_Last;
do
{
if(pWnd != this && pWnd->GetState() == eST_Down)
{
pWnd->SetState(eST_Normal);
break;
}
pWnd = pWnd->m_pWnd_RadioGroupMember_Previous;
}
while(pWnd->m_pWnd_RadioGroupMember_Previous);
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - -
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// 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 + -