📄 singleocxctl.cpp
字号:
// SingleOcxCtl.cpp : Implementation of the CSingleOcxCtrl ActiveX Control class.
#include "stdafx.h"
#include "SingleOcx.h"
#include "SingleOcxCtl.h"
#include "SingleOcxPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CSingleOcxCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CSingleOcxCtrl, COleControl)
//{{AFX_MSG_MAP(CSingleOcxCtrl)
// NOTE - ClassWizard will add and remove message map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CSingleOcxCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CSingleOcxCtrl)
DISP_PROPERTY_NOTIFY(CSingleOcxCtrl, "xPos", m_xPos, OnXPosChanged, VT_I2)
DISP_PROPERTY_EX(CSingleOcxCtrl, "yPos", GetYPos, SetYPos, VT_I2)
DISP_FUNCTION(CSingleOcxCtrl, "SetText", SetText, VT_EMPTY, VTS_BSTR)
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CSingleOcxCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CSingleOcxCtrl, COleControl)
//{{AFX_EVENT_MAP(CSingleOcxCtrl)
EVENT_CUSTOM("SINGLEOLEERR", FireSINGLEOLEERR, VTS_BSTR)
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CSingleOcxCtrl, 1)
PROPPAGEID(CSingleOcxPropPage::guid)
END_PROPPAGEIDS(CSingleOcxCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CSingleOcxCtrl, "SINGLEOCX.SingleOcxCtrl.1",
0x9336be03, 0xe76a, 0x4950, 0x84, 0xab, 0x98, 0x9e, 0x85, 0x4e, 0x7c, 0xdd)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CSingleOcxCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DSingleOcx =
{ 0xfe75388f, 0x55f7, 0x4187, { 0xa4, 0x77, 0xbc, 0xa3, 0x12, 0xb5, 0xc4, 0xfd } };
const IID BASED_CODE IID_DSingleOcxEvents =
{ 0xbe228166, 0x8589, 0x48c1, { 0xae, 0xff, 0x41, 0xc, 0x9a, 0x8f, 0x83, 0xa3 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwSingleOcxOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CSingleOcxCtrl, IDS_SINGLEOCX, _dwSingleOcxOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::CSingleOcxCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CSingleOcxCtrl
BOOL CSingleOcxCtrl::CSingleOcxCtrlFactory::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_SINGLEOCX,
IDB_SINGLEOCX,
afxRegApartmentThreading,
_dwSingleOcxOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::CSingleOcxCtrl - Constructor
CSingleOcxCtrl::CSingleOcxCtrl()
{
InitializeIIDs(&IID_DSingleOcx, &IID_DSingleOcxEvents);
m_xPos = 0 ;
m_strText = "简单的ActiveX控件" ;
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::~CSingleOcxCtrl - Destructor
CSingleOcxCtrl::~CSingleOcxCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::OnDraw - Drawing function
void CSingleOcxCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
CRect r(rcBounds);
r.left = m_xPos ;
r.top = GetYPos() ;
pdc->DrawText(m_strText,r,DT_LEFT);
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::DoPropExchange - Persistence support
void CSingleOcxCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// PX_Long(pPX,_T("xPos"),m_xPos,0);
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::OnResetState - Reset control to default state
void CSingleOcxCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl::AboutBox - Display an "About" box to the user
void CSingleOcxCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_SINGLEOCX);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSingleOcxCtrl message handlers
void CSingleOcxCtrl::OnXPosChanged()
{
InvalidateControl();
SetModifiedFlag();
}
short CSingleOcxCtrl::GetYPos()
{
// TODO: Add your property handler here
return 0;
}
void CSingleOcxCtrl::SetYPos(short nNewValue)
{
CString strMess ;
strMess.Format("%d",nNewValue);
AfxMessageBox(strMess);
// TODO: Add your property handler here
SetModifiedFlag();
}
void CSingleOcxCtrl::SetText(LPCTSTR lpText)
{
m_strText = lpText ;
if(m_strText.GetLength() > 100 )
{
m_strText = m_strText.Left(100) ;
FireSINGLEOLEERR("控件文本过长");
}
InvalidateControl();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -