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

📄 sam_windowctl.cpp

📁 制作VC控件教程
💻 CPP
字号:
// Sam_windowCtl.cpp : Implementation of the CSam_windowCtrl ActiveX Control class.

#include "stdafx.h"
#include "sam_21.h"
#include "Sam_windowCtl.h"
#include "Sam_windowPpg.h"


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


IMPLEMENT_DYNCREATE(CSam_windowCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CSam_windowCtrl, COleControl)
	//{{AFX_MSG_MAP(CSam_windowCtrl)
	ON_WM_CREATE()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


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

BEGIN_DISPATCH_MAP(CSam_windowCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CSam_windowCtrl)
	DISP_PROPERTY_EX(CSam_windowCtrl, "TextColor", GetTextColor, SetTextColor, VT_COLOR)
	DISP_FUNCTION(CSam_windowCtrl, "SetMertial", SetMertial, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CSam_windowCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


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

BEGIN_EVENT_MAP(CSam_windowCtrl, COleControl)
	//{{AFX_EVENT_MAP(CSam_windowCtrl)
	EVENT_CUSTOM("Timer", FireTimer, VTS_NONE)
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


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

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


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

IMPLEMENT_OLECREATE_EX(CSam_windowCtrl, "SAM21.SamwindowCtrl.1",
	0x58c72a49, 0xd633, 0x11d3, 0x9b, 0x30, 0x52, 0x54, 0x4c, 0x39, 0x3a, 0x8c)


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

IMPLEMENT_OLETYPELIB(CSam_windowCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DSam_window =
		{ 0x58c72a47, 0xd633, 0x11d3, { 0x9b, 0x30, 0x52, 0x54, 0x4c, 0x39, 0x3a, 0x8c } };
const IID BASED_CODE IID_DSam_windowEvents =
		{ 0x58c72a48, 0xd633, 0x11d3, { 0x9b, 0x30, 0x52, 0x54, 0x4c, 0x39, 0x3a, 0x8c } };


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

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

IMPLEMENT_OLECTLTYPE(CSam_windowCtrl, IDS_SAM_WINDOW, _dwSam_windowOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CSam_windowCtrl::CSam_windowCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CSam_windowCtrl

BOOL CSam_windowCtrl::CSam_windowCtrlFactory::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_SAM_WINDOW,
			IDB_SAM_WINDOW,
			afxRegApartmentThreading,
			_dwSam_windowOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CSam_windowCtrl::CSam_windowCtrl - Constructor

CSam_windowCtrl::CSam_windowCtrl()
{
	InitializeIIDs(&IID_DSam_window, &IID_DSam_windowEvents);
	m_szName="name";
	m_szBirth="birth";
	m_szClass="class";
	m_ocText=(OLE_COLOR)RGB(255,0,0);
}


/////////////////////////////////////////////////////////////////////////////
// CSam_windowCtrl::~CSam_windowCtrl - Destructor

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


/////////////////////////////////////////////////////////////////////////////
// CSam_windowCtrl::OnDraw - Drawing function

void CSam_windowCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	DoSuperclassPaint(pdc, rcBounds);
	CString szOut=m_szName;
	szOut+="\n";
	szOut+=m_szBirth;
	szOut+="\n";
	szOut+=m_szClass;
	CRect rcDraw=rcBounds;
	COLORREF clrText= TranslateColor(m_ocText);
	pdc->SetTextColor(clrText);
	pdc->DrawText(szOut,rcDraw,DT_CENTER);
}


/////////////////////////////////////////////////////////////////////////////
// CSam_windowCtrl::DoPropExchange - Persistence support

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

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

}


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

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

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


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

void CSam_windowCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_SAM_WINDOW);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CSam_windowCtrl message handlers
int CSam_windowCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	SetTimer(1,2000,NULL);	
	return 0;
}

void CSam_windowCtrl::OnTimer(UINT nIDEvent) 
{
	FireTimer();
	COleControl::OnTimer(nIDEvent);
}

void CSam_windowCtrl::SetMertial(LPCTSTR pszName, LPCTSTR pszBirth, LPCTSTR pszClass) 
{
	m_szName=pszName;
	m_szBirth=pszBirth;
	m_szClass=pszClass;
	Invalidate();
}

OLE_COLOR CSam_windowCtrl::GetTextColor() 
{
	return m_ocText;
}

void CSam_windowCtrl::SetTextColor(OLE_COLOR nNewValue) 
{
	m_ocText=nNewValue;
	Invalidate();
	SetModifiedFlag();
}

⌨️ 快捷键说明

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