FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problem with Listview
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Problem with Listview
Posted: Fri Jun 05, 2015 11:11 AM
I have a dbf with two record
Code (fw): Select all Collapse
    static function CreateTestDbf()

       local aCols := { { "PRCODE", 'C', 4, 0 }, { "PRDESC", 'C', 40, 0 }, ;
                        { "PRIMAGE", 'C', 60, 0 } }


      if .t. // ! File( "PROMO.DBF" )
          DBCREATE( "PROMO", aCols )
          USE PROMO EXCLUSIVE
          APPEND BLANK
          FIELD->PRCODE :="0001"
          FIELD->PRDESC :="PROMOZIONE  DI NATALE "
          FIELD->PRIMAGE:=".\bitmaps\files-exel.ico"
    APPEND BLANK
          FIELD->PRCODE :="0002"
          FIELD->PRDESC :="PROMOZIONE  DI PASQUA "
          FIELD->PRIMAGE:=".\bitmaps\files-word.ico"
         USE
       endif
    return nil



If I try to load this dbf into a listview control there is a strange error as you can see on this picture



the listview load my record but add 3 object (&one,&two,&tree) WHY ?

this is the test

Code (fw): Select all Collapse
    #INCLUDE "Fivewin.ch"
    #INCLUDE "Ribbon.ch"
    #include "constant.ch"
    #INCLUDE "XBROWSE.ch"

    #define TRUE .t.
    #define FALSE .f.

    Function Promo_ListVw()
       Local oDlg,oBtn1,oBtn2
       Local bClrGrad := { | lPressed | If( ! lPressed,;
                               { { 1, nRGB( 253, 254, 255 ), nRGB( 179, 217, 255 ) } },;
                               { { 1, nRGB( 179, 217, 255 ), nRGB( 253, 254, 255 ) } } ) }

    Local  nBottom   := 23
    Local  nRight    := 99
    Local  nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
    Local  nHeight := nBottom * DLG_CHARPIX_H



    Local lGridAll := TRUE
    Local lGridRow := FALSE

    Local oBtnConferma,oBtnAnnulla


    Local oGridPromo,oBtnDown,oListView, oImageList

    Local aPromozioni := {}
    Local aPromoImages:= {}


    CreateTestDbf()





    DEFINE DIALOG oDlg  SIZE nWidth, nHeight;
                TITLE "Selezionare una promozione";
                STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION,  4 )



   USE PROMO  ALIAS PR
     DO WHILE ! PR->(EoF())
        AAdd( aPromozioni,( TRIM(PR->PRDESC)))
        AAdd( aPromoImages,( allTRIM(PR->PRIMAGE)))
         PR->(DbSkip())
      ENDDO
    CLOSE PR





    oImageList = TImageList():New( 48, 48 )









       @ 150, 50  BTNBMP oBtnConferma PROMPT "&Conferma" OF oDlg FILENAME ".\bitmaps\DLG_OK.bmp" NOBORDER SIZE 50, 20 PIXEL  DEFAULT  ACTION   ( oDlg:end( IDOK ) )
       @ 150, 102 BTNBMP oBtnAnnulla PROMPT "&Annulla" OF oDlg FILENAME ".\bitmaps\DLG_NO.bmp" NOBORDER SIZE 50, 20 PIXEL  CANCEL ACTION  ( oDlg:end( IDCANCEL ) )
              oBtnConferma:bClrGrad = bClrGrad
              oBtnAnnulla:bClrGrad = bClrGrad
                         oBtnConferma:nLayout :=2
                         oBtnAnnulla:nLayout :=2


                        ACTIVATE DIALOG oDlg ;
                         ON INIT CreaListview(oImageList,aPromozioni,aPromoImages, oDlg)


     IF oDlg:nresult == IDOK



     ENDIF

     RETURN NIL

      FUNCTION CreaListview(oImageList,aPromozioni,aPromoImages, oDlg)
       Local oLvw,oBtnUp,oBtnDown


       @ 145, 10 LISTVIEW oLvw SIZE odlg:nwidth-30,130 PIXEL ;
          ACTION MsgInfo( nOption )




         for i=1 to len(aPromozioni)
            oLvw:InsertItem(i-1 , aPromozioni[i] )
           * oImageList:ReadBitmap( aPromoImages[i], 40,1)
                  oImageList:AddIcon(aPromoImages[i])
         Next i

       oLvw:SetImageList( oImageList )




    @  300,5 RBBTN oBtnUp    BITMAP ".\bitmaps\Up.BMP"  SIZE 40,40  OF  oDlg  PIXEL ;
            BORDER  CENTER ROUND ROUNDSIZE 2;
           ACTION  oLvw:KeyDown(VK_UP, 0)

    @  300,55 RBBTN oBtnDown  BITMAP ".\bitmaps\Down.BMP"  SIZE 40,40  OF  oDlg  PIXEL;
           BORDER  CENTER ROUND ROUNDSIZE 2;
           ACTION   oLvw:KeyDown(VK_DOWN, 0)






       RETU NIL



    static function CreateTestDbf()

       local aCols := { { "PRCODE", 'C', 4, 0 }, { "PRDESC", 'C', 40, 0 }, ;
                        { "PRIMAGE", 'C', 60, 0 } }


      if .t. // ! File( "PROMO.DBF" )
          DBCREATE( "PROMO", aCols )
          USE PROMO EXCLUSIVE
          APPEND BLANK
          FIELD->PRCODE :="0001"
          FIELD->PRDESC :="PROMOZIONE  DI NATALE "
          FIELD->PRIMAGE:=".\bitmaps\files-exel.ico"
    APPEND BLANK
          FIELD->PRCODE :="0002"
          FIELD->PRDESC :="PROMOZIONE  DI PASQUA "
          FIELD->PRIMAGE:=".\bitmaps\files-word.ico"

         USE
       endif

    return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 08:53 AM
Hello,
I see this behavior too!
The problem is in tlistview.prg:
Code (fw): Select all Collapse
METHOD New( nTop, nLeft, aPrompts, bAction, oWnd, nClrFore,;
            nClrBack, lPixel, lDesign, nWidth, nHeight, cMsg ) CLASS TListView

   DEFAULT nTop     := 0, nLeft := 0,;
           aPrompts := { "&One", "&Two", "T&hree" },;

The only workaround I found is call New directly, in your case:
Code (fw): Select all Collapse
 // @ 145, 10 LISTVIEW oLvw SIZE odlg:nwidth-30,130 PIXEL ACTION MsgInfo( nOption )
    oLvw := TListView():New( 145, 10,{}, { | nOption, Self | MsgInfo( nOption ) },,,, .T., .F., odlg:nwidth-30, 130, )

The easy way is to preprocess then add as 3rd parameter an empty array.
The listview implementation of fivewin looks only a sketch.

I see you have problem with the imageList too, I solved it in this way:
At imageList creation:
Code (fw): Select all Collapse
oImageList = TImageList():New( 48, 48 )
oImageList:hImageList := Fix(48,48)

plus this DUMP:
Code (fw): Select all Collapse
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#include <CommCtrl.h>

HB_FUNC( FIX )
{  
   typedef HIMAGELIST ( __stdcall * PIMAGELIST_CREATE ) ( int cx, int cy,   
                        UINT flags, int cInitial, int cGrow );
   static PIMAGELIST_CREATE pImageList_Create = NULL;
   HMODULE hDLL = NULL;
   if( pImageList_Create == NULL )
   {
      hDLL = LoadLibrary( "comctl32.dll" );
      if( hDLL )
         pImageList_Create = ( PIMAGELIST_CREATE ) GetProcAddress( hDLL, "ImageList_Create" );
   }
   
#ifndef _WIN64
  hb_retnl( ( LONG ) pImageList_Create( hb_parnl( 1 ), hb_parnl( 2 ),
             ILC_MASK | ILC_COLOR32, 0, 50 ) );
#else             
   hb_retnll( ( LONGLONG ) pImageList_Create( hb_parnl( 1 ), hb_parnl( 2 ),
             ILC_MASK | ILC_COLOR32, 0, 50 ) );
#endif
}
#pragma ENDDUMP

Regards,
Antonino
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 09:37 AM

thanks
run all ok
only when i compile fix function if I use w2 /w1 or w
Warning W8004 test.prg 396: 'hDLL' is assigned a value that is never used in function HB_FUN_FIX

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 10:02 AM
Try

Code (fw): Select all Collapse
HMODULE hDLL; // = NULL
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 02:45 PM
The solution is to modify tlistvie.prg this way:

Code (fw): Select all Collapse
METHOD New( nTop, nLeft, aPrompts, bAction, oWnd, nClrFore,;
            nClrBack, lPixel, lDesign, nWidth, nHeight, cMsg ) CLASS TListView

   DEFAULT nTop     := 0, nLeft := 0,;
           aPrompts := {},;


We just include three TListView examples in FWH and never got any feedback about it up today. Thank you :-)

Included for the next FWH build.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 03:06 PM

Antonino,

If we replace ILC_COLOR24 with ILC_COLOR32 then I guess FWH code should properly work

unless I am missing something else.

Included for next FWH build, thanks! :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 03:08 PM
Silvio,

Silvio.Falconi wrote:thanks
run all ok
only when i compile fix function if I use w2 /w1 or w
Warning W8004 test.prg 396: 'hDLL' is assigned a value that is never used in function HB_FUN_FIX


Replace this code:
Code (fw): Select all Collapse
   HMODULE hDLL = NULL;
   if( pImageList_Create == NULL )
   {
      hDLL = LoadLibrary( "comctl32.dll" );
      if( hDLL )
         pImageList_Create = ( PIMAGELIST_CREATE ) GetProcAddress( hDLL, "ImageList_Create" );
   }


with this:
Code (fw): Select all Collapse
   if( pImageList_Create == NULL )
   {
      HMODULE hDLL = LoadLibrary( "comctl32.dll" );
      if( hDLL )
         pImageList_Create = ( PIMAGELIST_CREATE ) GetProcAddress( hDLL, "ImageList_Create" );
   }
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 03:10 PM

Also a FreeLibrary() call is missing in that fix.

Anyhow next FWH build will include these changes :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 03:32 PM
Antonio Linares wrote:Also a FreeLibrary() call is missing in that fix.

Anyhow next FWH build will include these changes :-)

ops :-)
so the final version is:
Code (fw): Select all Collapse
 if( pImageList_Create == NULL )
   {
      HMODULE hDLL = LoadLibrary( "comctl32.dll" );
      if( hDLL )
         pImageList_Create = ( PIMAGELIST_CREATE ) GetProcAddress( hDLL, "ImageList_Create" );
      FreeLibrary(hDLL);
   }

It is missing in FiveWin code, fwh\source\winapi\imagelis.c

You are correct, another solution is modify imagelis.c to create always 32bit imageList, but generally I prefer don't change fivewin code.
Regards,
Antonino
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problem with Listview
Posted: Wed Jun 10, 2015 04:15 PM

Antonino,

The problem that we have in imagelis.c is that we load the DLL to get all the pointers at once to speed up
the need for loading and freeing a DLL.

In fact we would need an exit procedure to free the DLL, but as we only load it once, the EXE will release
it on the application exit, so its not a problem.

The problem only comes from loading it more than one time, then the EXE when it finish will not release those
extra loads, it will just decrease a Windows internal counter in one.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Problem with Listview
Posted: Thu Jun 11, 2015 11:11 AM

Antonio,

is there a function to call the icon of file ?

I explain if I add a record sample

c:\work\testsample.doc

it must create a item on listview and show his icon on listview

is it possible ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Problem with Listview
Posted: Thu Jun 11, 2015 01:33 PM
The FWH function Icon_Read returns the HICON of the file regardless its extension.
Here a snapshot of my code:

Code (fw): Select all Collapse
 nImage := Icon_Read("c:\work\testsample.doc")
      nImage := max(0,ILADDICON( oImageList:hImageList, nImage ) )
      DestroyIcon(nImage)
      oList:InsertItem(nImage, cFile, 0)


Regards,
Antonino
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Problem with Listview
Posted: Fri Jun 12, 2015 08:45 AM

I saw good.. I not Known this function sorry

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Problem with Listview
Posted: Sat Jun 13, 2015 12:06 PM

to make a preview for each file I need IPreviewHandler https://msdn.microsoft.com/en-us/librar ... 15(v=vs.85).aspx
but I not Know how use it on TListview Item class
Any solution please

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion