DoCapture(IHTMLElement *ele, IViewObject2 *vObj, int width, int height, int cwidth, int cheight, int wd, int hd)

2008. 8. 19. 17:25코드

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 CppWebBrowser1->Navigate(WideString(Edit1->Text));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
 IViewObject2 *vObj;
 IHTMLElement2 *ele2;
 IHTMLElement2 *ele_5;
 IHTMLDocument2 *doc2;
 IHTMLElement *ele;
 IHTMLElement *ele_4;
 IHTMLDocument3 *doc3;
 long bHeight, bWidth, height, width, height2, width2;

 if(FAILED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (void **)&doc2)))
  return;

 if(FAILED(doc2->get_body(&ele)))
  return;

 if(FAILED(ele->QueryInterface(IID_IHTMLElement2, (void **)&ele2)))
  return;

 if(FAILED(ele2->get_scrollHeight(&bHeight)))
  return;

 if(FAILED(ele2->get_scrollWidth(&bWidth)))
  return;

 if(FAILED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument3, (void **)&doc3)))
  return;

 if(FAILED(doc3->get_documentElement(&ele_4)))
  return;

 if(FAILED(ele_4->QueryInterface(IID_IHTMLElement2, (void **)&ele_5)))
  return;

 if(FAILED(ele_5->get_scrollHeight(&height2)))
  return;

 if(FAILED(ele_5->get_scrollWidth(&width2)))
  return;

 width = (width2 > bWidth ? width2 : bWidth);
 height = (height2 > bHeight ? height2 : bHeight);


 if(FAILED(CppWebBrowser1->Document->QueryInterface(IID_IViewObject2, (void **)&vObj)))
  return;

 DoCapture(ele, vObj, width, height, CppWebBrowser1->Width, CppWebBrowser1->Height, 30, 30);

 vObj->Release();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DoCapture(IHTMLElement *ele, IViewObject2 *vObj, int width, int height, int cwidth, int cheight, int wd, int hd)
{
 Graphics::TBitmap *bmp = new Graphics::TBitmap();
 bmp->Width = width;
 bmp->Height = height;

 Graphics::TBitmap *bmp2 = new Graphics::TBitmap();
 bmp2->Width = cwidth;
 bmp2->Height = cheight;

 OleVariant v;
 v = "yes";
 if(FAILED(ele->setAttribute(L"scroll", v, 0)))
  return;

 long cnt = 0;
 long hcnt = 0, wcnt = 0;
 long i = 0;
 TRect rect = Rect(0, 0, cwidth, cheight);
 VARIANT gv;

 while(cnt < height)
 {
  for(i = 0; i < width; i += (cwidth-wd))
  {
   v = cnt;
   ele->setAttribute(L"scrollTop", v, 0);
   v = i;
   ele->setAttribute(L"scrollLeft", v, 0);

   OleCheck( vObj->Draw(DVASPECT_CONTENT, 1, NULL, NULL, Form1->Handle,
     bmp2->Canvas->Handle, (const _RECTL *)&rect,
     NULL,NULL, 0)
   );

   ele->getAttribute(L"scrollTop", 0, &gv);
   hcnt = gv.lVal;
   ele->getAttribute(L"scrollLeft", 0, &gv);
   wcnt = gv.lVal;
   BitBlt(bmp->Canvas->Handle, wcnt, hcnt, (cwidth-wd), (cheight-hd),
     bmp2->Canvas->Handle, 0, 0, SRCCOPY);
  }
  cnt += (cheight-hd);
 }

 Image1->Picture->Bitmap->Assign(bmp);

 delete bmp2;
 delete bmp;


}

'코드' 카테고리의 다른 글

ServletFilter를 통한 URI 재구성 (Blog처럼)  (1) 2009.02.22
printStackTrace  (0) 2008.09.02
TShellWindows  (0) 2008.08.19
TInternetExplorer  (0) 2008.08.14
WebBrowser-Capture  (0) 2008.08.14