Problem with a Deskband using ATL
Hello All,
I'm a new to ATL, so I'm stuck on a problem.
I'm using ATL to build a Deskband object & I want to build the GUI
using MFC. I built the same project using simple Win32 & COM, which
worked okay. But using ATL, I'm running into a problem I'm unable to
fix.
My Problem is that the Deskband is displayed, the CEdit Control or
Button, whatever I choose to create is created, but NOT ON THE
DESKBAND. It gets created somewhere else.........
My Class Definition is as follows:
class ATL_NO_VTABLE CPluginPlatform : public
CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CPluginPlatform, &CLSID_PluginPlatform>,
public IObjectWithSiteImpl<CPluginPlatform>,
//public IDispatchImpl<IPluginPlatform, &IID_IPluginPlatform,
&LIBID_RSTBLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
public IDeskBand,
//public IDispEventImpl <1, CPluginPlatform,
&DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>,
public IInputObject {
public:
// Constructor
CPluginPlatform();
DECLARE_REGISTRY_RESOURCEID(IDR_PLUGINPLATFORM) // Indicates that a
registry script is defined for this ATL class
DECLARE_NOT_AGGREGATABLE(CPluginPlatform) // Declares that the
objct is not Aggregatable
// COM Interfaces whose pointers are to be returned by Query
Interface are written in the COM Map
BEGIN_COM_MAP (CPluginPlatform)
// COM_INTERFACE_ENTRY (IPluginPlatform) // This class
// COM_INTERFACE_ENTRY (IDispatch) // This interfaces uses
SINK MAPS to allow external applications to capture events
COM_INTERFACE_ENTRY (IObjectWithSite) // Used to Plug into
IE
COM_INTERFACE_ENTRY (IDeskBand) // GUI relevant
information of the deskband to be implemented
COM_INTERFACE_ENTRY2 (IOleWindow, IDeskBand)
COM_INTERFACE_ENTRY2 (IDockingWindow, IDeskBand)
// COM_INTERFACE_ENTRY_IID (IID_IInputObject, IInputObject) //
Deals with Keyboard related events
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT() // Protects the object from being
deleted if (during FinalConstruct) the internal aggregated object
increments the reference count then decrements the count to 0.
// Capturing ActiveX events
//BEGIN_SINK_MAP (CPluginPlatform)
// SINK_ENTRY_EX (1, DIID_DWebBrowserEvents2,
DISPID_DOCUMENTCOMPLETE, _OnDocumentComplete) // Document Complete
Event
//END_SINK_MAP ()
HRESULT FinalConstruct(void); // Called during the final stages of
Object Construction. Used if any additional data is to be initialized
void FinalRelease(void); // Called during the final stages of
Object Destruction. Used if any additional data is to be destroyed
public:
// THIS SECTION CONTAINS ALL THE COM INTERFACE METHODS
// IOleWindow Methods
STDMETHOD (GetWindow) (HWND*);
STDMETHOD (ContextSensitiveHelp) (BOOL);
// IDockingWindow Methods
STDMETHOD (ShowDW) (BOOL);
STDMETHOD (CloseDW) (DWORD);
STDMETHOD (ResizeBorderDW) (LPCRECT, IUnknown*, BOOL);
// IDeskBand Method
STDMETHOD (GetBandInfo) (DWORD, DWORD, DESKBANDINFO*);
// IInputObject Methods
STDMETHOD (UIActivateIO) (BOOL, LPMSG);
STDMETHOD (HasFocusIO) (void);
STDMETHOD (TranslateAcceleratorIO) (LPMSG);
// IObjectWithSite Methods
STDMETHOD (SetSite) (IUnknown*);
STDMETHOD (GetSite) (REFIID, LPVOID*);
// IPersistStream Methods
STDMETHOD (GetClassID) (LPCLSID);
STDMETHOD (IsDirty) (void);
STDMETHOD (Load) (LPSTREAM);
STDMETHOD (Save) (LPSTREAM, BOOL);
STDMETHOD (GetMaxSize) (ULARGE_INTEGER*);
private:
// THIS SECTION DEFINES ALL THE PRIVATE DATA MEMBERS
CComPtr <IWebBrowser2> _mBrowser;
BOOL _IsConnectedToBrowser;
IInputObjectSite *_IOSite;
DWORD _BANDID, _VIEWMODE;
public:
// THIS SECTION DEFINES ALL THE PUBLIC DATA MEMBERS
HWND _ParentHWND;
HWND _RSTHWND;
_RSTBandObject _RST;
CWnd _ReflectionWnd;
public:
// THIS SECTION DEFINES ALL THE PUBLIC FUNCTIONS
int _CreateToolband ();
public:
// THIS SECTION DEFINES ALL THE EVENT HANDLERS
void STDMETHODCALLTYPE _OnDocumentComplete (IDispatch *_PDisp,
VARIANT *_pURL);
};
//............................................................//
My Implementation of the SetSite Method is as follows:
STDMETHODIMP CPluginPlatform :: SetSite (IUnknown *_PunkSite) {
// _IOSite = (IInputObjectSite*) _PunkSite;
if (_PunkSite) {
IOleWindow *_PtrOleWnd;
_ParentHWND = NULL;
if (SUCCEEDED (_PtrOleWnd->QueryInterface (IID_IOleWindow,
(void**)&_PtrOleWnd))) {
_PtrOleWnd->GetWindow (&_ParentHWND);
_PtrOleWnd->Release ();
}
if (!_ParentHWND)
return E_FAIL;
IServiceProviderPtr _PtrSP = _PunkSite;
if (_mBrowser)
_mBrowser = NULL;
HRESULT _HRes = _PtrSP->QueryService (SID_SWebBrowserApp,
IID_IWebBrowser, (void**)&_mBrowser);
if (SUCCEEDED (_HRes)) { // i.e. Toolbar has properly plugged in
_IsConnectedToBrowser = TRUE;
_CreateToolband ();
}
}
return S_OK;
//return IObjectWithSiteImpl <CPluginPlatform> :: SetSite
(_PunkSite);
}
//
------------------------------------------------------------------------------------------------------------------------//
This is the _CreateToolband function:
int CPluginPlatform :: _CreateToolband () {
AFX_MANAGE_STATE ( AfxGetStaticModuleState ());
CWnd *_ParentWindow = CWnd::FromHandle (_ParentHWND);
CRect _parentRC;
_ParentWindow->GetClientRect (&_parentRC);
BOOL F = _ReflectionWnd.Create (NULL, NULL, WS_CHILD, _parentRC,
_ParentWindow, 0 , 0);
_ReflectionWnd.GetClientRect (&_parentRC);
_RST._CREATE (&_ReflectionWnd, _parentRC);
return 1;
}
//
------------------------------------------------------------------------------------------------------------------------//
The Toolbar class definition is as follows:
class _RSTBandObject : public CToolBarCtrl {
public:
CButton _SearchButton;
CEdit _SearchBox;
DECLARE_MESSAGE_MAP ()
public:
_RSTBandObject ();
afx_msg void _ONSEARCH ();
void _CREATE (CWnd*, CRect);
};
//----------------------------................................................//
I'd appreciate any help on this topic.......