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

📄 ncomboctl.cpp

📁 VisualC++实践与提高-ActiveX篇源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// NComboCtl.cpp : Implementation of the CNComboCtrl ActiveX Control class.

#include "stdafx.h"
#include "NCombo.h"
#include "NComboCtl.h"
#include "NComboPpg.h"
#include "AboutDlg.h"

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


IMPLEMENT_DYNCREATE(CNComboCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CNComboCtrl, COleControl)
	//{{AFX_MSG_MAP(CNComboCtrl)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


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

BEGIN_DISPATCH_MAP(CNComboCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CNComboCtrl)
	DISP_PROPERTY_NOTIFY(CNComboCtrl, "DropDownHeight", m_nDropDownHeight, OnDropDownHeightChanged, VT_I4)
	DISP_PROPERTY_EX(CNComboCtrl, "ColumnKey", GetColumnKey, SetColumnKey, VT_I4)
	DISP_PROPERTY_EX(CNComboCtrl, "Resizing", GetResizing, SetResizing, VT_BOOL)
	DISP_PROPERTY_EX(CNComboCtrl, "SelectItem", GetSelectItem, SetSelectItem, VT_I4)
	DISP_FUNCTION(CNComboCtrl, "InsertColumn", InsertColumn, VT_I4, VTS_I4 VTS_BSTR VTS_I4 VTS_I4 VTS_BOOL VTS_BOOL)
	DISP_FUNCTION(CNComboCtrl, "DeleteColumn", DeleteColumn, VT_BOOL, VTS_I4)
	DISP_FUNCTION(CNComboCtrl, "GetColumnCount", GetColumnCount, VT_I4, VTS_NONE)
	DISP_FUNCTION(CNComboCtrl, "InsertItem", InsertItem, VT_I4, VTS_I4 VTS_BSTR)
	DISP_FUNCTION(CNComboCtrl, "SetItemText", SetItemText, VT_BOOL, VTS_I4 VTS_I4 VTS_BSTR)
	DISP_FUNCTION(CNComboCtrl, "SetItemData", SetItemData, VT_BOOL, VTS_I4 VTS_I4)
	DISP_FUNCTION(CNComboCtrl, "GetItemCount", GetItemCount, VT_I4, VTS_NONE)
	DISP_FUNCTION(CNComboCtrl, "GetItemText", GetItemText, VT_BSTR, VTS_I4 VTS_I4)
	DISP_FUNCTION(CNComboCtrl, "GetItemData", GetItemData, VT_I4, VTS_I4)
	DISP_FUNCTION(CNComboCtrl, "GetColumnName", GetColumnName, VT_BSTR, VTS_I4)
	DISP_PROPERTY_PARAM(CNComboCtrl, "ColumnWidth", GetColumnWidth, SetColumnWidth, VT_I4, VTS_I4)
	DISP_PROPERTY_PARAM(CNComboCtrl, "ColumnVisible", GetColumnVisible, SetColumnVisible, VT_BOOL, VTS_I4)
	DISP_PROPERTY_PARAM(CNComboCtrl, "ColumnEnable", GetColumnEnable, SetColumnEnable, VT_BOOL, VTS_I4)
	DISP_STOCKPROP_FONT()
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CNComboCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


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

BEGIN_EVENT_MAP(CNComboCtrl, COleControl)
	//{{AFX_EVENT_MAP(CNComboCtrl)
	EVENT_CUSTOM("ChangingItem", FireChangingItem, VTS_I4)
	EVENT_CUSTOM("ChangedItem", FireChangedItem, VTS_I4)
	EVENT_CUSTOM("ChangeColumnKey", FireChangeColumnKey, VTS_I4)
	EVENT_CUSTOM("ChangeColumnContent", FireChangeColumnContent, VTS_I2  VTS_BSTR VTS_I4)
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


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

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CNComboCtrl, 2)
	PROPPAGEID(CNComboPropPage::guid)
	PROPPAGEID(CLSID_CFontPropPage )
END_PROPPAGEIDS(CNComboCtrl)


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

IMPLEMENT_OLECREATE_EX(CNComboCtrl, "NCOMBO.NComboCtrl.1",
	0xde201788, 0x9000, 0x11d2, 0x87, 0x26, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9)


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

IMPLEMENT_OLETYPELIB(CNComboCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DNCombo =
		{ 0xde201786, 0x9000, 0x11d2, { 0x87, 0x26, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9 } };
const IID BASED_CODE IID_DNComboEvents =
		{ 0xde201787, 0x9000, 0x11d2, { 0x87, 0x26, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9 } };


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

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

IMPLEMENT_OLECTLTYPE(CNComboCtrl, IDS_NCOMBO, _dwNComboOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::CNComboCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CNComboCtrl

BOOL CNComboCtrl::CNComboCtrlFactory::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_NCOMBO,
			IDB_NCOMBO,
			afxRegApartmentThreading,
			_dwNComboOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// Licensing strings

static const TCHAR BASED_CODE _szLicFileName[] = _T("NCombo.lic");

static const WCHAR BASED_CODE _szLicString[] =
	L"Copyright (c) 1998 Filimon";


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::CNComboCtrlFactory::VerifyUserLicense -
// Checks for existence of a user license

BOOL CNComboCtrl::CNComboCtrlFactory::VerifyUserLicense()
{
	return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
		_szLicString);
}


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::CNComboCtrlFactory::GetLicenseKey -
// Returns a runtime licensing key

BOOL CNComboCtrl::CNComboCtrlFactory::GetLicenseKey(DWORD dwReserved,
	BSTR FAR* pbstrKey)
{
	if (pbstrKey == NULL)
		return FALSE;

	*pbstrKey = SysAllocString(_szLicString);
	return (*pbstrKey != NULL);
}


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::CNComboCtrl - Constructor

// Function name	: CNComboCtrl::CNComboCtrl
// Description	    : Default constructor
// Return type		: 
CNComboCtrl::CNComboCtrl()
{
	InitializeIIDs(&IID_DNCombo, &IID_DNComboEvents);

	m_bCreated = FALSE;
}


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::~CNComboCtrl - Destructor

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


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::OnDraw - Drawing function

void CNComboCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	// do nothing
}


/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl::DoPropExchange - Persistence support

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

	PX_Long(pPX, _T("DropDownHeight"), m_nDropDownHeight, 256);
}


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

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

	SetControlSize(100, m_nDropDownHeight);
}

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

void CNComboCtrl::AboutBox()
{
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CNComboCtrl message handlers

typedef TCHAR (*RNDSTR) (CString* pString);

TCHAR RandomLimited(CString* pString)
{
        return (TCHAR)pString->GetAt(((BYTE)rand()) %
pString->GetLength());
}

TCHAR RandomUnLimited(CString* pString)
{
        return (TCHAR)(BYTE)rand();
}

CString RandomString(int nLength = 16, CString sWhat = _T("0123456789"))
{
        RNDSTR f = sWhat.IsEmpty() ? RandomUnLimited : RandomLimited;
        CString result;
        for (int i = 0; i < nLength; i++)
                result += f(&sWhat);
        return result;
}

// Function name	: CNComboCtrl::OnCreate
// Description	    : On create the control, we will create too a NWindow control
// Return type		: int 
// Argument         : LPCREATESTRUCT lpCreateStruct
int CNComboCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	m_nWindow.m_pControl = this;
	if (m_bCreated = m_nWindow.Create(WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, 0))
	{
/*		m_nWindow.SetResizing();
		m_nWindow.InsertColumn(0, _T("Column 2"), 256, LVCFMT_CENTER, FALSE);
		m_nWindow.InsertColumn(1, _T("Column 2"), 64, LVCFMT_RIGHT);
		m_nWindow.InsertColumn(2, _T("Column 2"), 164);
		m_nWindow.InsertColumn(0, _T("Column 2"), 87);

		for (int i = 0; i < 102; i++)
		{
			CString text;
			text.Format(_T("Item %i"), i);
			int ij = m_nWindow.InsertItem(0, text);
			for (int j = 1; j < 6; j++)
				m_nWindow.SetItemText(ij,j, RandomString());
		}	

		m_nWindow.SetSelectItem(20);*/
	}

⌨️ 快捷键说明

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