I'm trying to print an IE CWebBrowser2 control to a Metafile.
I'm using IViewObject::Draw method.
In order to fit the IE control to the page size I'm using the
lprcBounds parameter of IViewObject::Draw.
Unfortunately, stretching don't work properly: only the top-left
corner is stretched and the e rest of the IE control is ignored by the
metafile.
Adjusting lprcWBounds has no effect.
Is it a bug in the Microsoft IE control?
I don't use StretchBlt method because it's distorting fonts.
How can I stretch and draw the whole IE control to a metafile? |
Request for Question Clarification by
spot_tippybuttons-ga
on
14 Sep 2002 21:56 PDT
Would it be possible for you to post a short code snippet to look at?
|
Clarification of Question by
victore-ga
on
15 Sep 2002 07:58 PDT
Here you have some code
if(!mpWeb) return; //mpWeb is a CDialog holding IE control
CWebBrowser2* pWB = &mpWeb->m_web;
IViewObject2* pViewObject = NULL;
HRESULT hr = pWB->GetDocument()->QueryInterface(IID_IViewObject2,
(void**) &pViewObject);
if (FAILED(hr)) return;
//get size of control
CRect rect;
pWB->GetWindowRect(&rect);
int srcWidth = rect.Width(), srcHeight = rect.Height();
float factor = mStretch;//2; //the strectch factor is a member of
this class
if(factor <= 0) factor = 1;
RECTL rcOrig = { 0,0, srcWidth,srcHeight };
RECTL rcBounds = { 0,0, (int)(srcWidth*factor),(int)(
srcHeight*factor)};
RECTL rcWBounds = { 0,0, (int)(srcWidth*factor)*2,(int)(
srcHeight*factor)*2};
// good quality but there is a bug: top-left corner only is stretched
hr = pViewObject->Draw(DVASPECT_CONTENT, //DOCPRINT,
-1, NULL, NULL,pWB->GetDC()->m_hDC ,
((CMetaFileDC*)pDC)->m_hDC, //hdcMem,
&rcBounds, &rcWBounds, NULL, 0);
if (!SUCCEEDED(hr)) ASSERT(0);
pViewObject->Release();
|
Clarification of Question by
victore-ga
on
15 Sep 2002 08:02 PDT
///this code is collected from various functions, ignoring proper
deleting and releasing.
if(!mpWeb) return; //mpWeb is a CDialog holding IE control
//create a metafile
CMetaFileDC pDC = new CMetaFileDC();
pDC->CreateEnhanced(printerDC,NULL,NULL, "temp");
// printerDC is a CDC attached to GetPrinterDC()
pDC->SetAttribDC(printerDC->m_hAttribDC);//
//get the IViewObject interface
CWebBrowser2* pWB = &mpWeb->m_web;
IViewObject2* pViewObject = NULL;
HRESULT hr = pWB->GetDocument()->QueryInterface(IID_IViewObject2,
(void**) &pViewObject);
if (FAILED(hr)) return;
//get size of control
CRect rect;
pWB->GetWindowRect(&rect);
int srcWidth = rect.Width(), srcHeight = rect.Height();
float factor = mStretch;//2; //the strectch factor is a member of
this class
if(factor <= 0) factor = 1;
RECTL rcOrig = { 0,0, srcWidth,srcHeight };
RECTL rcBounds = { 0,0, (int)(srcWidth*factor),(int)(
srcHeight*factor)};
RECTL rcWBounds = { 0,0, (int)(srcWidth*factor)*2,(int)(
srcHeight*factor)*2};
//draw: good quality but there is a bug: top-left corner only is
stretched
hr = pViewObject->Draw(DVASPECT_CONTENT, //DOCPRINT,
-1, NULL, NULL,pWB->GetDC()->m_hDC ,
((CMetaFileDC*)pDC)->m_hDC, //hdcMem,
&rcBounds, &rcWBounds, NULL, 0);
if (!SUCCEEDED(hr)) ASSERT(0);
pViewObject
|
Clarification of Question by
victore-ga
on
15 Sep 2002 22:54 PDT
///this code is collected from various functions, ignoring proper
deleting and releasing.
if(!mpWeb) return; //mpWeb is a CDialog holding IE control
//create a metafile
EPrinterDC* printerDC = new EPrinterDC();
CMetaFileDC* pDC = new CMetaFileDC();
pDC->CreateEnhanced(printerDC,NULL,NULL, "temp");
// printerDC is a CDC attached to GetPrinterDC()
pDC->SetAttribDC(printerDC->m_hAttribDC);//
//get the IViewObject interface
CWebBrowser2* pWB = &mpWeb->m_web;
IViewObject2* pViewObject = NULL;
HRESULT hr = pWB->GetDocument()->QueryInterface(IID_IViewObject2,
(void**) &pViewObject);
if (FAILED(hr)) return;
//get size of control
CRect rect;
pWB->GetWindowRect(&rect);
int srcWidth = rect.Width(), srcHeight = rect.Height();
float factor = 3;//mStretch;//2; //the mStrectch factor is a member
of this class
if(factor <= 0) factor = 1;
RECTL rcOrig = { 0,0, srcWidth,srcHeight };
RECTL rcBounds = { 0,0, (int)(srcWidth*factor),(int)(
srcHeight*factor)};
RECTL rcWBounds = { 0,0, (int)(srcWidth*factor)*2,(int)(
srcHeight*factor)*2};
//draw: good quality but there is a bug: top-left corner only is
stretched
hr = pViewObject->Draw(DVASPECT_CONTENT, //DOCPRINT,
-1, NULL, NULL,pWB->GetDC()->m_hDC ,
((CMetaFileDC*)pDC)->m_hDC, //hdcMem,
&rcBounds, &rcWBounds, NULL, 0);
if (!SUCCEEDED(hr)) ASSERT(0);
pViewObject->Release();
//code for function until here
//Here is class EPrinterDC
class EPrinterDC : public CDC
{
public:
EPrinterDC()
{
mhDC = NULL;
CPrintDialog pDi(FALSE);
VERIFY(pDi.GetDefaults());
mhDC = pDi.GetPrinterDC();
VERIFY(Attach(mhDC));
}
~EPrinterDC()
{
Detach();
DeleteDC();
::DeleteDC(mhDC);
}
HDC mhDC;
};
#en
|