File icon

File icon

Postby Natter » Sun Jul 10, 2011 5:37 pm

Hi, all !

How correctly to use function ExtractAssociatedIcon, to receive a file icon on its extension (my.doc, my.xls...) ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: File icon

Postby Daniel Garcia-Gil » Sun Jul 10, 2011 5:41 pm

User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: File icon

Postby Natter » Sun Jul 10, 2011 5:56 pm

Thanks, Daniel. But it for исполнимых files(com, exe). And to me are necessary associated on the extension
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: File icon

Postby Daniel Garcia-Gil » Sun Jul 10, 2011 7:13 pm

Natter

you can use any file type...

it's same example using ExtractAssociatedIcon


Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"

Function Main()
local ico, oIcon, oWnd, aRet

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
local nIndex := 0
cname := cGetFile( "*.*", "Select file" )

if cname != NIL
   ico  := EXTRACTASSICON( 0, cname, @nIndex )
   hBmp := BmpFromIcon( ico )
   
   oCol:oBrw:aCols[ 1 ]:AddBmpHandle( hBmp )
   
   aRet := { Len( oCol:oBrw:aCols[ 1 ]:aBitmaps ), cName }


endi

RETU aRet

#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 );
 
}

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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: File icon

Postby Natter » Sun Jul 10, 2011 8:10 pm

Daniel, many thanks. All work perfectly
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests