"override" Grid Imagelist with System Imagelist. ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

"override" Grid Imagelist with System Imagelist. ?

Post by AUGE_OHR »

hi,

under GRID you will find
- <ParentWindowName>.<GridControlName>.Image ( lTransparent ) := { "image1.png", "image2.bmp", ... }
- <ParentWindowName>.<GridControlName>.ImageIndex ( nRow , nCol ) [ := | -->] nIndex
- <ParentWindowName>.<GridControlName>.ImageList [ := | -->] hImageList
to use Image in GRID you need Image as File or Resource and assign it with ImageIndex ( zero-based )

Code: Select all

   Win_1.Grid_Device.Image( .T. ) := acImage
   FOR i = 1 TO Win_1.Grid_Device.ItemCount
      Win_1.Grid_Device.ImageIndex( i, 1 ) := i - 1
   NEXT
here ImageIndex( i, 1 ) point to the Image which i have load before

---

Explorer show System Icon

in c:\hmg.3.4.4\SOURCE\BosTaurus\c_BosTaurus.c there are some HB_FUNC()

Code: Select all

   // BT_ImageListGetSystemIcon ( [ lLargeIcon ] ) --> hImageList ( You NEVER add, remove or delete icons from the System Imagelist )
   hImageList := BT_IMAGELISTGETSYSTEMICON()

   // BT_DirectoryInfo ( [nCSIDL|cPath] , [nTypeList] , @nIndexRoot, @CSIDL_Name ) --> { { Data1, Data2, Data3, ... } , ... }
   aInfoDir :=  BT_DIRECTORYINFO( "c:\hmg.3.4.4\0\HBFM", BT_DIRECTORYINFO_INTERNALDATA_IMAGEINDEX+BT_DIRECTORYINFO_LISTALL, @nIndexRoot )

   // BT_ImageListExtractIcon(himl, nIndex)
   hIcon := BT_IMAGELISTEXTRACTICON(hImageList,190)
BT_DIRECTORYINFO give me a Array like Directory but have more Element.
last Element "seem" the "Icon Number" PRG = 190

---

my try

Code: Select all

   @ nRow, nCol GRID &cObj ;
           PARENT &cForm ;
   ...
   SetProperty( cForm, cObj, "PaintDoubleBuffer", .T. )
   SetProperty (cForm, cObj,"ImageList", hImageList )
i have made hImageList Field-Wide STATIC and add it here as Imagelist ... is this right :?: ( does not crash )

Code: Select all

   aInfoDir :=  BT_DIRECTORYINFO(cNewPath, BT_DIRECTORYINFO_INTERNALDATA_IMAGEINDEX+BT_DIRECTORYINFO_LISTALL, @nIndexRoot )
   iMax := LEN(aInfoDir)
   i := 1
   FOR i := 1 TO iMax
      cSeek := TRIM(aInfoDir[ i ][ F_NAME ])
      nIco  := aInfoDir[ i ][ 8 ]
      nPosi := ASCAN( aNewDir, { | x | x[ F_NAME ] = cSeek } )
      IF nPosi > 0
      DO CASE
         CASE cForm = "WinLeft"
            SetProperty( "WinLeft" , cObj, "ImageIndex",i,1,nIco)
         CASE cForm = "WinRight"
            SetProperty( "WinRight", cObj, "ImageIndex",i,1,nIco)
*         hIcon := BT_IMAGELISTEXTRACTICON(hImageList,nIco)
*         SetProperty( "WinRight", cObj, "ImageIndex",i,1,hIcon)
      ENDCASE
      ENDIF
   NEXT
but i see no Icons (empty place) :(
i also try to use hIcon but it does not help :x

do i need to create my own Imagelist and add those hIcon :idea:
i "think" those Icon are in System-Imagelist or ... :?:
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: "override" Grid Imagelist with System Imagelist. ?

Post by danielmaximiliano »

I don't understand what you want to do, my method to upload icons or images to my GRID is like this.

Code: Select all

   
   DBUSEAREA     ( .T. , "DBFCDX" , "BANDERAS" ) 
   DBCREATEINDEX( "NOMBRE" , "NOMBRE") 
   DBSETINDEX    ( "NOMBRE" )
  
   Do While !Eof()
         AADD( aImagenes , '.\Banderas\16x16\' + ALLTRIM(BANDERAS->NOMBRE )+'.bmp' )
		 BANDERAS->(DBSKIP(1))
   End Do
   BANDERAS->(DBGOTOP())
  
  DBUSEAREA     ( .T. , "DBFCDX" , "GS1" ) 
  DBCREATEINDEX( "PREFIX" , "PREFIX") 
  DBSETINDEX    ( "PREFIX" )
  Do While !Eof()
         AADD( aGS1 , { GS1->PREFIX , GS1->IMAGEN , GS1->NOMBRE } )
		 GS1->( DBSKIP( 1 ) )
  End Do
GS1 = Barcodes are symbols that can be scanned by proper systems and play a key role in supply chains. Find here several types of barcodes managed by GS1.
Banderas = Flags
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: "override" Grid Imagelist with System Imagelist. ?

Post by AUGE_OHR »

hi,
danielmaximiliano wrote: Mon Feb 10, 2020 9:23 pm I don't understand what you want to do, my method to upload icons or images to my GRID is like this.

Code: Select all

   AADD( aImagenes , '.\Banderas\16x16\' + ALLTRIM(BANDERAS->NOMBRE )+'.bmp' )
that is the normal HMG Way use *.BMP Files as Image for GRID.

not sure how your 16x16 BMP look like ...
what do you do when User switch Scale to 200% ... did you switch to 32x32 BMP :?:

i want to use System-Icon as you see it in Explorer for folder and files.
those Icon have from 16x16 up to 256x256 Image and Imagelist will use "right Size" when Scale is <> 100 %

---

this is the Code i like to use with HMG GRID to get File-Icon like Explorer

Code: Select all

 SHFILEINFO psfi;
 hImageList = (HIMAGELIST)SHGetFileInfo(szFileName, 0, &psfi,
        sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
 ListView_SetImageList(hList, hImageList, LVSIL_SMALL);
---

HMG use this

in c:\hmg.3.4.4\SOURCE\c_grid.c you will find

Code: Select all

HB_FUNC (ADDLISTVIEWBITMAP)
...
         if ( hImageList == NULL )
            hImageList = HMG_ImageListLoadFirst (FileName, nCount, Transparent, &nWidth, NULL);
         else
            HMG_ImageListAdd (hImageList, FileName, Transparent);
as you can see it use Filename e.g. *.BMP and not hBitmap or hIcon

Code: Select all

HB_FUNC ( SETIMAGELISTVIEWITEMS )
...
	LI.mask= LVIF_IMAGE ;	
	...
        LI.iImage= hb_parni( 3 );
this i have to check out

in c:\hmg.3.4.4\SOURCE\c_GridEx.c you will find

Code: Select all

HB_FUNC ( LISTVIEW_SETITEMIMAGEINDEX )
...
      LV.mask      = LVIF_IMAGE;
      ...
      LV.iImage    = iImage;
it also have LVIF_IMAGE so it might be interesting.

---

i understand that level is higher than HMG ... it is going to MiniGUI Level.
i just try to enhance HMG without "break Code".

i use System-Icon for all Stuff which belong to OS so these Icon will look like there OS.
a Drive Icon in Explorer are always same icon but it look different under XP than in Windows 10

i use Bitmap, Jpg, GIF or PNG for "external" Image but not as Image for Control.
Barcode are generate so i don`t need a File ... i can store hBitMap or hIcon to Imagelist and use it to Draw or Print

Windows use Imagelist and HMG use it e.g. for GRID Header ... so why not for GRID itself :(

---

i know MiniGUI use Imagelist ... but "many" Sample are not Compatible to HMG ...
i have ask for System-Icon here http://hmgforum.com/viewtopic.php?f=12&t=6185&p=59902

i have try to re-write that Sample to HMG Level ... not the BUTTON Part with EXTRACT ... but using ExctractIcon itself.
not sure if it make Sence to do that Work when later switch to MiniGUI while reach the Limit of HMG ...

p.s. i like to help to enhance HMG Source Code of GRID so who have i to contact for this .
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: "override" Grid Imagelist with System Imagelist. ?

Post by danielmaximiliano »

not sure how your 16x16 BMP look like ...
what do you do when User switch Scale to 200% ... did you switch to 32x32 BMP
Directory : mi directory contain 122 elements
Flags.png
Flags.png (5.18 KiB) Viewed 2901 times
Image 16x16
16x16.png
16x16.png (17.98 KiB) Viewed 2901 times
Image 32x32
32x32.png
32x32.png (14.62 KiB) Viewed 2901 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: "override" Grid Imagelist with System Imagelist. ?

Post by AUGE_OHR »

hi

i can see that you Icon get bigger but these are not Windows icon, or :?:
i agree for normal Apps i have "extra" Icon but Windows have a lot of Icon which can be used.

i mean those System Icon which are assign with Extension like BMP, PDF, DOC, XLS ... and Folder Icon.
these Icon are display by Explorer and use API SHGetFileInfo

i have search in HMG and MiniGUI but not found SHGetFileInfo.
FiveWin have HB_FUNC(ICON_READEX) which use SHGetFileInfoW ... hm ... perhaps i have to use UNICODE Version :idea:
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: "override" Grid Imagelist with System Imagelist. ?

Post by danielmaximiliano »

Hi
SHGetFileInfo and SHGetFileInfoW is included in MinGW, native Harbor / HMG compiler

See https://sourceforge.net/p/mingw-w64/mai ... /31703900/

Lib = LibShell32.a
Last edited by danielmaximiliano on Tue Feb 11, 2020 2:54 pm, edited 1 time in total.
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: "override" Grid Imagelist with System Imagelist. ?

Post by gfilatov »

AUGE_OHR wrote: Tue Feb 11, 2020 12:06 pm hi
...
i mean those System Icon which are assign with Extension like BMP, PDF, DOC, XLS ... and Folder Icon.
these Icon are display by Explorer and use API SHGetFileInfo

i have search in HMG and MiniGUI but not found SHGetFileInfo.
Hi Jimmy,

Please try the attached old MiniGUI project :arrow:
Attachments
IconAssociatedFile.zip
Select file & Icon associated with the file type
(662.03 KiB) Downloaded 175 times
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: "override" Grid Imagelist with System Imagelist. ?

Post by AUGE_OHR »

hi,
gfilatov wrote: Tue Feb 11, 2020 1:52 pm Please try the attached old MiniGUI project :arrow:
Yes that work .
can you point me to Source or tell me "how" it work :idea:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: "override" Grid Imagelist with System Imagelist. ?

Post by AUGE_OHR »

hi,
danielmaximiliano wrote: Tue Feb 11, 2020 1:46 pm SHGetFileInfo and SHGetFileInfoW is included in MinGW, native Harbor / HMG compiler

See https://sourceforge.net/p/mingw-w64/mai ... /31703900/

Lib = LibShell32.a
Thx for this Info.

when i say "did not found" i talk about *.PRG Sample.
when found a HB_FUNC() i need a Description or Sample how Parameter work

when use SHGetFileInfo() it will return hIcon which i can assign to iImage

Code: Select all

METHOD DXE_ListView:OnDISPINFO( o, lp ) // using LVN_GETDISPINFO
   st := NMLVDISPINFO() :New()
   st:_link_( lp, .F. )

   // ZERO-based :iItem and :iSubItem
   nRec := st:item:iItem + 1                                       // Array ZERO-based+1
   nSub := st:item:iSubItem + 1                                    // always 0 when Ownerdraw ?
   ctext := ::aSource[ nRec ] [ nSub ]                             // use Array
   
  // fileIconIndex() use SHGetFileInfo() 
   st:item:iImage := fileIconIndex( ::cStartdir + ::aSource[nRec+1][LV_NAME]+"."+::aSource[nRec+1][LV_EXT], cAttr )
   // Assign Array Text to Display
   st:item:cText := ctext                                       // +CHR(0)
other Way is to use Imagelist

Code: Select all

   nFileHandle := oIcon:LoadFileIcon( cFile, cAttr )
   IF nFileHandle > 0
      nIcoHandle := @User32:CopyIcon( nFileHandle )
   ELSE
      nIcoHandle := oIcon:load( ::cDllName, ICON_DUMMY )
   ENDIF
   // for Icon use ImageList_ReplaceIcon()
   @ comctl32:ImageList_ReplaceIcon( hImgLstSmall, ;   // A handle to the image list.
                                              - 1, ;   // The index of the image to replace. If i is -1, the function appends the image to the end of the list.
                                        nIcoHandle )   // The handle to the icon or cursor that contains the bitmap and mask for the new image.
   @ User32:DestroyIcon( nIcoHandle )
than i "just" have to set Imagelist and share it

Code: Select all

   @ User32:SetWindowLongA( ::hLv, GWL_STYLE, nor( @User32:GetWindowLongA( ::hLv, GWL_STYLE ), LVS_SHAREIMAGELISTS ) )

   hImgLstLarge := ::lv_SetImageList( LVSIL_NORMAL, hImgLstLarge )
   hImgLstSmall := ::lv_SetImageList( LVSIL_SMALL, hImgLstSmall )

   IF ( !EMPTY( hImgLstLarge ) )
      @ comctl32:ImageList_Destroy( hImgLstLarge )
   ENDIF
   IF ( !EMPTY( hImgLstSmall ) )
      @ comctl32:ImageList_Destroy( hImgLstSmall )
   ENDIF
so it is more than only API Function SHGetFileInfo() to get it work with HMG or MiniGUI and GRID (or other Control)

i will freeze Icon / Imagelist until i have learn more ... still a lot of work to do.
thx for help.
have fun
Jimmy
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: "override" Grid Imagelist with System Imagelist. ?

Post by gfilatov »

AUGE_OHR wrote: Wed Feb 12, 2020 2:21 am hi,
gfilatov wrote: Tue Feb 11, 2020 1:52 pm Please try the attached old MiniGUI project :arrow:
Yes that work .
can you point me to Source or tell me "how" it work :idea:
Hi,

Please take a look for the code snippet below:

Code: Select all

...
   // The function returns the icon file type associations 
   hIcon := EXTRACTASSICON( 0, cFile , @nIndex )
   hBmp := BmpFromIcon( hIcon )    // return bmp handle

   This.&(cObj).Hbitmap := hBmp
where

Code: Select all

#pragma BEGINDUMP

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

extern HBITMAP Icon2Bmp( HICON hIcon );

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( BMPFROMICON )
{
HICON hIcon = ( HICON ) hb_parnl( 1 );

hb_retnl( ( LONG ) Icon2Bmp( hIcon ) );
}

#pragma ENDDUMP
It is the MiniguiEx power 8-)
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
Post Reply