您好,登錄后才能下訂單哦!
小編給大家分享一下DeskBand實現之SdkDeskBandObject.cpp文件有什么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
SdkDeskBandObject.cpp文件
說明:這是Desk Band最核心的類,它主要完成Band對象的創建,銷毀,窗體創建,關閉,顯示等。當創建空上對象時,一定要把當前DLL的引用計數加1,對象析構時,DLL的引用計數要減1。
#define _DEFINE_GLOBAL_VARIABLES #include "SdkDeskBandDef.h" #include "SdkDeskBandObject.h" SdkDeskBandObject::SdkDeskBandObject(void) { m_lRefCount = 1; m_dwBandID = 0; m_fHasFocus = FALSE; m_fIsDirty = FALSE; m_dwViewMode = DBIF_VIEWMODE_NORMAL; m_pInputObjSite = NULL; m_pDeskBandWin = NULL; m_fCompositionEnabled = FALSE; // Add the reference count of dll. // This is a global variable defined in SdkDeskBandDef.h file InterlockedIncrement(&g_lDllRefCount); } ////////////////////////////////////////////////////////////////////////// SdkDeskBandObject::~SdkDeskBandObject(void) { // Subtract the reference count of dll. // This is a global variable defined in SdkDeskBandDef.h file InterlockedDecrement(&g_lDllRefCount); SAFE_DELETE(m_pDeskBandWin); SAFE_RELEASE(m_pInputObjSite); } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::QueryInterface(REFIID riid, void** ppv) { static const QITAB qit[] = { QITABENT(SdkDeskBandObject, IDeskBand), QITABENT(SdkDeskBandObject, IDeskBand2), QITABENT(SdkDeskBandObject, IDockingWindow), QITABENT(SdkDeskBandObject, IPersist), QITABENT(SdkDeskBandObject, IPersistStream), QITABENT(SdkDeskBandObject, IInputObject), QITABENT(SdkDeskBandObject, IOleWindow), QITABENT(SdkDeskBandObject, IObjectWithSite), { 0 }, }; return QISearch(this, qit, riid, ppv); } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP_(ULONG) SdkDeskBandObject::AddRef() { return InterlockedIncrement(&m_lRefCount); } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP_(ULONG) SdkDeskBandObject::Release() { ULONG lRef = InterlockedDecrement(&m_lRefCount); if ( 0 == lRef ) { delete this; } return lRef; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::GetWindow(HWND *phwnd) { if ( NULL == phwnd ) { return E_INVALIDARG; } if ( NULL != m_pDeskBandWin ) { *phwnd = m_pDeskBandWin->GetDeskBandHandle(); } return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::ContextSensitiveHelp(BOOL fEnterMode) { UNREFERENCED_PARAMETER(fEnterMode); return E_NOTIMPL; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::ShowDW(BOOL fShow) { if ( NULL != m_pDeskBandWin ) { m_pDeskBandWin->ShowDeskBand(fShow); } return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::CloseDW(DWORD dwReserved) { UNREFERENCED_PARAMETER(dwReserved); if ( NULL != m_pDeskBandWin ) { m_pDeskBandWin->CloseDeskBand(); } return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::ResizeBorderDW(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved) { UNREFERENCED_PARAMETER(prcBorder); UNREFERENCED_PARAMETER(punkToolbarSite); UNREFERENCED_PARAMETER(fReserved); return E_NOTIMPL; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi) { if ( NULL == pdbi ) { return E_INVALIDARG; } m_dwBandID = dwBandID; m_dwViewMode = dwViewMode; SIZE deskBandSize = m_pDeskBandWin->GetDeskBandMinSize( (DBIF_VIEWMODE_VERTICAL == dwViewMode) ? FALSE : TRUE ); POINTL ptMinSize = { deskBandSize.cx, deskBandSize.cy }; POINTL ptActual = { deskBandSize.cx, deskBandSize.cy }; if ( pdbi->dwMask & DBIM_MINSIZE ) { pdbi->ptMinSize = ptMinSize; } if ( pdbi->dwMask & DBIM_ACTUAL ) { pdbi->ptActual = ptActual; } if ( pdbi->dwMask & DBIM_MAXSIZE ) { // There is no limit for the maximum height. pdbi->ptMaxSize.y = -1; } if ( pdbi->dwMask & DBIM_INTEGRAL ) { // The sizing step value of the band object. pdbi->ptIntegral.y = 1; } if ( pdbi->dwMask & DBIM_TITLE ) { // Do NOT show the title by removing the flag. pdbi->dwMask &= ~DBIM_TITLE; } if ( pdbi->dwMask & DBIM_MODEFLAGS ) { pdbi->dwModeFlags = DBIMF_NORMAL | DBIMF_VARIABLEHEIGHT; } if ( pdbi->dwMask & DBIM_BKCOLOR ) { // Use the default background color by removing this flag. pdbi->dwMask &= ~DBIM_BKCOLOR; } return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::CanRenderComposited(BOOL *pfCanRenderComposited) { if ( NULL == pfCanRenderComposited ) { return E_INVALIDARG; } *pfCanRenderComposited = TRUE; return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::SetCompositionState(BOOL fCompositionEnabled) { m_fCompositionEnabled = fCompositionEnabled; if ( NULL != m_pDeskBandWin ) { m_pDeskBandWin->RefreshDeskBand(); } return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::GetCompositionState(BOOL *pfCompositionEnabled) { if ( NULL == pfCompositionEnabled ) { return E_INVALIDARG; } *pfCompositionEnabled = m_fCompositionEnabled; return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::GetClassID(CLSID *pclsid) { if ( NULL == pclsid ) { return E_INVALIDARG; } *pclsid = CLSID_SdkDeskBand; return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::IsDirty() { return (TRUE == m_fIsDirty) ? S_OK : S_FALSE; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::Load(IStream *pStm) { UNREFERENCED_PARAMETER(pStm); return E_NOTIMPL; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::Save(IStream *pStm, BOOL fClearDirty) { UNREFERENCED_PARAMETER(pStm); if ( TRUE == fClearDirty ) { m_fIsDirty = FALSE; } return E_NOTIMPL; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::GetSizeMax(ULARGE_INTEGER *pcbSize) { UNREFERENCED_PARAMETER(pcbSize); return E_NOTIMPL; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::SetSite(IUnknown *pUnkSite) { SAFE_RELEASE(m_pInputObjSite); if ( NULL == pUnkSite ) { return S_OK; } IOleWindow *pOleWindow = NULL; HRESULT hr = pUnkSite->QueryInterface(IID_PPV_ARGS(&pOleWindow)); if ( SUCCEEDED(hr) ) { HWND hParentWnd = NULL; hr = pOleWindow->GetWindow(&hParentWnd); if ( SUCCEEDED(hr) ) { // Create the desk band window. if ( NULL != m_pDeskBandWin ) { // g_hDllInst is a global variable to // indicate instance of current dll defined // in SdkDeskBanddef.h file. m_pDeskBandWin->CreateDeskBand(hParentWnd, g_hDllInst, this); } } hr = pUnkSite->QueryInterface(IID_PPV_ARGS(&m_pInputObjSite)); } SAFE_RELEASE(pOleWindow); return hr; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::GetSite(REFIID riid, void **ppv) { if ( NULL == ppv ) { return E_INVALIDARG; } HRESULT hr = E_FAIL; if ( NULL == m_pInputObjSite ) { *ppv = NULL; } else { hr = m_pInputObjSite->QueryInterface(riid, ppv); } return hr; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::UIActivateIO(BOOL fActivate, MSG *pMsg) { UNREFERENCED_PARAMETER(pMsg); if ( TRUE == fActivate ) { if ( NULL != m_pDeskBandWin ) { SetFocus(m_pDeskBandWin->GetDeskBandHandle()); } } return S_OK; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::HasFocusIO() { return (TRUE == m_fHasFocus) ? S_OK : S_FALSE; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkDeskBandObject::TranslateAcceleratorIO(MSG *pMsg) { UNREFERENCED_PARAMETER(pMsg); return S_FALSE; } ////////////////////////////////////////////////////////////////////////// BOOL SdkDeskBandObject::OnSetFocus(BOOL fSetFocus) { if ( NULL == m_pInputObjSite ) { return FALSE; } m_fHasFocus = fSetFocus; HRESULT hr = m_pInputObjSite->OnFocusChangeIS( static_cast<IOleWindow*>(this), fSetFocus); return SUCCEEDED(hr) ? TRUE : FALSE; } ////////////////////////////////////////////////////////////////////////// BOOL SdkDeskBandObject::IsVerticalViewMode() { return (DBIF_VIEWMODE_VERTICAL == m_dwViewMode) ? TRUE : FALSE; }
SdkClassFactory.cpp文件
說明:這個類用于創建Band對象,在其CreateInstance方法里面,就要創建出Band對象,它由DllGetClassObject函數調用。
SdkClassFactory::SdkClassFactory(void) { m_lRefCount = 1; // Add the reference count of dll. This is a global // variable defined in SdkDeskBandDef.h file InterlockedIncrement(&g_lDllRefCount); } ////////////////////////////////////////////////////////////////////////// SdkClassFactory::~SdkClassFactory(void) { // Subtract the reference count of dll. This is a global // variable defined in SdkDeskBandDef.h file InterlockedDecrement(&g_lDllRefCount); } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkClassFactory::QueryInterface(REFIID riid, void **ppv) { static const QITAB qit[] = { QITABENT(SdkClassFactory, IUnknown), QITABENT(SdkClassFactory, IClassFactory), { 0 }, }; return QISearch(this, qit, riid, ppv); } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP_(ULONG) SdkClassFactory::AddRef() { return InterlockedIncrement(&m_lRefCount); } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP_(ULONG) SdkClassFactory::Release() { ULONG lRef = InterlockedDecrement(&m_lRefCount); if ( 0 == lRef ) { delete this; } return m_lRefCount; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkClassFactory::CreateInstance( IUnknown *pUnkOuter, REFIID riid, void **ppv) { HRESULT hr = CLASS_E_NOAGGREGATION; if ( NULL == pUnkOuter ) { hr = E_OUTOFMEMORY; SdkDeskBandObject *pDeskBand = new SdkDeskBandObject(); if ( NULL != pDeskBand ) { hr = pDeskBand->QueryInterface(riid, ppv); } SAFE_RELEASE(pDeskBand); } return hr; } ////////////////////////////////////////////////////////////////////////// STDMETHODIMP SdkClassFactory::LockServer(BOOL fLock) { if ( TRUE == fLock ) { // Add the reference count of dll. This is a // global variable defined in SdkDeskBandDef.h file. InterlockedIncrement(&g_lDllRefCount); } else { // Subtract the reference count of dll. This is // a global variable defined in SdkDeskBandDef.h file. InterlockedDecrement(&g_lDllRefCount); } return S_OK; }
以上是“DeskBand實現之SdkDeskBandObject.cpp文件有什么用”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。