Links to Images
[Previous] [Main] [Next]

 
Because htmlHyperLink is derived from htmlGroup, creating hyperlinks from images is a snap. Simply instantiate an htmlHyperLink object for the desired URL, then insert an htmlImage object describing the image using the << insertion operator. As with most html++ classes, several versions of constructors are available. The following code snippets are all functionally equivalent:  
 
   //  example 1  
page << htmlHyperLink( "http://www.dcmicro.com",  
            htmlImage( "/images/logo.gif" ) ) ;  
 
   //  example 2  
htmlImage  image( "/images/logo.gif" ) ;  
page << ( htmlHyperLink( "http://www.dcmicro.com" )  
             << image ) ;  
 
   //  example 3  
htmlImage  image( "/images/logo.gif" ) ;  
htmlHyperLink  h ;  
h.URL( "http://www.dcmicro.com" ) ;  
h << image ;  
page << h ;  
 
Each of the above examples produce the following HTML output:  
 
<A HREF="http://www.dcmicro.com"><IMG SRC="/images/logo.gif"></IMG></A>  
 
 
The following is a complete example application :  
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   //  Add some text to the page  
   page << "Click the image below to jump to DC Micro "  
        << "Development's web site."  
        << htmlParagraph() ;  
 
   //  Create an object for the image  
   htmlImage  logo( "http://www.dcmicro.com/images/htmlpp_logo2.gif" ) ;  
   logo.AlternateText( "html++ logo" )  
      .Border( 0 )  
      .Align( align_right ) ;  
 
   //  Add the hyperlink containing the image to the page  
   page << htmlHyperLink( "http://www.dcmicro.com", logo ) ;  
     
   server << page ;  
   return 0 ;  
}  
 
 
When executed, the above program produces the following HTML output:  
 
Content-Type: text/html  
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
Click the image below to jump to DC Micro Development's web site.<P></P>  
<A HREF="http://www.dcmicro.com"><IMG SRC="http://www.dcmicro.com/images/htmlpp_logo2.gif" ALT="html++ logo" BORDER="0" ALIGN="RIGHT"></IMG></A>  
</BODY>  
</HTML>  
 
 

ex_hyperlink2.gif  



©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.