#include
void __fastcall TForm1::GetHTMLCode ( TCppWebBrowser *WebBrowser, TMemo *SourceMemo )
{
SourceMemo -> Lines -> Clear ();
TMemoryStream* pMemoryStream = new TMemoryStream();
IStream *pIStream;
HGLOBAL hGlobal;
IPersistStreamInit *psi;
const int Size = 0x100000;
if ( WebBrowser -> Document == NULL ) return;
hGlobal = GlobalAlloc ( GPTR, Size );
if ( 0 == hGlobal )
{
ShowMessage ( "GlobalAlloc Error" );
return;
}
OleCheck ( CreateStreamOnHGlobal ( hGlobal, true, &pIStream ) );
try
{
OleCheck ( WebBrowser -> Document -> QueryInterface ( __uuidof( IPersistStreamInit ), ( void ** )&psi ) );
try
{
OleCheck ( psi -> Save ( pIStream, false ) );
pMemoryStream -> SetSize ( Size );
CopyMemory ( pMemoryStream -> Memory, hGlobal, Size );
}
__finally
{
delete psi;
}
}
__finally
{
delete pIStream;
}
SourceMemo -> Lines -> LoadFromStream ( pMemoryStream );
}