Click here to Skip to main content
15,891,688 members
Articles / Programming Languages / C#

Windows Development in C++, COM API Clients

Rate me:
Please Sign up or sign in to vote.
4.98/5 (31 votes)
3 Jan 2015CPOL7 min read 63K   1.6K   106  
Using the Facade Pattern to simplify development with COM based APIs
//hwincomcontrolsite.h
#pragma once
#ifndef __HWINCOMCONTROLSITE_H__
#define __HWINCOMCONTROLSITE_H__

#include "hwincontrol.h"
#include "hwinobjimpl.h"
#include "hwincomobject.h"

namespace harlinn
{
    namespace windows
    {
        class ComControlSite : public ComObject,
            IOleClientSiteImpl<ComControlSite>,
            IOleControlSiteImpl<ComControlSite>,
            IOleInPlaceSiteImpl<ComControlSite>,
            IAdviseSinkImpl<ComControlSite>,
            IOleDocumentSiteImpl<ComControlSite>,
            IOleUIObjInfoImpl<ComControlSite>
        {
        public:
            
            

            typedef ComObject Base;
            ComControlSite( std::shared_ptr<Control> theControl )
                : Base(theControl),
                  IOleClientSiteImpl<ComControlSite>(this),
                  IOleControlSiteImpl<ComControlSite>(this),
                  IOleInPlaceSiteImpl<ComControlSite>(this),
                  IAdviseSinkImpl<ComControlSite>(this),
                  IOleDocumentSiteImpl<ComControlSite>(this),
                  IOleUIObjInfoImpl<ComControlSite>(this)
            {}


            virtual HRESULT QueryInterface( REFIID riid,void ** ppvObject)
            {
                return Base::QueryInterface( riid,ppvObject);
            }

            virtual ULONG STDMETHODCALLTYPE AddRef( )
            {
                return Base::AddRef( );
            }

            virtual ULONG STDMETHODCALLTYPE Release( )
            {
                return Base::Release( );
            }

            // IOleWindow
            HWIN_EXPORT HRESULT GetWindow(HWND *phwnd);
            HWIN_EXPORT HRESULT ContextSensitiveHelp(BOOL fEnterMode);

            // IOleClientSite
            HWIN_EXPORT HRESULT SaveObject( );
            HWIN_EXPORT HRESULT GetMoniker( DWORD dwAssign,DWORD dwWhichMoniker,IMoniker **ppmk);
            HWIN_EXPORT HRESULT GetContainer( IOleContainer **ppContainer);
            HWIN_EXPORT HRESULT ShowObject( );
            HWIN_EXPORT HRESULT OnShowWindow( BOOL fShow);
            HWIN_EXPORT HRESULT RequestNewObjectLayout( );

            // IOleControlSite
            HWIN_EXPORT HRESULT OnControlInfoChanged( );
            HWIN_EXPORT HRESULT LockInPlaceActive( BOOL fLock);
            HWIN_EXPORT HRESULT GetExtendedControl( IDispatch **ppDisp);
            HWIN_EXPORT HRESULT TransformCoords( POINTL *pPtlHimetric,POINTF *pPtfContainer, DWORD dwFlags);
            HWIN_EXPORT HRESULT TranslateAccelerator( MSG *pMsg,DWORD grfModifiers);
            HWIN_EXPORT HRESULT OnFocus( BOOL fGotFocus);
            HWIN_EXPORT HRESULT ShowPropertyFrame( );

            HWIN_EXPORT HRESULT CanInPlaceActivate( );
            HWIN_EXPORT HRESULT OnInPlaceActivate( );
            HWIN_EXPORT HRESULT OnUIActivate( );
            HWIN_EXPORT HRESULT GetWindowContext( IOleInPlaceFrame **ppFrame,IOleInPlaceUIWindow **ppDoc,LPRECT lprcPosRect,LPRECT lprcClipRect,LPOLEINPLACEFRAMEINFO lpFrameInfo);
            HWIN_EXPORT HRESULT Scroll( SIZE scrollExtant);
            HWIN_EXPORT HRESULT OnUIDeactivate( BOOL fUndoable);
            HWIN_EXPORT HRESULT OnInPlaceDeactivate( );
            HWIN_EXPORT HRESULT DiscardUndoState( );
            HWIN_EXPORT HRESULT DeactivateAndUndo( );
            HWIN_EXPORT HRESULT OnPosRectChange( LPCRECT lprcPosRect);

            // IAdviseSinkImpl
            HWIN_EXPORT void OnDataChange( FORMATETC *pFormatetc,STGMEDIUM *pStgmed);
            HWIN_EXPORT void OnViewChange( DWORD dwAspect,LONG lindex);
            HWIN_EXPORT void OnRename( IMoniker *pmk);
            HWIN_EXPORT void OnSave( );
            HWIN_EXPORT void OnClose( );

            // IOleUIObjInfo
            HWIN_EXPORT HRESULT GetObjectInfo(DWORD dwObject,DWORD* lpdwObjSize, LPWSTR * lplpszLabel,LPWSTR FAR* lplpszType, LPWSTR * lplpszShortType,LPWSTR * lplpszLocation);
            HWIN_EXPORT HRESULT GetConvertInfo(DWORD dwObject,
                                                CLSID * lpClassID, WORD * lpwFormat,
                                                CLSID * lpConvertDefaultClassID,
                                                LPCLSID * lplpClsidExclude, UINT * lpcClsidExclude);
            HWIN_EXPORT HRESULT ConvertObject(DWORD dwObject, REFCLSID clsidNew);
            
            HWIN_EXPORT HRESULT GetViewInfo (DWORD dwObject,HGLOBAL * phMetaPict, DWORD* pdvAspect, int* pnCurrentScale);
            HWIN_EXPORT HRESULT SetViewInfo (DWORD dwObject,HGLOBAL hMetaPict, DWORD dvAspect,int nCurrentScale, BOOL bRelativeToOrig);

            // IOleDocumentSite
            HWIN_EXPORT HRESULT ActivateMe(IOleDocumentView *pViewToActivate);



        };
    }
}


#endif //hwincomcontrolsite.h

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions