Modifications on TListView
Posted: Mon Jun 15, 2015 10:52 am
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:
with
to allow transparent ListView.
In this case You must call:
or create it with LVS_EX_TRANSPARENTBKGND extended style. (It is a good idea)
2) Added method SetView:
with this code in c:
where view can be:
3) Added method GetSelection
with this code in c:
(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:
5) added this method to change text color:
Here my ListView:
PS: note the Explorer Theme
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 )
Code: Select all
::PaintBack( ::hDC )
In this case You must call:
Code: Select all
::oView:SendMsg(/*LVM_SETEXTENDEDLISTVIEWSTYLE*/0x1000+54, /*LVS_EX_TRANSPARENTBKGND*/0x00400000,/*LVS_EX_TRANSPARENTBKGND*/0x00400000)
2) Added method SetView:
Code: Select all
METHOD SetView(iView) INLINE LVSetView(::hWnd, iView )
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));
}
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
Code: Select all
METHOD GetSelection() INLINE LVGetSelection(::hWnd, iView )
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++;
}
}
}
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;
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));
}
PS: note the Explorer Theme