FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Icon in Webview
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Icon in Webview
Posted: Sat May 27, 2023 06:37 PM
Hi,

Is it possible to show an icon in WebView not as a link to a file, but as a value (generate an icon from the source text) ?
For example
Code (fw): Select all Collapse
pol:=0
     hBmp:=BmpFromIcon(EXTRACTASSICON( 0, "Name.pdf", @pol))
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Icon in Webview
Posted: Sun May 28, 2023 09:26 AM

Dear Yuri,

Could you please describe what function EXTRACTASSICON( 0, "Name.pdf", @pol) would do ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Icon in Webview
Posted: Sun May 28, 2023 11:39 AM
Code (fw): Select all Collapse
#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( EXTRACTASSICON )
{
  HICON hIcon;
  LONG hInstance = hb_parnl( 1 );
  char * lpIconPath = ( char * ) hb_parc( 2 );
  WORD lpiIcon = hb_parnl( 3 );

  hIcon = ExtractAssociatedIcon( ( HINSTANCE ) hInstance, lpIconPath, &lpiIcon );

  hb_stornl( lpiIcon, 3 );
  hb_retnl( ( LONG ) hIcon );
}

DLL32 FUNCTION ExtractAssociatedIcon( hIns AS LONG, cPth AS LPSTR, nInd AS LONG ) ;
AS LONG PASCAL FROM "ExtractAssociatedIconA" LIB "SHELL32.DLL"
Here it is described how to show an image in HTML not by link, but by value

https://www.w3docs.com/snippets/html/how-to-display-base64-images-in-html.html

To use this method I need to use hb_base64encode(), but I don't understand how to do it for
hBmp:=BmpFromIcon(EXTRACTASSICON( 0, "Name.pdf", @pol)) :(
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Icon in Webview
Posted: Sun May 28, 2023 03:15 PM

Dear Yuri,

You may try this:

hDib = DibFromBitmap( hBmp )

DibWrite( cFileName, hDib )

hb_base64Encode( hb_memoRead( cFileName ) )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Icon in Webview
Posted: Sun May 28, 2023 09:08 PM
While ExtractAssociatedIcon(...) is one way of fetching the icon of the associated application of a file, FWH provides much simpler way.

Most used FW_ReadImage()/oWnd:ReadImage() can also be used.

Just to check, please run this one line code:
Code (fw): Select all Collapse
XIMAGE( "name.pdf(256x256)" )


FWH also allows us to select the size of the icon, vix. 16x16, 32x32, 64x64 or 256x256. Just add "(64x64") to the file name and use the function.

Next:
For base64 encoding of any image, FWH provides the class TImageBase64() (file fwh\source\classes\imageb64.prg)

Now let us see how to use.
In this sample, we will select 32x32 iconsize and prepare Base64 tag to be included in the html script directly.
We will also test a sample HTML
Code (fw): Select all Collapse
   // Read icon --> bmp --> png formatted string
   aBmp  := FW_ReadImage( nil, ".pdf(32x32)" )
   cPng  := GDIP_BMP2PNGSTR( aBmp[ 1 ] )
   PalBmpFree( aBmp )
   //
   
   // Use the class to prepare base64 tag
   oImage64 := TImageBase64():New( cPng )
   cTag := oImage64:MakeText( .f., .t., .f. )
   oImage64:TestHtml() // if you want to test before using the tag
cTag in the above program looks like this:
"<img src="data:image/png;base64,iVBORw0KGgoAAAANSU...../>"

You can insert this html Tag at the desired place in your HTML code.
To make sure this tag really works, you can test with:
Code (fw): Select all Collapse
oImage64:TestHtml()


Note:
If we want Icon of 16x16 or 32x32, we need not specify the full pdf file name. It is enough to specify ".pdf(32x32)"
If we want icon size 64x64 or 256x256, then we need to specify an existing file name in full.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Icon in Webview
Posted: Mon May 29, 2023 08:11 PM
Thank you very much, everything worked out !!! :D

Continue the discussion