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

📄 superdigitalclockctl.cpp

📁 VisualC高级编程技术精粹.rar
💻 CPP
字号:
// SuperDigitalClockCtl.cpp : Implementation of the CSuperDigitalClockCtrl ActiveX Control class.

#include "stdafx.h"
#include "SuperDigitalClock.h"
#include "SuperDigitalClockCtl.h"
#include "SuperDigitalClockPpg.h"
#include "Colors.h"

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


IMPLEMENT_DYNCREATE(CSuperDigitalClockCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CSuperDigitalClockCtrl, COleControl)
	//{{AFX_MSG_MAP(CSuperDigitalClockCtrl)
	ON_WM_RBUTTONDOWN()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CSuperDigitalClockCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CSuperDigitalClockCtrl)
	DISP_FUNCTION(CSuperDigitalClockCtrl, "SetColors", SetColors, VT_EMPTY, VTS_COLOR VTS_COLOR VTS_COLOR)
	DISP_FUNCTION(CSuperDigitalClockCtrl, "SetMode", SetMode, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CSuperDigitalClockCtrl, "SetTime", SetTime, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CSuperDigitalClockCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CSuperDigitalClockCtrl, COleControl)
	//{{AFX_EVENT_MAP(CSuperDigitalClockCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CSuperDigitalClockCtrl, 1)
	PROPPAGEID(CSuperDigitalClockPropPage::guid)
END_PROPPAGEIDS(CSuperDigitalClockCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CSuperDigitalClockCtrl, "SUPERDIGITALCLOCK.SuperDigitalClockCtrl.1",
	0xaf3fb796, 0x91fa, 0x4bb2, 0x92, 0xfd, 0xf7, 0x74, 0x6e, 0xe, 0xac, 0xc5)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CSuperDigitalClockCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DSuperDigitalClock =
		{ 0xd88d086, 0x6589, 0x428e, { 0xae, 0xf3, 0x1e, 0xb8, 0x2d, 0xd9, 0x9a, 0x62 } };
const IID BASED_CODE IID_DSuperDigitalClockEvents =
		{ 0xca6cf673, 0xb72b, 0x4b16, { 0x87, 0xcb, 0x78, 0x3c, 0x6a, 0xcc, 0xbf, 0x88 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwSuperDigitalClockOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CSuperDigitalClockCtrl, IDS_SUPERDIGITALCLOCK, _dwSuperDigitalClockOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::CSuperDigitalClockCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CSuperDigitalClockCtrl

BOOL CSuperDigitalClockCtrl::CSuperDigitalClockCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_SUPERDIGITALCLOCK,
			IDB_SUPERDIGITALCLOCK,
			afxRegApartmentThreading,
			_dwSuperDigitalClockOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::CSuperDigitalClockCtrl - Constructor

CSuperDigitalClockCtrl::CSuperDigitalClockCtrl()
{
	InitializeIIDs(&IID_DSuperDigitalClock, &IID_DSuperDigitalClockEvents);

	// TODO: Initialize your control's instance data here.
	m_sMode = 0;
	m_BackgroundColor = TranslateColor(RGB(0,0,0)); // 黑色
	m_TextColor = TranslateColor(RGB(255,0,0)); // 红色
	m_LinesColor = TranslateColor(RGB(0,0,0)); // 黑色
}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::~CSuperDigitalClockCtrl - Destructor

CSuperDigitalClockCtrl::~CSuperDigitalClockCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::OnDraw - Drawing function

void CSuperDigitalClockCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	rect = rcBounds;
	static int i=0;

	if (i==0)
	{
		i = 1;
		SetTimer(1,1000,NULL);
	}

	CBrush br;
	br.CreateSolidBrush(TranslateColor(m_BackgroundColor));
	pdc->SelectObject(&br);
	pdc->Rectangle(rcBounds);
	br.DeleteObject();

	GDigitalClock.c_fundal = TranslateColor(m_BackgroundColor);
	GDigitalClock.c_inside = TranslateColor(m_TextColor);
	GDigitalClock.c_line = TranslateColor(m_LinesColor);

	if (m_sMode==0) 
	{
		GDigitalClock.DrawRect(rcBounds,pdc);
	}

	if (m_sMode==1)
	{
		GDigitalClock.SetTime(m_sHour,m_sMinute,m_sSecond,rect,pdc);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::DoPropExchange - Persistence support

void CSuperDigitalClockCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::OnResetState - Reset control to default state

void CSuperDigitalClockCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl::AboutBox - Display an "About" box to the user

void CSuperDigitalClockCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_SUPERDIGITALCLOCK);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CSuperDigitalClockCtrl message handlers

void CSuperDigitalClockCtrl::SetColors(OLE_COLOR BackgroundColor, 
									   OLE_COLOR LinesColor, 
									   OLE_COLOR TextColor) 
{
	CBrush br;
	m_BackgroundColor = BackgroundColor;
	br.CreateSolidBrush(TranslateColor(m_BackgroundColor));

	CDC* pdc;
	pdc = GetDC();
	pdc->SelectObject(&br);
	pdc->Rectangle(rect);
	br.DeleteObject();
	GDigitalClock.c_fundal = TranslateColor(m_BackgroundColor);
	br.DeleteObject();
	ReleaseDC(pdc);

	m_TextColor = TextColor;
	m_LinesColor = LinesColor;

	InvalidateRect(NULL);
}

void CSuperDigitalClockCtrl::SetMode(short sMode) 
{
	m_sMode = sMode;
}

void CSuperDigitalClockCtrl::SetTime(short sHour, 
									 short sMinute, 
									 short sSecond) 
{
	m_sHour = sHour;
	m_sMinute = sMinute;
	m_sSecond = sSecond;

	InvalidateRect(NULL);
}

void CSuperDigitalClockCtrl::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CColors ColorDlg;
	ColorDlg.BackgroundColor = m_BackgroundColor;
	ColorDlg.TextColor = m_TextColor;
	ColorDlg.LinesColor = m_LinesColor;

	if (ColorDlg.DoModal()==IDOK)
	{
		m_BackgroundColor = ColorDlg.BackgroundColor;
		m_TextColor = ColorDlg.TextColor;
		m_LinesColor = ColorDlg.LinesColor;

		InvalidateRect(NULL);
	}

	COleControl::OnRButtonDown(nFlags, point);
}

void CSuperDigitalClockCtrl::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (m_sMode==0) 
	{
		InvalidateRect(NULL);
	}

	COleControl::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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