BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting image from web site

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Web)
View previous topic :: View next topic  
Author Message
Grumps
Guest





PostPosted: Fri Mar 16, 2007 8:10 am    Post subject: Getting image from web site Reply with quote



Hi All
I'm not really a C++ programmer, but I have dabbled with C++Builder 5 a bit.
I'm trying to grab an image from a web site.
I can open a browser using CppWebBrowser1->Navigate(URL); and this is fine.
Firstly, how do I know when the page has completed, and second, how do you
get the images from this page?
Sorry if this has been asked a thousand times, but my C++ knowledge is
somewhat lacking.
Back to top
Graeme
Guest





PostPosted: Fri Mar 16, 2007 2:35 pm    Post subject: Re: Getting image from web site Reply with quote



Grumps wrote:
Quote:
Hi All
I'm not really a C++ programmer, but I have dabbled with C++Builder 5
a bit. I'm trying to grab an image from a web site.
I can open a browser using CppWebBrowser1->Navigate(URL); and this is
fine. Firstly, how do I know when the page has completed, and second,
how do you get the images from this page?
Sorry if this has been asked a thousand times, but my C++ knowledge is
somewhat lacking.

Ok. Got the page completed issue sorted using the OnDocumentComplete event.
Just need to get the images from the page.
Back to top
Hans Galema
Guest





PostPosted: Fri Mar 16, 2007 3:45 pm    Post subject: Re: Getting image from web site Reply with quote



Graeme wrote:

Quote:
Just need to get the images from the page.

T(Cpp)WebBrowsr has a method to give you all the img's on that page.

From thereon you can get the url in the src="url".

Code below shows the amount of images and after that displays the
src url's. Only it does not. It does display the url for the first image
only.

Maybe you can get it to work properly. At the moment I have no time for it.
If you get it to work pleas post the code.

Hans.

void __fastcall TForm1::SpeedButton22Click(TObject *Sender)
{
AnsiString AllImages;

IHTMLDocument2 *HTMLDoc = NULL;

if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
{
IHTMLElementCollection *pAll = NULL;

if(SUCCEEDED(HTMLDoc->get_images(&pAll))) // mshtml.h
{
long collSize;
pAll->get_length(&collSize);
IDispatch* id;
VARIANT one;
for( int idx = 0; idx < collSize; idx++)
{
one.vt = VT_UINT;
one.lVal = idx;
VARIANT two = {0};
pAll->item(one,two,&id);
IHTMLElement* pElem = NULL;
id->QueryInterface( IID_IHTMLElement, (LPVOID*)&pElem );
BSTR bstr = NULL;
pElem->toString(&bstr);

AllImages += bstr;
AllImages += "\n";
}

ShowMessage ( "AllObjects for Images\n\n" + AllImages ); // shows you amount


long count = -1;
long length = 0;

pAll->get_length( &length);

// ShowMessage ( "length: " + AnsiString ( length ) );

TVariant name = NULL;
TVariant index = count;
IDispatch *pDisp = NULL;

while ( ++ count < 5) // 5!!
{
OleVariant varIndex((int)count);
// index = count;
pDisp = NULL;

if(SUCCEEDED(pAll->item(name, varIndex, &pDisp)))
// if(SUCCEEDED(pAll->item(name, index, &pDisp)))
//if(SUCCEEDED(pAll->item("",count, &pDisp)))
{
// ShowMessage ( "SUCCEEDED(pAll->item(name, index, &pDisp))) " + IntToStr ( (int)pDisp) );

if ( pDisp )
{
IHTMLImgElement *ImgElement = NULL; // mshtml.h
pDisp->QueryInterface(IID_IHTMLImgElement, (LPVOID*)&ImgElement);
pDisp->Release();

if(ImgElement)
{
WideString src;
ImgElement->get_src ( &src );
ShowMessage ( src) ;

SysFreeString (src);

ImgElement->Release();
}
}
}
else
break;
}

pAll->Release();
}

HTMLDoc->Release();
}
}
Back to top
Grumps
Guest





PostPosted: Fri Mar 16, 2007 3:56 pm    Post subject: Re: Getting image from web site Reply with quote

Hans Galema wrote:
Quote:
Graeme wrote:

Just need to get the images from the page.

T(Cpp)WebBrowsr has a method to give you all the img's on that page.

From thereon you can get the url in the src="url".

Code below shows the amount of images and after that displays the
src url's. Only it does not. It does display the url for the first
image only.

Maybe you can get it to work properly. At the moment I have no time
for it. If you get it to work pleas post the code.

Hans.

void __fastcall TForm1::SpeedButton22Click(TObject *Sender)
{
AnsiString AllImages;

IHTMLDocument2 *HTMLDoc = NULL;

I've fallen at the first hurdle!
Where do I get IHTMLDocument2 from? Is it part of C++Builder5?
Back to top
Hans Galema
Guest





PostPosted: Fri Mar 16, 2007 4:42 pm    Post subject: Re: Getting image from web site Reply with quote

Grumps wrote:

Quote:
I've fallen at the first hurdle!
Where do I get IHTMLDocument2 from? Is it part of C++Builder5?

The comment should have given you the clue:

if(SUCCEEDED(HTMLDoc->get_images(&pAll))) // mshtml.h

Hans.
Back to top
Grumps
Guest





PostPosted: Fri Mar 16, 2007 4:47 pm    Post subject: Re: Getting image from web site Reply with quote

Hans Galema wrote:
Quote:
Grumps wrote:

I've fallen at the first hurdle!
Where do I get IHTMLDocument2 from? Is it part of C++Builder5?

The comment should have given you the clue:

if(SUCCEEDED(HTMLDoc->get_images(&pAll))) // mshtml.h

Oops! It does now. Thanks.
Back to top
Grumps
Guest





PostPosted: Sun Mar 18, 2007 1:23 pm    Post subject: Re: Getting image from web site Reply with quote

"Hans Galema" <notused (AT) notused (DOT) nl> wrote in message
news:45fa760d$1 (AT) newsgroups (DOT) borland.com...
Quote:
Graeme wrote:

Just need to get the images from the page.

T(Cpp)WebBrowsr has a method to give you all the img's on that page.

From thereon you can get the url in the src="url".

Code below shows the amount of images and after that displays the
src url's. Only it does not. It does display the url for the first image
only.

Maybe you can get it to work properly. At the moment I have no time for
it.
If you get it to work pleas post the code.

I've looked at the code, but have absolutely no idea why it doesn't work.
I've since found another code snippet that gets an image. In fact, there is
only one image on the page I'm looking at, which makes it easy.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Web) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.