Re: CHtmlView OLECMDID_PRINT CreateControlSite



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,
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
derived
class. When I use the custom site, I can't get a print dialog when I press
Ctrl+P. if I remove that I am able to bring up the print dialog. I need
the
custom site to handle script errors in OLECMDID_SCRIPTERROR...

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,
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,
nCmdID,0,
NULL, NULL);
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
fContinueRunningScripts
= true;
int i;
params.cArgs = 0;
params.cNamedArgs = 0;


// Get the document that is currently being
viewed.
hr =
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
object.
for (i = 0; i < 5; i++)
{
// 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, &params,
&rgvaEventInfo[i],NULL, NULL);


SysFreeString(rgwszNames[i]);
}


// At this point, you would normally alert the
user
with
// 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
on
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


.



Relevant Pages

  • Re: How to handle script error in the WebBrowser control
    ... there will be a script error and a yes/no message box will pop up asking whether I want to debug or not. ... it doesn't apply to the instances of the WebBrowser control. ... There must be a registry setting somewhere to handle the instances of the WebBrowser control. ... I've up on creating a code solution - none of the code I've found so far has worked. ...
    (microsoft.public.vb.general.discussion)
  • Re: Strange URLDownloadToFile problem
    ... I think the URL was encoded by IE with UTF-8 before send to server. ... > I have an application that host a webbrowser control. ... I use URLDownloadToFile function to download url ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • RE: Word 2002 SP2 - SaveAs HTML oddity when using DsoFramer
    ... may try to host an webbrowser control on the winform and then host the word ... Use the WebBrowser Control to Open an Office Document in Visual ... Microsoft Online Partner Support ...
    (microsoft.public.office.developer.automation)
  • Re: How to host WebBrowser control in MTA application?
    ... > I want to create WebBrowser control in MTA application ... You can't host WebBrowser control (or, for that matter, any visual ... ActiveX control) on an MTA thread. ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Strange Behavior
    ... I am working on a project which needs to take some snapshoots of web sites. ... I host the Webbrowser control in a Windows form and use WM_PRINT message to ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)