The place you put implementation of IProtectFocus and IInternetSecurityManager depends on your implementation of QueryService. Since you are calling CCustomControlSite::ExternalQueryInterface in your implementation, you need to add interface map macros on the CCustomControlSite class.
How could I use IProtectFocus to keep CDHtmlDialog navigate from drawing focus from editBox?
سؤال
I know IProtectFocus interface AllowFocusChange function could solve the "focus steal issue" when CDHtmlDialog excute the navigate() functions, but I don't quite clear about how to implement IProtectFocus function into my code. Could anyone please help me out? Any code sample is quite appreciate.
More details, I could implement IInternetSecurityManager interface to fix javascript ActiveX authority issue. But I tried the same way to implement IProtectFocus, do not work. I need C++ code only, thanks!
My code example:(CCustomControlSite is customized IWebBrowser control, CInstantAnswerDlg is a CDHtmlDialog.)
MFC interface part:
class CCustomControlSite: public COleControlSite
{
public:
CCustomControlSite(COleControlContainer *pCnt):COleControlSite(pCnt){}
protected:
DECLARE_INTERFACE_MAP();
// Implement IServiceProvider
BEGIN_INTERFACE_PART(ServiceProvider, IServiceProvider)
STDMETHOD(QueryService)(REFGUID,REFIID,void**);
END_INTERFACE_PART(ServiceProvider)
// Implement IServiceProvider
BEGIN_INTERFACE_PART(ProtectFocus, IProtectFocus)
STDMETHOD(AllowFocusChange)(BOOL *);
END_INTERFACE_PART(ProtectFocus)
};
Implementation part:
ULONG FAR EXPORT CCustomControlSite::XServiceProvider::AddRef()
{
METHOD_PROLOGUE(CCustomControlSite, ServiceProvider)
return pThis->ExternalAddRef();
}
ULONG FAR EXPORT CCustomControlSite::XServiceProvider::Release()
{
METHOD_PROLOGUE(CCustomControlSite, ServiceProvider)
return pThis->ExternalRelease();
}
HRESULT FAR EXPORT CCustomControlSite::XServiceProvider::QueryInterface(REFIID riid,void** ppvObj)
{
METHOD_PROLOGUE(CCustomControlSite, ServiceProvider)
HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
return hr;
}
STDMETHODIMP CCustomControlSite::XServiceProvider::QueryService(REFGUID guidService,REFIID riid,void** ppvObject)
{
if (guidService == SID_SInternetSecurityManager &&
riid == IID_IInternetSecurityManager)
{
METHOD_PROLOGUE(CCustomControlSite, ServiceProvider)
HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObject);
return hr;
}
else
{
*ppvObject = NULL;
}
return E_NOINTERFACE;
}
// ProtectFocus Methods
ULONG FAR EXPORT CCustomControlSite::XProtectFocus::AddRef()
{
METHOD_PROLOGUE(CCustomControlSite, ProtectFocus)
return pThis->ExternalAddRef();
}
ULONG FAR EXPORT CCustomControlSite::XProtectFocus::Release()
{
METHOD_PROLOGUE(CCustomControlSite, ProtectFocus)
return pThis->ExternalRelease();
}
HRESULT FAR EXPORT CCustomControlSite::XProtectFocus::QueryInterface(REFIID riid,void** ppvObj)
{
METHOD_PROLOGUE(CCustomControlSite, ProtectFocus)
HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
return hr;
}
STDMETHODIMP CCustomControlSite::XProtectFocus::AllowFocusChange(BOOL *pfAllow)
{
*pfAllow = FALSE;
return S_OK;
}
Add control to CDHtmlDialog:
BOOL CInstantAnswerDlg::CreateControlSite(COleControlContainer* pContainer,COleControlSite** ppSite,UINT /* nID */,REFCLSID /* clsid */ )
{
if(ppSite == NULL)
{
ASSERT(FALSE);
return FALSE;
}
m_pCustSite = m_insAnswerManager->CreateSite(pContainer);
if (!m_pCustSite)
return FALSE;
*ppSite = m_pCustSite;
return TRUE;
}
The question is both XProtectFocus::QueryInterface and XProtectFocus::AllowFocusChange function do not get called, while XServiceProvider::QueryInterface could get called. where am I wrong??
المحلول