Hi, all !
How correctly to use function ExtractAssociatedIcon, to receive a file icon on its extension (my.doc, my.xls...) ?
#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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 87 guests