【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-ClockCtl.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// ClockCtl.cpp : Implementation of the CClockCtrl ActiveX Control class.
#include "stdafx.h"
#include "Clock.h"
#include "ClockCtl.h"
#include "ClockPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CClockCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CClockCtrl, COleControl)
//{{AFX_MSG_MAP(CClockCtrl)
ON_WM_TIMER()
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CClockCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CClockCtrl)
DISP_FUNCTION(CClockCtrl, "PropBox", PropBox, VT_EMPTY, VTS_NONE)
DISP_STOCKPROP_BACKCOLOR()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CClockCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CClockCtrl, COleControl)
//{{AFX_EVENT_MAP(CClockCtrl)
EVENT_CUSTOM("NewMinute", FireNewMinute, VTS_NONE)
EVENT_STOCK_CLICK()
EVENT_STOCK_DBLCLICK()
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CClockCtrl, 1)
PROPPAGEID(CClockPropPage::guid)
END_PROPPAGEIDS(CClockCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CClockCtrl, "CLOCK.ClockCtrl.1",
0xaa89f3e8, 0x991b, 0x11d2, 0x81, 0x3, 0xdb, 0x87, 0xba, 0x51, 0x12, 0xfb)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CClockCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DClock =
{ 0xaa89f3fd, 0x991b, 0x11d2, { 0x81, 0x3, 0xdb, 0x87, 0xba, 0x51, 0x12, 0xfb } };
const IID BASED_CODE IID_DClockEvents =
{ 0xaa89f3fe, 0x991b, 0x11d2, { 0x81, 0x3, 0xdb, 0x87, 0xba, 0x51, 0x12, 0xfb } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwClockOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CClockCtrl, IDS_CLOCK, _dwClockOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::CClockCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CClockCtrl
BOOL CClockCtrl::CClockCtrlFactory::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_CLOCK,
IDB_CLOCK,
afxRegApartmentThreading,
_dwClockOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::CClockCtrl - Constructor
CClockCtrl::CClockCtrl()
{
InitializeIIDs(&IID_DClock, &IID_DClockEvents);
// TODO: Initialize your control's instance data here.
SetInitialSize(200,20);
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::~CClockCtrl - Destructor
CClockCtrl::~CClockCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::OnDraw - Drawing function
void CClockCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
//pdc->Ellipse(rcBounds);
pdc->SetBkMode(TRANSPARENT);
CBrush bkBrush(TranslateColor(GetBackColor()));
pdc->FillRect(rcBounds,&bkBrush);
char CurrentTime[30];
struct tm* newtime;
long lTime;
time(&lTime);
newtime=localtime(&lTime);
strcpy(CurrentTime,asctime(newtime));
CurrentTime[24]=' ';
CurrentTime[25]=0;
pdc->ExtTextOut(rcBounds.left,rcBounds.top,
ETO_CLIPPED,rcBounds,CurrentTime,
strlen(CurrentTime),NULL);
if(newtime->tm_sec==0)
FireNewMinute();
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::DoPropExchange - Persistence support
void CClockCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::OnResetState - Reset control to default state
void CClockCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl::AboutBox - Display an "About" box to the user
void CClockCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_CLOCK);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CClockCtrl message handlers
void CClockCtrl::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
InvalidateControl();
COleControl::OnTimer(nIDEvent);
}
int CClockCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,NULL);
return 0;
}
void CClockCtrl::PropBox()
{
// TODO: Add your dispatch handler code here
CDialog dlg(IDD_ABOUTBOX_CLOCK);
dlg.DoModal();
}
上一篇:
Clock.cpp
下一篇:
浙大人文社会科学引文索引来源期刊CSSCI(2010