코드
TShellWindows 인데 FindWindow로 변경했을 떄와 같이 HWND를 받을 수 있도록 찾아보자.
by umaking
2008. 7. 18.
//---------------------------------------------------------------------------
#include
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "shdocvw_ocx"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TShellWindows *Sh = new TShellWindows(NULL);
try
{
for(int i = 0; i < Sh->Count; i++)
{
if(Sh->Item(i) == NULL)
continue;
DoDrawImage(Sh->Item(i));
}
}
__finally
{
delete Sh;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DoDrawImage(IDispatch *Idisp)
{
IWebBrowser2 *IE;
IHTMLDocument2 *doc2;
IHTMLElement*ele;
IHTMLElement2 *ele2;
IHTMLDocument3 *doc3;
long bHeight, bWidth, height, width;
Idisp->QueryInterface(IID_IWebBrowser2, (void **)&IE);
if(IE == NULL)
return;
if(FAILED(IE->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(IE->Document->QueryInterface(IID_IHTMLDocument3, (void **)&doc3)))
return;
if(FAILED(doc3->get_documentElement(&ele)))
return;
if(FAILED(ele->QueryInterface(IID_IHTMLElement2, (void **)&ele2)))
return;
if(FAILED(ele2->get_scrollHeight(&height)))
return;
if(FAILED(ele2->get_scrollWidth(&width)))
return;
width = (width > bWidth ? width : bWidth);
height = (height > bHeight ? height : bHeight);
IViewObject2 *vObj2;
if(FAILED(IE->Document->QueryInterface(IID_IViewObject2, (void **)&vObj2)))
return;
TRect rect = Rect(0, 0, width, height);
Graphics::TBitmap *bmp = new Graphics::TBitmap();
bmp->Width = width;
bmp->Height = height;
OleCheck(vObj2->Draw(DVASPECT_CONTENT, 1, NULL, NULL, IE->Parent,
bmp->Canvas->Handle, (const _RECTL *)&rect, NULL, NULL, 0));
Image1->Picture->Bitmap->Assign(bmp);
Image1->Repaint();
vObj2->Release();
delete bmp;
IE->Release();
}
//---------------------------------------------------------------------------