powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Delphi [игнор отключен] [закрыт для гостей] / TWebBrowser/TDHTMLEdit
2 сообщений из 2, страница 1 из 1
TWebBrowser/TDHTMLEdit
    #32314110
Фотография NetFantom
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Кто-нибудь знает как добраться до картинки? Т.е. до IHtmlImgElement я добраться могу без проблемм, но мне нужено именно манипулировать с самой картинкой - подменить ее скажем налету, или сохранить в отдельный файл...читать с диска по src очень не хочется. В DOM я не нашел как добраться, может можно через сам TWebBrowser? Должна же там картинка представляться как OLE объект...или не должна? :)
...
Рейтинг: 0 / 0
TWebBrowser/TDHTMLEdit
    #32314184
Lepsik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
посмотри пример для Builder


Как программно записать на диск открытый документ в CppWebBrowser? (C++Builder) Сохранить желательно с рисунками.

cker(?????????????????)???:?????



??IE?????,???????...

void __fastcall TfrmMain::Button1Click(TObject *Sender)

{

IHTMLDocument2* HTMLDocument = NULL;

IPersistFile* PersistFile = NULL;

if(!CppWebBrowser->Busy && CppWebBrowser->Document &&

AnsiString(CppWebBrowser->LocationURL) != "about:blank" &&

SUCCEEDED(CppWebBrowser->Document->QueryInterface(

IID_IHTMLDocument2, (LPVOID*)&HTMLDocument)))

{

// ??????

if(SUCCEEDED(HTMLDocument->QueryInterface(IID_IPersistFile,

(LPVOID*)&PersistFile)))

{



AnsiString TempFile = ExtractFilePath(ParamStr(0))+

"0000html_temp";

PersistFile->Save(WideString(TempFile), false);

PersistFile->Release();



TMemoryStream* pStream = new TMemoryStream;

if(pStream)

{

// ????????????TStrings,???

if(FileExists(TempFile))

{

pStream->LoadFromFile(TempFile);

// DataModule->WriteBlob(pStream);

DeleteFile(TempFile);

}

}

delete pStream;

}

}

}

//---------------------------------------------------------------------------

void __fastcall DataModule::WriteBlob(const TMemoryStream* pStream)

{

pQuery->Edit();

TBlobField * pField=(TBlobField *)pQuery->FieldByName("HTML_FIELD");

TBlobStream * pmem=new TBlobStream(pField,bmWrite);

pmem->Seek(0,soFromBeginning);

pStream->SaveToStream(pmem);

delete pmem;

pQuery->Post();

}

???????????



???:

??2:

???????,???CppWebBrowser???Bug,const int Size = 0x100000;??????,???????IHTMLDocument????????,??????....

10000????????....

//---------------------------------------------------------------------------

void GetHtmlSourceFromWebBrowser( TCppWebBrowser *WebBrowser,TMemoryStream* pMemoryStream )

{

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;

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{



TMemoryStream* pStream = new TMemoryStream();



GetHtmlSourceFromWebBrowser(CppWebBrowser1, pStream);



DataModule->WriteBlob(pStream);



if(pStream) delete pStream;

}

//---------------------------------------------------------------------------

?????????,?????,???msdn??IPersistStreamInit??

interface IPersistStream : IPersist {

//IUnknown members and GetClassID from IPersist

HRESULT IsDirty(void);

HRESULT Load(IStream *pStm);

HRESULT Save(IStream *pStm, BOOL fClearDirty);

HRESULT GetSizeMax(ULARGE_INTEGER *pcbSize); };

interface IPersistStreamInit : IPersist { HRESULT InitNew(void); };

?????save??

Instructs the object to save its persistent data at the current seek offset of the given stream. The object must save its data and return without holding the IStream pointer. The fClearDirty argument tells the object whether it should consider itself clean after this call—a client may be making a copy of the object as opposed to saving its data permanently, and this flag distinguishes the cases.





???:



void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,

LPDISPATCH pDisp, Variant *URL)

{

//??????,?????Document???????OnDocumentComplete??

IHTMLDocument2 *document;

IHTMLElement *body;

BSTR title,source,content;



(void *)document=CppWebBrowser1->Document;



document->get_title(&title);

document->get_body(&body);

body->get_outerHTML(&source);

body->get_outerText(&content);



Edit1->Text=title;

Edit2->Text=*URL;

Memo1->Text=source;

Memo2->Text=content;



TMemoryStream* pms = new TMemoryStream();

TStringStream* pss = new TStringStream(AnsiString(source));

pms->CopyFrom(pss,pss->Size);



// WriteToDB(pms);



delete pms,pss;



}
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Delphi [игнор отключен] [закрыт для гостей] / TWebBrowser/TDHTMLEdit
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]