Re: CHtmlView OLECMDID_PRINT CreateControlSite
- From: "Sheng Jiang[MVP]" <sheng_jiang@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Aug 2007 13:38:31 -0500
OLECMDERR_E_UNKNOWNGROUP or OLECMDERR_E_NOTSUPPORTED means the command can
not be executed. I think you need to return E_NOTIMPL or something.
You have no access to the IE host of the webbrowser control because you are
replacing it with your host.
--
Sheng Jiang
Microsoft MVP in VC++
"AmitSharma" <amit_sharma@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CA0C54D3-A7CC-44B4-B0ED-0A1C549CB268@xxxxxxxxxxxxxxxx
Hi All,derived
Please help on to bring up the print dialog when implementing the Custom
control site to suprress/handle the script error I have a CHtmlView
class. When I use the custom site, I can't get a print dialog when I pressthe
Ctrl+P. if I remove that I am able to bring up the print dialog. I need
custom site to handle script errors in OLECMDID_SCRIPTERROR...0);
Pl look at the below code and a solution would be a gr8 help, i have been
trying this since last 10 days...
BOOL CTestPrint_HtmlViewView::CreateControlSite(COleControlContainer*
pContainer,
COleControlSite** ppSite, UINT /* nID */, REFCLSID /* clsid */)
{
ASSERT(ppSite != NULL);
// when the below line is commented, On Ctrl+P the Print dialog is invoked
*ppSite = new CMyHtmlControlSite(pContainer);
return TRUE;
}
void CTestPrint_HtmlViewView::OnFilePrint()
{
HRESULT hr;
CComPtr<IHTMLDocument2> spDoc = (IHTMLDocument2*) GetHtmlDocument();
if (spDoc != NULL)
{
CComQIPtr<IOleCommandTarget> spCmdTarget = spDoc;
if (spCmdTarget != NULL)
{
hr = spCmdTarget->Exec(NULL,
OLECMDID_PRINT,OLECMDEXECOPT_DODEFAULT, 0, 0);
}
}
//Also tried with this->ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DODEFAULT, 0,
}nCmdID,0,
STDMETHODIMP CMyHtmlControlSite::XOleCommandTarget::Exec(const GUID*
pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG* pvaIn,
VARIANTARG* pvaOut )
{
METHOD_PROLOGUE_EX_(CMyHtmlControlSite, OleCommandTarget)
HRESULT hr = S_OK;
if (pguidCmdGroup && IsEqualGUID(*pguidCmdGroup,
CGID_DocHostCommandHandler))
{
switch (nCmdID)
{
case OLECMDID_PRINT:
{
//return S_OK;//1 or any value doesnt bring the print dialog
//if we do the below, It falls in the same case ITS A KIND OF RECURSIVE
CALL
CComQIPtr<IOleCommandTarget> pCmdTarget = pThis->GetIDispatch(TRUE);
if (pCmdTarget != NULL)
{
hr = pCmdTarget->Exec(pguidCmdGroup,
NULL, NULL);fContinueRunningScripts
return hr;
}
}
//is required to handle/supress script error
case OLECMDID_SHOWSCRIPTERROR:
{
IHTMLDocument2* pDoc = NULL;
IHTMLWindow2* pWindow = NULL;
IHTMLEventObj* pEventObj = NULL;
BSTR rgwszNames[5] =
{
SysAllocString(L"errorLine"),
SysAllocString(L"errorCharacter"),
SysAllocString(L"errorCode"),
SysAllocString(L"errorMessage"),
SysAllocString(L"errorUrl")
};
DISPID rgDispIDs[5];
VARIANT rgvaEventInfo[5];
DISPPARAMS params;
BOOL
= true;viewed.
int i;
params.cArgs = 0;
params.cNamedArgs = 0;
// Get the document that is currently being
hr =object.
pvaIn->punkVal->QueryInterface(IID_IHTMLDocument2, (void **)
&pDoc);
// Get document.parentWindow.
hr = pDoc->get_parentWindow(&pWindow);
pDoc->Release();
// Get the window.event object.
hr = pWindow->get_event(&pEventObj);
// Get the error info from the window.event
for (i = 0; i < 5; i++)user
{
// Get the property's dispID.
hr = pEventObj->GetIDsOfNames(IID_NULL,
&rgwszNames[i], 1,
LOCALE_SYSTEM_DEFAULT, &rgDispIDs[i]);
// Get the value of the property.
hr = pEventObj->Invoke(rgDispIDs[i],
IID_NULL,LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, ¶ms,
&rgvaEventInfo[i],NULL, NULL);
SysFreeString(rgwszNames[i]);
}
// At this point, you would normally alert the
withon
// the information about the error, which is now
contained
// in rgvaEventInfo[]. Or, you could just exit
silently.
(*pvaOut).vt = VT_BOOL;
break;
}
case OLECMDID_SHOWMESSAGE:
(*pvaOut).boolVal = VARIANT_TRUE;
break;
default:
hr = OLECMDERR_E_NOTSUPPORTED;
break;
}//end of switch
}
else
{
hr = OLECMDERR_E_UNKNOWNGROUP;
}
return 0L;
}
if u need more information i can provide the sample code and its available
http://files-upload.com/files/453048/TestPrint_HtmlView.zip
i am already registered with experts-exchange but no one could provide a
solution to this..
Thanx in advance
.
- Follow-Ups:
- Re: CHtmlView OLECMDID_PRINT CreateControlSite
- From: AmitSharma
- Re: CHtmlView OLECMDID_PRINT CreateControlSite
- References:
- CHtmlView OLECMDID_PRINT CreateControlSite
- From: AmitSharma
- CHtmlView OLECMDID_PRINT CreateControlSite
- Prev by Date: Re: PassthruAPP question - when connection ends?
- Next by Date: Re: CHtmlView OLECMDID_PRINT CreateControlSite
- Previous by thread: Re: CHtmlView OLECMDID_PRINT CreateControlSite
- Next by thread: Re: CHtmlView OLECMDID_PRINT CreateControlSite
- Index(es):
Relevant Pages
|
|