PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Jean-Pierre LEROY on June 30, 2005, 01:17:04 AM

Title: How to block the width of column in a ListView
Post by: Jean-Pierre LEROY on June 30, 2005, 01:17:04 AM
Hi,

I don't want the user of my application to be able to change the width of column in a ListView.

How can I do that ?

Thank you for your help.
Jean-Pierre LEROY.
Title: How to block the width of column in a ListView
Post by: TechSupport on July 04, 2005, 02:35:36 PM
I did a search in POFFS and came up with the following from Edwin. Basically, you need to subclass the Header control of the ListView.



'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                        hWndForm As Dword, _  ' handle of Form
                        ByVal UserData As Long _  'optional user defined Long value
                        ) As Long

FF_ListView_DeleteAllItems HWND_FORM1_LISTVIEW1
 
FF_ListView_InsertColumn HWND_FORM1_LISTVIEW1, 0, "Column1", 0, 100
FF_ListView_InsertColumn HWND_FORM1_LISTVIEW1, 1, "Column2", 0, 100
FF_ListView_InsertColumn HWND_FORM1_LISTVIEW1, 2, "Column3", %LVCFMT_RIGHT, 100
 
 
For row& = 0 To 10
  For col& = 0 To 2
      FF_ListView_InsertItem HWND_FORM1_LISTVIEW1, row&, col&, Str$(row&) & Str$(col&), 0, 0
  Next
Next
                                           
                                           
'Subclass the Header control of the ListView
   Local hwndHeader As Dword
   hwndHeader = SendMessage( HWND_FORM1_LISTVIEW1, %LVM_GETHEADER, 0, 0)
   SetWindowLong hwndHeader, %GWL_USERDATA, GetWindowLong( hwndHeader, %GWL_WNDPROC )
   SetWindowLong hwndHeader, %GWL_WNDPROC, CodePtr( LVHeader_Callback )

End Function


Function LVHeader_Callback( ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long ) As Long

   Dim pPrevProc   As Long
   Dim R           As Rect
   Dim HDHT        As HDHITTESTINFO
   Static hCursor  As Long

   pPrevProc = GetWindowLong( hWnd, %GWL_USERDATA )

   Select Case wMsg
   Case %WM_NCHITTEST

       GetWindowRect hWnd, R

       HDHT.pt.x = LoWrd( lParam ) - R.nLeft
       HDHT.pt.y = HiWrd( lParam ) - R.nTop

       SendMessage hWnd, %HDM_HITTEST, 0, VarPtr( HDHT )

       If ( HDHT.flags And %HHT_ONDIVIDER ) Then

           Function = %HTTRANSPARENT
           Exit Function

       ElseIf( HDHT.flags And %HHT_ONDIVOPEN ) Then

           Function = %HTTRANSPARENT
           Exit Function

       ElseIf( HDHT.flags And %HHT_ONHEADER ) Then

           hCursor = GetCursor()

       End If

   Case %WM_SETCURSOR

       If hCursor Then

           SetCursor hCursor
           Function = 1
           Exit Function

       End If

   Case %WM_DESTROY, %WM_NCDESTROY

       hCursor = 0

   End Select

   If pPrevProc Then
       Function = CallWindowProc( pPrevProc, hWnd, wMsg, wParam, lParam )
   End If

End Function