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

📄 componentdata.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include <Shlwapi.h>#include <Shlobj.H>#include "ComponentData.h"   // class implemented#include "WarMmcSnapin.h"#include "StaticNode.h"#include "Component.h"#include "DataObject.h"/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================CComponentData::CComponentData(): m_cref(0), m_ipConsoleNameSpace(NULL), m_ipConsole(NULL){    OBJECT_CREATED    m_pStaticNode = new CStaticNode;}CComponentData::~CComponentData(){    if (m_pStaticNode)     {        delete m_pStaticNode;    }    OBJECT_DESTROYED}//============================= OPERATORS ====================================//============================= OPERATIONS ===================================///////////////////////// IUnknown implementation///////////////////////STDMETHODIMP CComponentData::QueryInterface(REFIID riid, LPVOID *ppv){    if (!ppv)        return E_FAIL;    *ppv = NULL;    if (IsEqualIID(riid, IID_IUnknown))        *ppv = static_cast<IComponentData *>(this);    else if (IsEqualIID(riid, IID_IComponentData))        *ppv = static_cast<IComponentData *>(this);    // first things first, make sure that when MMC    // asks if we do property sheets, that we actually    // say "yes"    else if (IsEqualIID(riid, IID_IExtendPropertySheet) ||        IsEqualIID(riid, IID_IExtendPropertySheet2))        *ppv = static_cast<IExtendPropertySheet2 *>(this);    if (*ppv)    {        reinterpret_cast<IUnknown *>(*ppv)->AddRef();        return S_OK;    }    return E_NOINTERFACE;}STDMETHODIMP_(ULONG) CComponentData::AddRef(){    return InterlockedIncrement((LONG *)&m_cref);}STDMETHODIMP_(ULONG) CComponentData::Release(){    if (InterlockedDecrement((LONG *)&m_cref) == 0)    {        // we need to decrement our object count in the DLL        delete this;        return 0;    }    return m_cref;}///////////////////////////////// Interface IComponentData///////////////////////////////HRESULT CComponentData::Initialize(                                   /* [in] */ LPUNKNOWN pUnknown){    HRESULT      hr;    //    // Get pointer to name space interface    //    hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);    _ASSERT( S_OK == hr );    //    // Get pointer to console interface    //    hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);    _ASSERT( S_OK == hr );    IImageList *pImageList;    m_ipConsole->QueryScopeImageList(&pImageList);    _ASSERT( S_OK == hr );    hr = pImageList->ImageListSetStrip( (long *)m_pStaticNode->m_pBMapSm, // pointer to a handle        (long *)m_pStaticNode->m_pBMapLg, // pointer to a handle        0, // index of the first image in the strip        RGB(0, 128, 128)  // color of the icon mask        );    pImageList->Release();    return S_OK;}HRESULT CComponentData::CreateComponent(                                        /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent){    *ppComponent = NULL;    CComponent *pComponent = new CComponent(this);    if (NULL == pComponent)        return E_OUTOFMEMORY;    return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);}HRESULT CComponentData::Notify(                               /* [in] */ LPDATAOBJECT lpDataObject,                               /* [in] */ MMC_NOTIFY_TYPE event,                               /* [in] */ LPARAM arg,                               /* [in] */ LPARAM param){    MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);    HRESULT hr = S_FALSE;	//Get our data object. If it is NULL, we return with S_FALSE.	//See implementation of GetOurDataObject() to see how to	//handle special data objects.	CDataObject *pDataObject = GetOurDataObject(lpDataObject);	if (NULL == pDataObject)		return S_FALSE;		CDelegationBase *base = pDataObject->GetBaseNodeObject();    switch (event)    {    case MMCN_EXPAND:        hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);        break;    }    return hr;}HRESULT CComponentData::Destroy( void){    // Free interfaces    if (m_ipConsoleNameSpace) {        m_ipConsoleNameSpace->Release();        m_ipConsoleNameSpace = NULL;    }    if (m_ipConsole) {        m_ipConsole->Release();        m_ipConsole = NULL;    }    return S_OK;}HRESULT CComponentData::QueryDataObject(                                        /* [in] */ MMC_COOKIE cookie,                                        /* [in] */ DATA_OBJECT_TYPES type,                                        /* [out] */ LPDATAOBJECT *ppDataObject){    CDataObject *pObj = NULL;    if (cookie == 0)        pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);    else        pObj = new CDataObject(cookie, type);    if (!pObj)        return E_OUTOFMEMORY;    pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);    return S_OK;}HRESULT CComponentData::GetDisplayInfo(                                       /* [out][in] */ SCOPEDATAITEM *pScopeDataItem){    HRESULT hr = S_FALSE;    // if they are asking for the SDI_STR we have one of those to give    if (pScopeDataItem->lParam) {        CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;        if (pScopeDataItem->mask & SDI_STR) {                        LPCTSTR pszT = base->GetDisplayName();                        MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);            pScopeDataItem->displayname = pszW;        }        if (pScopeDataItem->mask & SDI_IMAGE) {            pScopeDataItem->nImage = base->GetBitmapIndex();        }    }    return hr;}HRESULT CComponentData::CompareObjects(                                       /* [in] */ LPDATAOBJECT lpDataObjectA,                                       /* [in] */ LPDATAOBJECT lpDataObjectB){    CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();    CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();    // compare the object pointers    if (baseA->GetCookie() == baseB->GetCookie())        return S_OK;    return S_FALSE;}HRESULT CStaticNode::CreatePropertyPages(IPropertySheetCallback *lpProvider, LONG_PTR handle){    PROPSHEETPAGE psp;    HPROPSHEETPAGE hPage = NULL;        psp.dwSize = sizeof(PROPSHEETPAGE);    psp.dwFlags = PSP_DEFAULT;    psp.hInstance = g_hinst;    psp.pszTemplate = MAKEINTRESOURCE(IDD_CHOOSER_CHOOSE_MACHINE);    psp.pfnDlgProc = DialogProc;    psp.lParam = reinterpret_cast<LPARAM>(&snapInData);    psp.pszTitle = MAKEINTRESOURCE(IDS_SELECT_COMPUTER);        hPage = CreatePropertySheetPage(&psp);    _ASSERT(hPage);        return lpProvider->AddPage(hPage);}HRESULT CStaticNode::HasPropertySheets(){    return S_OK;}HRESULT CStaticNode::GetWatermarks(HBITMAP *lphWatermark,                                   HBITMAP *lphHeader,                                   HPALETTE *lphPalette,                                   BOOL *bStretch){    *lphHeader = (HBITMAP)LoadImage(g_hinst, MAKEINTRESOURCE(IDB_HEADER), IMAGE_BITMAP, 0, 0, 0);    *lphWatermark = (HBITMAP)LoadImage(g_hinst, MAKEINTRESOURCE(IDB_WATERMARK), IMAGE_BITMAP, 0, 0, 0);    *bStretch = FALSE;        return S_OK;}///////////////////////////////////// Interface IExtendPropertySheet2///////////////////////////////////HRESULT CComponentData::CreatePropertyPages(                                            /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,                                            /* [in] */ LONG_PTR handle,                                            /* [in] */ LPDATAOBJECT lpIDataObject){    CDelegationBase *base = GetOurDataObject(lpIDataObject)->GetBaseNodeObject();    return base->CreatePropertyPages(lpProvider, handle);}HRESULT CComponentData::QueryPagesFor(                                      /* [in] */ LPDATAOBJECT lpDataObject){    CDelegationBase *base = GetOurDataObject(lpDataObject)->GetBaseNodeObject();    return base->HasPropertySheets();}HRESULT CComponentData::GetWatermarks(                                      /* [in] */ LPDATAOBJECT lpIDataObject,                                      /* [out] */ HBITMAP __RPC_FAR *lphWatermark,                                      /* [out] */ HBITMAP __RPC_FAR *lphHeader,                                      /* [out] */ HPALETTE __RPC_FAR *lphPalette,                                      /* [out] */ BOOL __RPC_FAR *bStretch){    CDelegationBase *base = GetOurDataObject(lpIDataObject)->GetBaseNodeObject();    return base->GetWatermarks(lphWatermark, lphHeader, lphPalette, bStretch);}//============================= ACCESS     ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ////////////////////////////////////////////////////////////////// PRIVATE    ///////////////////////////////////

⌨️ 快捷键说明

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