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

📄 bcgptoolbardatetimectrl.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a part of the BCGControlBar Library
// Copyright (C) 1998-2000 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.
//*******************************************************************************
//
// BCGPToolbarDateTimeCtrl.cpp: implementation of the CBCGPToolbarDateTimeCtrl class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "bcgglobals.h"
#include "BCGPToolBar.h"
#include "BCGPToolbarMenuButton.h"
#include "MenuImages.h"
#include "BCGPToolbarDateTimeCtrl.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_SERIAL(CBCGPToolbarDateTimeCtrl, CBCGPToolbarButton, 1)

static const int iDefaultSize = 100;
static const int iHorzMargin = 3;
static const int iVertMargin = 3;

BEGIN_MESSAGE_MAP(CBCGPDateTimeCtrlWin, CDateTimeCtrl)
	//{{AFX_MSG_MAP(CBCGPDateTimeCtrlWin)
	ON_NOTIFY_REFLECT(DTN_DATETIMECHANGE, OnDateTimeChange)
	ON_NOTIFY_REFLECT(DTN_DROPDOWN, OnDateTimeDropDown)
	ON_NOTIFY_REFLECT(DTN_CLOSEUP, OnDateTimeCloseUp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

#pragma warning (disable : 4310)

void CBCGPDateTimeCtrlWin::OnDateTimeChange (NMHDR * pNotifyStruct, LRESULT* pResult)
{
	// Send a WM_COMMAND message with the DTN_DATETIMECHANGE notification (truncated to lower 16 bits)
	// so that we will process it first then it will get forwarded by CBCGToolbar to the current
	// frame window, otherwise everyone has to subclass this class and reflect the WM_NOTIFY messages.
	// Yeah, a hack, but a pretty safe one.
	if (!m_bMonthCtrlDisplayed)
	{
		LPNMDATETIMECHANGE pNotify = (LPNMDATETIMECHANGE) pNotifyStruct;

		GetOwner()->PostMessage (WM_COMMAND,
			MAKEWPARAM (pNotify->nmhdr.idFrom, LOWORD (DTN_DATETIMECHANGE)), (LPARAM)GetSafeHwnd());
	}

	*pResult = 0;
}
//**************************************************************************************
void CBCGPDateTimeCtrlWin::OnDateTimeDropDown (NMHDR* /* pNotifyStruct */, LRESULT* pResult)
{
	m_bMonthCtrlDisplayed = true;

	*pResult = 0;
}
//**************************************************************************************
void CBCGPDateTimeCtrlWin::OnDateTimeCloseUp (NMHDR* pNotifyStruct, LRESULT* pResult)
{
	m_bMonthCtrlDisplayed = false;

	LPNMDATETIMECHANGE pNotify = (LPNMDATETIMECHANGE) pNotifyStruct;

	GetOwner()->PostMessage (WM_COMMAND,
		MAKEWPARAM (pNotify->nmhdr.idFrom, LOWORD (DTN_DATETIMECHANGE)), (LPARAM)GetSafeHwnd());

	*pResult = 0;
}

#pragma warning (default : 4310)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBCGPToolbarDateTimeCtrl::CBCGPToolbarDateTimeCtrl()
{
	m_dwStyle = WS_CHILD | WS_VISIBLE;
	m_iWidth = iDefaultSize;

	Initialize ();
}
//**************************************************************************************
CBCGPToolbarDateTimeCtrl::CBCGPToolbarDateTimeCtrl (UINT uiId,
			int iImage,
			DWORD dwStyle,
			int iWidth) :
			CBCGPToolbarButton (uiId, iImage)
{
	m_dwStyle = dwStyle | WS_CHILD | WS_VISIBLE;
	m_iWidth = (iWidth == 0) ? iDefaultSize : iWidth;

	Initialize ();
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::Initialize ()
{
	m_pWndDateTime = NULL;
	m_bHorz = TRUE;
	m_dwTimeStatus = GDT_VALID;
	m_time = CTime::GetCurrentTime ();
}
//**************************************************************************************
CBCGPToolbarDateTimeCtrl::~CBCGPToolbarDateTimeCtrl ()
{
	if (m_pWndDateTime != NULL)
	{
		m_pWndDateTime->DestroyWindow ();
		delete m_pWndDateTime;
	}
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::CopyFrom (const CBCGPToolbarButton& s)
{
	CBCGPToolbarButton::CopyFrom (s);

	DuplicateData ();

	const CBCGPToolbarDateTimeCtrl& src = (const CBCGPToolbarDateTimeCtrl&) s;
	m_dwStyle = src.m_dwStyle;
	m_iWidth = src.m_iWidth;
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::Serialize (CArchive& ar)
{
	CBCGPToolbarButton::Serialize (ar);

	if (ar.IsLoading ())
	{
		ar >> m_iWidth;
		m_rect.right = m_rect.left + m_iWidth;
		ar >> m_dwStyle;
		ar >> m_dwTimeStatus;
		ar >> m_time;

		if (m_pWndDateTime)
			m_pWndDateTime->SetTime (m_dwTimeStatus == GDT_VALID? &m_time : NULL);

		DuplicateData ();
	}
	else
	{
		if(m_pWndDateTime)
		m_dwTimeStatus = m_pWndDateTime->GetTime(m_time);

		ar << m_iWidth;
		ar << m_dwStyle;
		ar << m_dwTimeStatus;
		ar << m_time;
	}
}
//**************************************************************************************
SIZE CBCGPToolbarDateTimeCtrl::OnCalculateSize (CDC* pDC, const CSize& sizeDefault, BOOL bHorz)
{
	if(!IsVisible())
	{
		return CSize(0,0);
	}

	m_bHorz = bHorz;
	m_sizeText = CSize (0, 0);

	if (bHorz)
	{
		if (m_pWndDateTime->GetSafeHwnd () != NULL && !m_bIsHidden)
		{
			m_pWndDateTime->ShowWindow (SW_SHOWNOACTIVATE);
		}

		//----------------
		// By Guy Hachlili
		//----------------
		if (m_bTextBelow && !m_strText.IsEmpty())
		{
			CRect rectText (0, 0, m_iWidth, sizeDefault.cy);
			pDC->DrawText (m_strText, rectText, DT_CENTER | DT_CALCRECT | DT_WORDBREAK);
			m_sizeText = rectText.Size ();
		}

		return CSize (m_iWidth, sizeDefault.cy + m_sizeText.cy);
	}
	else
	{
		if (m_pWndDateTime->GetSafeHwnd () != NULL &&
			(m_pWndDateTime->GetStyle () & WS_VISIBLE))
		{
			m_pWndDateTime->ShowWindow (SW_HIDE);
		}

		return CBCGPToolbarButton::OnCalculateSize (pDC, sizeDefault, bHorz);
	}
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::OnMove ()
{
	if (m_pWndDateTime->GetSafeHwnd () == NULL ||
		(m_pWndDateTime->GetStyle () & WS_VISIBLE) == 0)
	{
		return;
	}

	CRect rectDateTime;
	m_pWndDateTime->GetWindowRect (rectDateTime);

	m_pWndDateTime->SetWindowPos (NULL, 
		m_rect.left + iHorzMargin, 
		m_rect.top + (m_rect.Height () - m_sizeText.cy - rectDateTime.Height ()) / 2,
		m_rect.Width () - 2 * iHorzMargin, 
		globalData.GetTextHeight() + 2 * iVertMargin,
		SWP_NOZORDER | SWP_NOACTIVATE);

	AdjustRect ();
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::OnSize (int iSize)
{
	m_iWidth = iSize;
	m_rect.right = m_rect.left + m_iWidth;

	if (m_pWndDateTime->GetSafeHwnd () != NULL &&
		(m_pWndDateTime->GetStyle () & WS_VISIBLE))
	{
		m_pWndDateTime->SetWindowPos (NULL, 
			m_rect.left + iHorzMargin, m_rect.top,
			m_rect.Width () - 2 * iHorzMargin, 
			globalData.GetTextHeight() + 2 * iVertMargin,
			SWP_NOZORDER | SWP_NOACTIVATE);

		AdjustRect ();
	}
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::OnChangeParentWnd (CWnd* pWndParent)
{
	CBCGPToolbarButton::OnChangeParentWnd (pWndParent);

	if (m_pWndDateTime->GetSafeHwnd () != NULL)
	{
		CWnd* pWndParentCurr = m_pWndDateTime->GetParent ();
		ASSERT (pWndParentCurr != NULL);

		if (pWndParent != NULL &&
			pWndParentCurr->GetSafeHwnd () == pWndParent->GetSafeHwnd ())
		{
			return;
		}

		m_pWndDateTime->DestroyWindow ();
		delete m_pWndDateTime;
		m_pWndDateTime = NULL;
	}

	if (pWndParent == NULL || pWndParent->GetSafeHwnd () == NULL)
	{
		return;
	}

	CRect rect = m_rect;
	rect.InflateRect (-2, 0);
	rect.bottom = rect.top + globalData.GetTextHeight() + 2 * iVertMargin;

	if ((m_pWndDateTime = CreateDateTimeCtrl (pWndParent, rect)) == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	AdjustRect ();

	m_pWndDateTime->SetFont (&globalData.fontRegular);

	m_pWndDateTime->SetTime (m_dwTimeStatus == GDT_VALID? &m_time : NULL);
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::AdjustRect ()
{
	if (m_pWndDateTime->GetSafeHwnd () == NULL ||
		(m_pWndDateTime->GetStyle () & WS_VISIBLE) == 0 ||
		m_rect.IsRectEmpty ())
	{
		return;
	}

	m_pWndDateTime->GetWindowRect (&m_rect);
	m_pWndDateTime->ScreenToClient (&m_rect);
	m_pWndDateTime->MapWindowPoints (m_pWndDateTime->GetParent (), &m_rect);
	m_rect.InflateRect (iHorzMargin, iVertMargin);
}
//**************************************************************************************

#pragma warning (disable : 4310)

BOOL CBCGPToolbarDateTimeCtrl::NotifyCommand (int iNotifyCode)
{
	if (m_pWndDateTime->GetSafeHwnd () == NULL)
	{
		return FALSE;
	}

	switch (iNotifyCode)
	{
	case LOWORD(DTN_DATETIMECHANGE):
	case DTN_DATETIMECHANGE:
		{
			m_dwTimeStatus = m_pWndDateTime->GetTime (m_time);

			//------------------------------------------------------
			// Try set selection in ALL DateTimeCtrl's with the same ID:
			//------------------------------------------------------
			CObList listButtons;
			if (CBCGPToolBar::GetCommandButtons (m_nID, listButtons) > 0)
			{
				for (POSITION posCombo = listButtons.GetHeadPosition (); posCombo != NULL;)

⌨️ 快捷键说明

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