How to select a Icon from Exe with multiple Icons ?

How to select a Icon from Exe with multiple Icons ?

Postby ukoenig » Fri Oct 21, 2011 11:17 pm

Hello,

Is it possible to select a Icon from Exe-file
with multiple icons included ?

As a sample : Explorer.exe includes 23 ( main ) Icons :

Image

with the Test below, the first Main-Icon from the Exe-file is selected
and saved ( extracted ) as BMP-file :

Image

Code: Select all  Expand view

#INCLUDE "FIVEWIN.CH"
#include "xbrowse.ch"

FUNCTION MAIN()
local ico, oIcon, oWnd, aRet, oBrw

aArr_g := {}

for nI := 1 to 5
    aadd( aArr_g, { "", Space( 50 ), 0 } )
next

DEFINE WINDOW oWnd FROM 0, 0 TO 30, 60 TITLE "Test"

   @ 0,0 XBROWSE oBrw OF oWnd columns {1, 2, 3};
      Array aArr_g sizes {100, 250, 1} LINES CELL autocols fastedit

   oBrw:nMarqueeStyle              := 1
   oBrw:nRowHeight                 := 33

//   oBrw:aCols[ 1 ]:lBmpStretch     := .t.
   oBrw:aCols[ 1 ]:lBmpTransparent := .t.
   oBrw:aCols[ 1 ]:nDataBmpAlign   := AL_CENTER
   oBrw:aCols[ 1 ]:bStrData        := {|| NIL }
   oBrw:aCols[ 1 ]:bBmpData        := {| | oBrw:aRow[ 3 ] }

   oBrw:aCols[ 2 ]:nEditType       := EDIT_BUTTON
   oBrw:aCols[ 2 ]:bEditBlock      := {|nRow, nCol, oCol| aRet := file_load( oCol ), ;
                                                          oBrw:aRow[ 3 ] := aRet[ 1 ],;
                                                          oBrw:aRow[ 2 ] := aRet[ 2 ] }

   oBrw:aCols[ 3 ]:lHide           := .T.

   oWnd:oClient                    := oBrw

   oBrw:CreateFromCode()

ACTIVATE WINDOW oWnd //on paint( PalBmpDraw( hDC, 0, 0, hBmp ) )

return nil

/*------------------------------------------------------------------------*/

FUNC file_load( oCol )
loca cname
local hBmp
local aRet
cname := cGetFile( "*.*", "Select file" )

if cname != NIL
   ico  := ICON_EXEREAD(cname)
   hBmp := BmpFromIcon( ico )
   // write Icon to Disk
   // ----------------------
   hDib := DibFromBitmap( hBmp )
   DibWrite( "test.bmp", hDib )  
   // ----------------------
   DeleteObject( hDib )

   oCol:oBrw:aCols[ 1 ]:AddBmpHandle( hBmp )
   
   aRet := { Len( oCol:oBrw:aCols[ 1 ]:aBitmaps ), cName }

endif

RETURN aRet

#pragma BEGINDUMP

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

HB_FUNC( ICON_EXEREAD )
{
   SHFILEINFO sfi;
   
   ZeroMemory(&sfi, sizeof(SHFILEINFO));

   SHGetFileInfo(hb_parc(1), 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON );
   
   hb_retnl( ( LONG ) sfi.hIcon );

}

HB_FUNC( BMPFROMICON )
{
     HICON hIcon = ( HICON ) hb_parnl( 1 );
     HDC HDCMem  = GetDC( GetDesktopWindow() );
   HDC hDC = CreateCompatibleDC( HDCMem );
   HBITMAP hBitmap = CreateCompatibleBitmap(HDCMem, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
   HBITMAP hOldBitmap = (HBITMAP)SelectObject(hDC, hBitmap);
   DrawIcon(hDC, 0, 0, hIcon);
   SelectObject(hDC, hOldBitmap);
   DeleteDC(hDC);

   hb_retnl( ( LONG ) hBitmap );
}

#pragma ENDDUMP
 


Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 111 guests