📄 xfloorwndctl.cpp
字号:
/************************************
REVISION LOG ENTRY
Revision By: Mihai Filimon
Revised on 10/8/98 3:52:57 PM
Comments: XFloorWndCtl.cpp : Implementation of the CXFloorWndCtrl ActiveX Control class.
************************************/
#include "stdafx.h"
#include "XFloorWnd.h"
#include "XFloorWndCtl.h"
#include "XFloorWndPpg.h"
#include "FloorLabeObject.h"
#include "gdi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CXFloorWndCtrl, COleControl)
#ifdef _OBEJCTISSAFETY
//Implementation IObjectSafety
BEGIN_INTERFACE_MAP(CXFloorWndCtrl, COleControl)
INTERFACE_PART(CXFloorWndCtrl, IID_IObjectSafety, ObjectSafety)
END_INTERFACE_MAP()
STDMETHODIMP CXFloorWndCtrl::XObjectSafety::GetInterfaceSafetyOptions(
REFIID riid,
DWORD __RPC_FAR *pdwSupportedOptions,
DWORD __RPC_FAR *pdwEnabledOptions)
{
METHOD_PROLOGUE_EX(CXFloorWndCtrl, ObjectSafety)
if (!pdwSupportedOptions || !pdwEnabledOptions)
{
return E_POINTER;
}
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
*pdwEnabledOptions = 0;
if (NULL == pThis->GetInterface(&riid))
{
TRACE("Requested interface is not supported.\n");
return E_NOINTERFACE;
}
// What interface is being checked out anyhow?
OLECHAR szGUID[39];
int i = StringFromGUID2(riid, szGUID, 39);
if (riid == IID_IDispatch)
{
// Client wants to know if object is safe for scripting
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
return S_OK;
}
else if (riid == IID_IPersistPropertyBag
|| riid == IID_IPersistStreamInit
|| riid == IID_IPersistStorage
|| riid == IID_IPersistMemory)
{
// Those are the persistence interfaces COleControl derived controls support
// as indicated in AFXCTL.H
// Client wants to know if object is safe for initializing from persistent data
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
return S_OK;
}
else
{
// Find out what interface this is, and decide what options to enable
TRACE("We didn't account for the safety of this interface, and it's one we support...\n");
return E_NOINTERFACE;
}
}
STDMETHODIMP CXFloorWndCtrl::XObjectSafety::SetInterfaceSafetyOptions(
REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions)
{
METHOD_PROLOGUE_EX(CXFloorWndCtrl, ObjectSafety)
OLECHAR szGUID[39];
// What is this interface anyway?
// We can do a quick lookup in the registry under HKEY_CLASSES_ROOT\Interface
int i = StringFromGUID2(riid, szGUID, 39);
if (0 == dwOptionSetMask && 0 == dwEnabledOptions)
{
// the control certainly supports NO requests through the specified interface
// so it's safe to return S_OK even if the interface isn't supported.
return S_OK;
}
// Do we support the specified interface?
if (NULL == pThis->GetInterface(&riid))
{
TRACE1("%s is not support.\n", szGUID);
return E_FAIL;
}
if (riid == IID_IDispatch)
{
TRACE("Client asking if it's safe to call through IDispatch.\n");
TRACE("In other words, is the control safe for scripting?\n");
if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions)
{
return S_OK;
}
else
{
return E_FAIL;
}
}
else if (riid == IID_IPersistPropertyBag
|| riid == IID_IPersistStreamInit
|| riid == IID_IPersistStorage
|| riid == IID_IPersistMemory)
{
TRACE("Client asking if it's safe to call through IPersist*.\n");
TRACE("In other words, is the control safe for initializing from persistent data?\n");
if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions)
{
return NOERROR;
}
else
{
return E_FAIL;
}
}
else
{
TRACE1("We didn't account for the safety of %s, and it's one we support...\n", szGUID);
return E_FAIL;
}
}
STDMETHODIMP_(ULONG) CXFloorWndCtrl::XObjectSafety::AddRef()
{
METHOD_PROLOGUE_EX_(CXFloorWndCtrl, ObjectSafety)
return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CXFloorWndCtrl::XObjectSafety::Release()
{
METHOD_PROLOGUE_EX_(CXFloorWndCtrl, ObjectSafety)
return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP CXFloorWndCtrl::XObjectSafety::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(CXFloorWndCtrl, ObjectSafety)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
#endif //_OBEJCTISSAFETY
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CXFloorWndCtrl, COleControl)
//{{AFX_MSG_MAP(CXFloorWndCtrl)
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
ON_WM_ERASEBKGND()
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CXFloorWndCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CXFloorWndCtrl)
DISP_PROPERTY_NOTIFY(CXFloorWndCtrl, "Animation", m_bAnimation, OnAnimationChanged, VT_BOOL)
DISP_PROPERTY_NOTIFY(CXFloorWndCtrl, "Sleep", m_nSleep, OnSleepChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CXFloorWndCtrl, "Sign", m_bSign, OnSignChanged, VT_BOOL)
DISP_PROPERTY_NOTIFY(CXFloorWndCtrl, "Pages", m_sPages, OnPagesChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY(CXFloorWndCtrl, "AsPage", m_bAsPage, OnAsPageChanged, VT_BOOL)
DISP_FUNCTION(CXFloorWndCtrl, "AddPage", _AddPage, VT_I2, VTS_BSTR)
DISP_FUNCTION(CXFloorWndCtrl, "DeletePage", _DeletePage, VT_BOOL, VTS_I2)
DISP_FUNCTION(CXFloorWndCtrl, "GetPageName", _GetPageName, VT_BSTR, VTS_I2)
DISP_FUNCTION(CXFloorWndCtrl, "GetPage", _GetPage, VT_I2, VTS_BSTR)
DISP_FUNCTION(CXFloorWndCtrl, "ActivatePage", _ActivatePage, VT_BOOL, VTS_I2)
DISP_FUNCTION(CXFloorWndCtrl, "AttachWindow", _AttachWindow, VT_BOOL, VTS_I2 VTS_I4)
DISP_FUNCTION(CXFloorWndCtrl, "SetPageName", _SetPageName, VT_BOOL, VTS_I2 VTS_BSTR)
DISP_FUNCTION(CXFloorWndCtrl, "Init", _Init, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CXFloorWndCtrl, "GetActivePage", _GetActivePage, VT_I2, VTS_NONE)
DISP_FUNCTION(CXFloorWndCtrl, "GetPagesCount", _GetPagesCount, VT_I4, VTS_NONE)
DISP_FUNCTION(CXFloorWndCtrl, "IsPage", _IsPage, VT_BOOL, VTS_I2)
DISP_FUNCTION(CXFloorWndCtrl, "GetLeftTopPage", _GetLeftTopPage, VT_I4, VTS_I2)
DISP_FUNCTION(CXFloorWndCtrl, "GetBottomRightPage", _GetBottomRightPage, VT_I4, VTS_I2)
DISP_FUNCTION(CXFloorWndCtrl, "StyleAs", StyleAs, VT_EMPTY, VTS_BOOL)
DISP_FUNCTION(CXFloorWndCtrl, "GetHWnd", GetHWnd, VT_I4, VTS_I4)
DISP_PROPERTY_PARAM(CXFloorWndCtrl, "Height", GetHeight, SetHeight, VT_I2, VTS_I2)
DISP_PROPERTY_PARAM(CXFloorWndCtrl, "Color", GetColor, SetColor, VT_COLOR, VTS_I2)
DISP_PROPERTY_PARAM(CXFloorWndCtrl, "UserData", GetUserData, SetUserData, VT_I4, VTS_I2)
DISP_STOCKPROP_BACKCOLOR()
DISP_STOCKPROP_FONT()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CXFloorWndCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CXFloorWndCtrl, COleControl)
//{{AFX_EVENT_MAP(CXFloorWndCtrl)
EVENT_CUSTOM("ActivatePage", FireActivatePage, VTS_I2)
EVENT_CUSTOM("ClickOnActivePage", FireClickOnActivePage, VTS_I2)
EVENT_STOCK_CLICK()
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CXFloorWndCtrl, 3)
PROPPAGEID(CXFloorWndPropPage::guid)
PROPPAGEID(CLSID_CColorPropPage)
PROPPAGEID(CLSID_CFontPropPage)
END_PROPPAGEIDS(CXFloorWndCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CXFloorWndCtrl, "XFLOORWND.XFloorWndCtrl.1",
0x24ffd1ed, 0x5ea9, 0x11d2, 0x86, 0xb1, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CXFloorWndCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DXFloorWnd =
{ 0x24ffd1eb, 0x5ea9, 0x11d2, { 0x86, 0xb1, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9 } };
const IID BASED_CODE IID_DXFloorWndEvents =
{ 0x24ffd1ec, 0x5ea9, 0x11d2, { 0x86, 0xb1, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwXFloorWndOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CXFloorWndCtrl, IDS_XFLOORWND, _dwXFloorWndOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CXFloorWndCtrl::CXFloorWndCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CXFloorWndCtrl
BOOL CXFloorWndCtrl::CXFloorWndCtrlFactory::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_XFLOORWND,
IDB_XFLOORWND,
afxRegApartmentThreading,
_dwXFloorWndOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CXFloorWndCtrl::CXFloorWndCtrl - Constructor
CFloorPageObject* CXFloorWndCtrl::m_pFocusPage = NULL;
UINT CXFloorWndCtrl::m_nMessageChange = NULL;
CRect CXFloorWndCtrl::m_rtBorder(CPoint(-2,-2), CSize(0,0));
// Function name : CXFloorWndCtrl::CXFloorWndCtrl
// Description : Default constructor
// Return type :
CXFloorWndCtrl::CXFloorWndCtrl()
{
InitializeIIDs(&IID_DXFloorWnd, &IID_DXFloorWndEvents);
RegClassFloorWnd();
m_pActivePage = NULL;
m_nSleep = 0;
m_pArPage = new CArrayPage();
m_nDYLabel = GetSystemMetrics(SM_CYCAPTION); // a default value...
m_nDYCombo = 10 * m_nDYLabel; // a default value...
}
/////////////////////////////////////////////////////////////////////////////
// CXFloorWndCtrl::~CXFloorWndCtrl - Destructor
// Function name : CXFloorWndCtrl::~CXFloorWndCtrl
// Description : default destructor
// Return type :
CXFloorWndCtrl::~CXFloorWndCtrl()
{
while (DeletePage(0));
if (m_pArPage)
delete m_pArPage;
m_pArPage = NULL;
}
/////////////////////////////////////////////////////////////////////////////
// CXFloorWndCtrl::OnDraw - Drawing function
void CXFloorWndCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
if (m_hWnd)
if (::IsWindow(m_hWnd))
{
CDC dcMem; CBitmap bmpMem;
CRect r; GetClientRect(r);
if (dcMem.CreateCompatibleDC(pdc))
if (bmpMem.CreateCompatibleBitmap(pdc, r.Width(), r.Height()))
{
CBitmap* pBitmap = dcMem.SelectObject(&bmpMem);
COLORREF colorBkGnd = TranslateColor(GetBackColor());
CBrush brBkGnd(colorBkGnd);
CBrush* pBrush = dcMem.SelectObject(&brBkGnd);
//Erase the bkgnd of this
dcMem.PatBlt(r.left, r.top, r.right, r.bottom, PATCOPY);
for (int i = 0; i < GetCountPage(); i++)
GetPage(i)->OnDraw(&dcMem, TRUE);
pdc->BitBlt(r.left,r.top,r.Width(), r.Height(), &dcMem, 0,0, SRCCOPY);
dcMem.SelectObject(pBitmap);
dcMem.SelectObject(pBrush);
}
return;
}
// Write the version
COLORREF colorBkGnd = TranslateColor(GetBackColor());
CBrush brBkGnd(colorBkGnd);
CBrush* pBrush = pdc->SelectObject(&brBkGnd);
//Erase the bkgnd of this
pdc->PatBlt(rcInvalid.left, rcInvalid.top, rcInvalid.right, rcInvalid.bottom, PATCOPY);
CFont* pFont = SelectStockFont(pdc);
CString version; version.Format(_T("XFloorWnd %i.%02i"), _wVerMajor, _wVerMinor);
pdc->SetBkMode(TRANSPARENT);
pdc->DrawText(version, CRect(rcInvalid), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
pdc->SelectObject(pFont);
pdc->SelectObject(pBrush);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -