Article View: borland.public.cppbuilder.internet.web
Article #724TWebBrowser how to put_value() for <input type="file">
From: Hans Galema
Date: Mon, 30 Oct 2006 23:12
Date: Mon, 30 Oct 2006 23:12
147 lines
4260 bytes
4260 bytes
For TWebBrowser in Turbo C++ I'm puzzled how to use put_value()
for <input type="file">
I can handle that for <input type="text" > using IHTMLInputElement.
IHTMLInputFileElement used for <input type="file"> does find the input
but put_value() has no effect.
To demonstrate the problem take a TForm and put two TSpeedButtons
on it a a TWebBrowser.
The first speedbutton will load a specific url:
void __fastcall TForm3::SpeedButton1Click(TObject *Sender)
{
WebBrowser1->Navigate ( "http://video.tinypic.com/vidiframe.php" );
}
That page has the following <input>'s which I try to fill:
void __fastcall TForm3::SpeedButton2Click(TObject *Sender)
{
//<input type="file" name="the_file" size="30">
//<input type="text" name="the_tag" size="25" maxlength="30">
PlaceInputFileText ( "the_file", "a filename" );
PlaceInputText ( "the_tag", "a title" );
}
Only the title is set.
Here the two used functions:
#include <mshtml.h>
bool __fastcall TForm3::PlaceInputText ( char *inputname, AnsiString Text )
{
bool done = false;
IHTMLDocument2 *HTMLDoc = NULL;
if(SUCCEEDED(WebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
{
IHTMLElementCollection *pAll = NULL;
if(SUCCEEDED(HTMLDoc->get_all(&pAll)))
{
// <input type="text" name="the_tag">
Variant name = inputname;
Variant index = 0;
IDispatch *pDisp = NULL;
if(SUCCEEDED(pAll->item(name, index, &pDisp)))
{
if ( pDisp )
{
// IHTMLInputFileElement *pInput = NULL; // mshtml.h
IHTMLInputElement *pInput = NULL; // mshtml.h
// IHTMLFormElement *pForm = NULL; // mshtml.h
pDisp->QueryInterface(IID_IHTMLInputElement, (LPVOID*)&pInput);
pDisp->Release();
if(pInput)
{
pInput->put_value(WideString(Text));
done = true;
/*
WideString mybuffer;
pInput->get_value ( &mybuffer );
ShowMessage ( mybuffer );
*/
pInput->Release();
}
}
}
pAll->Release();
}
HTMLDoc->Release();
}
return done;
}
bool __fastcall TForm3::PlaceInputFileText ( char *inputname, AnsiString Text )
{
bool done = false;
IHTMLDocument2 *HTMLDoc = NULL;
if(SUCCEEDED(WebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
{
IHTMLElementCollection *pAll = NULL;
if(SUCCEEDED(HTMLDoc->get_all(&pAll)))
{
// <input type="file" name="the_file">
Variant name = inputname;
Variant index = 0;
IDispatch *pDisp = NULL;
if(SUCCEEDED(pAll->item(name, index, &pDisp)))
{
if ( pDisp )
{
IHTMLInputFileElement *pInput = NULL; // mshtml.h
// IHTMLInputElement *pInput = NULL; // mshtml.h
// IHTMLFormElement *pForm = NULL; // mshtml.h
// pDisp->QueryInterface(IID_IHTMLInputElement, (LPVOID*)&pInput);
pDisp->QueryInterface(IID_IHTMLInputFileElement, (LPVOID*)&pInput);
pDisp->Release();
if(pInput)
{
pInput->put_value(WideString(Text.c_str()));
done = true;
/*
WideString mybuffer;
pInput->get_value ( &mybuffer );
ShowMessage ( mybuffer );
*/
pInput->Release();
}
}
}
pAll->Release();
}
HTMLDoc->Release();
}
return done;
}
Who knows how to set Video input prgammatically?
Hans.
Technical Details
Message-ID:
<45468718@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: feeec,2bc0d92930b979d2,start X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 31 Oct 2006 00:12:09 +0100 From: Hans Galema <notused@notused.nl> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.web Subject: TWebBrowser how to put_value() for <input type="file"> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 145.98.201.248 Message-ID: <45468718@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1162250008 145.98.201.248 (30 Oct 2006 15:13:28 -0700) Lines: 147 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail