Article View: borland.public.cppbuilder.internet.web
Article #726Re: TWebBrowser how to put_value() for <input type="file">
From: Hans Galema
Date: Tue, 31 Oct 2006 14:36
Date: Tue, 31 Oct 2006 14:36
100 lines
3628 bytes
3628 bytes
Remy Lebeau (TeamB) wrote:
> You cannot use it at all. The IHTMLInputFileElement::value property is
> read-only. This is by design as part of Microsoft's security model.
Ok. Thanks.
> The only way to fill in the field programmably is to set focus to the edit
> control itself (use IHTMLElement::focus()) and then send keystrokes to it.
Setting focus was possible with IHTMLElement2::focus() // 2 added
But sending keystrokes took me hours before I had managed that.
It appears that using keybd_event() for a TEdit is easier then
to a TWebBrowser.
Using WM_CHAR like:
SendMessage(WebBrowser1->Handle, WM_CHAR, 'G', 2);
does nothing.
SendMessage ( WebBrowser1->Handle, WM_KEYDOWN, 'w', 0);
does not work either. So I constructed a function ( see below )
that uses keybd_event(). This works but only after taking
special care for char's like : \ ' . - +
For the moment this function will do but as soon as there
are other special chars in filenames it will fail.
Isn't there a function that will convert a char to VK_XXXX ?
Hans.
void SendKeys(char *s)
{
if (s)
{
do
{
bool withshift = false;
char key= *s++;
if ( key == '.' )
key = VK_OEM_PERIOD ;
else if ( key == ',' )
key = VK_OEM_COMMA;
else if ( key == '-' )
key = VK_OEM_MINUS;
else if ( key == '+' )
key = VK_OEM_PLUS;
else if ( key == ':' )
{
key = VK_OEM_1;
withshift = true;
}
else if ( key == '\\' )
key = VK_OEM_5 ;
else if ( isupper (key ) )
{
withshift = true;
}
else key = UpCase (key);
if ( withshift )
{
WPARAM param =WPARAM(VK_LSHIFT);
keybd_event(param,0,0, 0);
}
WPARAM param =WPARAM(key);
keybd_event(param,0,0,0);
keybd_event(param,0,KEYEVENTF_KEYUP,0);
if ( withshift)
{
WPARAM param =WPARAM(VK_LSHIFT);
keybd_event(param,0,KEYEVENTF_KEYUP,0);
}
} while (*s);
}
}
> Otherwise, you will have to stop using TWebBrowser to submit the forms at
> all. Use an HTTP library to program to the HTTP protocol directly. Indy,
> for example, has a special TStream class specifically for uploading
> form-based fields, including files.
As can be seen in the source op the url tat I provided earlier there is
javascript onsubmit() to be executed. Will TIdHTTP care for that too?
I don't think so.
At the moment things run. The program can upload a directory with videos
to the specified url and extract the resulting url's for use in webpages.
Hans.
Technical Details
Message-ID:
<45475fb0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news2.volia.net!newsfeed.gamma.ru!Gamma.RU!ecngs!feeder.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45468718@newsgroups.borland.com> <4546982a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,2bc0d92930b979d2 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 31 Oct 2006 15:36:14 +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: Re: TWebBrowser how to put_value() for <input type="file"> References: <45468718@newsgroups.borland.com> <4546982a$1@newsgroups.borland.com> In-Reply-To: <4546982a$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 145.98.201.248 Message-ID: <45475fb0@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1162305456 145.98.201.248 (31 Oct 2006 06:37:36 -0700) Lines: 100 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news2.volia.net!newsfeed.gamma.ru!Gamma.RU!ecngs!feeder.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail