void __fastcall TFlyingForm::GetWebFullPic(LPDISPATCH WebDoc,HWND hWnd,
AnsiString strTitle, AnsiString strUrl)
{
//TODO: 取得鼠标指向的页面的全部图象。
AnsiString FullPicTempPath=GetDocBookTempPath()+"WebFullPic.jpg";
//IViewObject *ViewObject;
::IViewObject *ViewObject=0;
IHTMLDocument2 *pDocument ;
IHTMLWindow2 *pHtmlWin;
IHTMLElement *pHtmlBodyElem;
RECTL sourceDrawRect;
HBITMAP pDest,pSour;
HRESULT hr ;
int i,m;
int iScrollHeight,iScrollWidth;
VARIANT vScrollHeight,vScrollWidth;
VARIANT vOffsetHeight,vOffsetWidth;
VARIANT vScrollLeft,vScrollTop;
//获得IHTMLDocument2接口
hr = WebDoc->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument) ;
if(SUCCEEDED(hr) )
{
wchar_t *url;
pDocument->get_URL(&url);
//hr=pDocument->QueryInterface(IID_IViewObject, (void**)&ViewObject);
hr=pDocument->QueryInterface(::IID_IViewObject,reinterpret_cast<void**>(&ViewObject));
if(SUCCEEDED(hr) )
{
Graphics :: TBitmap *HtmlBmp = new Graphics :: TBitmap();
HtmlBmp->PixelFormat= pf24bit;
try
{
pDocument->get_parentWindow(&pHtmlWin);
pHtmlWin->scroll(0,0);
pDocument->get_body(&pHtmlBodyElem);
pHtmlBodyElem->getAttribute(WideString("scrollHeight"),0,&vScrollHeight);
pHtmlBodyElem->getAttribute(WideString("scrollwidth"),0,&vScrollWidth);
iScrollHeight = vScrollHeight.lVal;
iScrollWidth = vScrollWidth.lVal;
HtmlBmp->Height = iScrollHeight ;
HtmlBmp->Width = iScrollWidth ;
pDest = HtmlBmp->Canvas->Handle;
pHtmlBodyElem->getAttribute(WideString("offsetHeight"),0,&vOffsetHeight);
pHtmlBodyElem->getAttribute(WideString("offsetwidth"),0,&vOffsetWidth);
m = iScrollHeight / ( vOffsetHeight.lVal - 20); /*Trunc()*/
i = iScrollWidth / ( vOffsetWidth.lVal - 20);
for(int j=0;j<i;j++)
{
for(int k=0;k<=m;k++)
{
Graphics :: TBitmap *tempBmp = new Graphics :: TBitmap();
int iLeft=0;
pHtmlBodyElem->getAttribute(WideString("offsetHeight"),0,&vOffsetHeight);
pHtmlBodyElem->getAttribute(WideString("offsetWidth"),0,&vOffsetWidth);
tempBmp->Height = vOffsetHeight.lVal;
tempBmp->Width = vOffsetWidth.lVal;
pSour = tempBmp->Canvas->Handle;
sourceDrawRect.top=0;
sourceDrawRect.left=0;
sourceDrawRect.right=tempBmp->Width;
sourceDrawRect.bottom=tempBmp->Height;
TRect HtmlRect;
HDC HtmlDC=GetWindowDC(hWnd);
TCanvas *BCanvas = new TCanvas();
HtmlRect.Left=0;
HtmlRect.top=0;
int a=HtmlRect.Width();
HtmlRect.Right=tempBmp->Width;
HtmlRect.Bottom= tempBmp->Height;
BCanvas->Handle=HtmlDC;
tempBmp->Canvas->CopyRect(HtmlRect,BCanvas,HtmlRect);
delete BCanvas;
ReleaseDC(HtmlDC,0);
/*
//会出错。没法了。只好不用了。
OleCheck(ViewObject->Draw(DVASPECT_CONTENT, 1, NULL,NULL,Handle,
tempBmp->Canvas->Handle,&sourceDrawRect, NULL, NULL, 0));
*/
pHtmlBodyElem->getAttribute(WideString("scrollLeft"),0,&vScrollLeft);
pHtmlBodyElem->getAttribute(WideString("Scrolltop"),0,&vScrollTop);
BitBlt(pDest, vScrollLeft.lVal , vScrollTop.lVal,
tempBmp->Width, tempBmp->Height, pSour, 2, 2, SRCCOPY);
pHtmlBodyElem->getAttribute(WideString("offsetHeight"),0,&vOffsetHeight);
pHtmlBodyElem->getAttribute(WideString("Scrolltop"),0,&vScrollTop);
iLeft= vOffsetHeight.lVal + vScrollTop.lVal
- GetSystemMetrics(SM_CXVSCROLL) - 24;
pHtmlBodyElem->getAttribute(WideString("scrollLeft"),0,&vScrollLeft);
pHtmlWin->scroll(vScrollLeft.lVal ,iLeft );
delete tempBmp;
tempBmp=NULL;
}// end of for(int k=0;k<=m;k++)
int iLeftSize=0;
pHtmlBodyElem->getAttribute(WideString("offsetWidth"),0,&vOffsetWidth) ;
pHtmlBodyElem->getAttribute(WideString("scrollLeft"),0,&vScrollLeft);
iLeftSize = vOffsetWidth.lVal + vScrollLeft.lVal
- GetSystemMetrics(SM_CXVSCROLL) - 24;
pHtmlWin->scroll(iLeftSize,0);
} //end of for(j=0;j<i;j++)
TJPEGImage * HtmlJpg = new TJPEGImage();
HtmlJpg->CompressionQuality=80;
HtmlJpg->Assign(HtmlBmp);
HtmlJpg->SaveToFile(FullPicTempPath);
delete HtmlJpg;
HtmlJpg=NULL;
}__finally
{
ViewObject->Release();
delete HtmlBmp;
HtmlBmp=NULL;
}
}// end of if(SUCCEEDED(hr) )
pDocument->Release() ;
}// end of if(SUCCEEDED(hr) )
}
//---------------------------------------------------------------------------