Modifications on TListView

Post Reply
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Modifications on TListView

Post by AntoninoP »

Hello,
In my version of FW I made some modification that I think can be useful to others too.
1) In METHOD Paint() CLASS TListView I substituted:

Code: Select all

FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
with

Code: Select all

::PaintBack( ::hDC )
to allow transparent ListView.
In this case You must call:

Code: Select all

::oView:SendMsg(/*LVM_SETEXTENDEDLISTVIEWSTYLE*/0x1000+54, /*LVS_EX_TRANSPARENTBKGND*/0x00400000,/*LVS_EX_TRANSPARENTBKGND*/0x00400000)
or create it with LVS_EX_TRANSPARENTBKGND extended style. (It is a good idea)
2) Added method SetView:

Code: Select all

METHOD SetView(iView) INLINE LVSetView(::hWnd, iView )
with this code in c:

Code: Select all

HB_FUNC( LVSETVIEW )
{
     #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else   
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif   
   DWORD nView = ( DWORD ) hb_parnl( 2 );
   hb_retnl( ListView_SetView(hWnd, nView));
}
where view can be:

Code: Select all

#define LV_VIEW_ICON            0x0000
#define LV_VIEW_DETAILS         0x0001
#define LV_VIEW_SMALLICON       0x0002
#define LV_VIEW_LIST            0x0003
#define LV_VIEW_TILE            0x0004
3) Added method GetSelection

Code: Select all

METHOD GetSelection() INLINE LVGetSelection(::hWnd, iView )
with this code in c:

Code: Select all

HB_FUNC( LVGETSELECTION )
{
     #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else   
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif   
   UINT nItem = ListView_GetItemCount(hWnd);
   UINT nSel = ListView_GetSelectedCount(hWnd);
   UINT i,j=0;
   char bBuffer[ 250 ];
   for(i=0;i<nItem;i++)
   {
      bBuffer[i] = ( ListView_GetItemState(hWnd, (int)i, LVIS_SELECTED) == LVIS_SELECTED)? '1' : '0';
   }
   hb_reta( nSel );
   for(i=0;i<nItem;i++)
   {
      if( bBuffer[i] == '1')
      {
         hb_storvni( i+1, -1, j+1 ); 
         j++; 
      }
   }
}
(If I call ListView_GetItemState between hb_reta and hb_storvni it does not work... I don't know why, maybe someone can light me)
4) Set the group collapsible, it should be an option on the method InsertGroup.
I changed LVINSERTGROUP with this code:

Code: Select all

   grp.mask = LVGF_HEADER | LVGF_GROUPID | LVGF_FOOTER |LVGF_STATE;
   grp.state = LVGS_COLLAPSIBLE;
   grp.stateMask = LVGS_COLLAPSIBLE;
 
5) added this method to change text color:

Code: Select all

HB_FUNC( LVSETTEXTCOLOR  )
{
     #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else   
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif   
   COLORREF clrText = ( COLORREF ) hb_parnl( 2 );
   hb_retnl( ListView_SetTextColor(hWnd, clrText));
}
Here my ListView:
Image
PS: note the Explorer Theme :)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Modifications on TListView

Post by Antonio Linares »

Antonino,

Many thanks, it looks great :-)

We will include it in FWH after FWH 15.05 build 4
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply