Page 1 of 1

Problem with Listview

Posted: Fri Jun 05, 2015 11:11 am
by Silvio.Falconi
I have a dbf with two record

Code: Select all | Expand


    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

Image

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

this is the test

Code: Select all | Expand



    #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





 

Re: Problem with Listview

Posted: Wed Jun 10, 2015 8:53 am
by AntoninoP
Hello,
I see this behavior too!
The problem is in tlistview.prg:

Code: Select all | Expand

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: Select all | Expand

// @ 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: Select all | Expand

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

plus this DUMP:

Code: Select all | Expand

#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

Re: Problem with Listview

Posted: Wed Jun 10, 2015 9:37 am
by Silvio.Falconi
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

Re: Problem with Listview

Posted: Wed Jun 10, 2015 10:02 am
by cnavarro
Try

Code: Select all | Expand


HMODULE hDLL; // = NULL
 

Re: Problem with Listview

Posted: Wed Jun 10, 2015 2:45 pm
by Antonio Linares
The solution is to modify tlistvie.prg this way:

Code: Select all | Expand


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.

Re: Problem with Listview

Posted: Wed Jun 10, 2015 3:06 pm
by Antonio Linares
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! :-)

Re: Problem with Listview

Posted: Wed Jun 10, 2015 3:08 pm
by Antonio Linares
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: Select all | Expand

  HMODULE hDLL = NULL;
   if( pImageList_Create == NULL )
   {
      hDLL = LoadLibrary( "comctl32.dll" );
      if( hDLL )
         pImageList_Create = ( PIMAGELIST_CREATE ) GetProcAddress( hDLL, "ImageList_Create" );
   }


with this:

Code: Select all | Expand

  if( pImageList_Create == NULL )
   {
      HMODULE hDLL = LoadLibrary( "comctl32.dll" );
      if( hDLL )
         pImageList_Create = ( PIMAGELIST_CREATE ) GetProcAddress( hDLL, "ImageList_Create" );
   }

Re: Problem with Listview

Posted: Wed Jun 10, 2015 3:10 pm
by Antonio Linares
Also a FreeLibrary() call is missing in that fix.

Anyhow next FWH build will include these changes :-)

Re: Problem with Listview

Posted: Wed Jun 10, 2015 3:32 pm
by AntoninoP
Antonio Linares wrote:Also a FreeLibrary() call is missing in that fix.

Anyhow next FWH build will include these changes :-)

ops :lol:
so the final version is:

Code: Select all | Expand

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

Re: Problem with Listview

Posted: Wed Jun 10, 2015 4:15 pm
by Antonio Linares
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.

Re: Problem with Listview

Posted: Thu Jun 11, 2015 11:11 am
by Silvio.Falconi
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 ?

Re: Problem with Listview

Posted: Thu Jun 11, 2015 1:33 pm
by AntoninoP
The FWH function Icon_Read returns the HICON of the file regardless its extension.
Here a snapshot of my code:

Code: Select all | Expand

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


Regards,
Antonino

Re: Problem with Listview

Posted: Fri Jun 12, 2015 8:45 am
by Silvio.Falconi
I saw good.. I not Known this function sorry

Re: Problem with Listview

Posted: Sat Jun 13, 2015 12:06 pm
by Silvio.Falconi
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