Newsgroup: it.comp.lang.visual-basic
Titolo: VB.NET - WndProc di una Listview

Salve a tutti, ho trovato il seguente codice:
Inherits System.Windows.Forms.ListView
...
Private Const WM_HSCROLL As Integer = &H114
Private Const WM_VSCROLL As Integer = &H115
Protected Overrides Sub WndProc(ByRef msg As Message)
    ' Look for the WM_VSCROLL or the WM_HSCROLL messages.
    If ((msg.Msg = WM_VSCROLL) Or (msg.Msg = WM_HSCROLL)) Then
        ' Move focus to the ListView to cause ComboBox to lose focus.
        Me.Focus()
    End If
End If
    ' Pass message to default handler.
    MyBase.WndProc(msg)
End Sub
con il quale č possibile sapere quando viene fatto lo scroll orizzontare e
verticale.
Come faccio a sapere quando viene fatto il resize di una colonna ?
ma in generale esiste da qualche parte l'elenco delle costanti che č
possibile intercettare ?
grazie

L'informazione ti arriva attraverso il messaggio WM_NOTIFY,ecco un esempio:
Option Strict On
Imports System.Runtime.InteropServices
Public Class ListViewEx
  Inherits System.Windows.Forms.ListView
  ' Constants passed to the Scroll event
  Public Enum ScrollDirection
    Horizontal = 0
    Vertical
  End Enum
  ' Window messages we need to intercept
  Private Enum WindowMessages As Integer
    WM_HSCROLL = &H114
    WM_NOTIFY = &H4E
    WM_VSCROLL = &H115
  End Enum
  ' Notification messages for WM_NOTIFY
  Private Enum HeaderNotifications As Integer
    HDN_FIRST = -300&
    HDN_BEGINTRACK = (HDN_FIRST - 26)       ' Begin Column resize
    HDN_ENDTRACK = (HDN_FIRST - 27)         ' End Column resize
    HDN_DIVIDERDBLCLICK = (HDN_FIRST - 25)  ' Double-click on divider
    HDN_ITEMCHANGING = (HDN_FIRST - 20)     ' Column resizing
  End Enum
  ' Structure to hold extra information for WM_NOTIFY messages
  <StructLayout(LayoutKind.Sequential)> Private Structure NMHDR
    Friend hWndFrom As Integer
    Friend idfrom As Integer
    Friend code As Integer
  End Structure
  Protected mblnAllowColumnResize As Boolean = True
  Public Event ColumnsResized(ByVal sender As Object)
  Public Event Scroll(ByVal sender As Object, _
                      ByVal Direction As ScrollDirection)
  '***********************************************************************
  ' Public Sub New()
  ' Description: Class constructor
  '***********************************************************************
  Public Sub New()
    MyBase.New()
  End Sub
  '***********************************************************************
  ' Protected Overridable Sub OnColumnHeaderResized()
  ' Description: Performs actions and raises events when a ListView
  '              column is resized.
  '***********************************************************************
  Protected Overridable Sub OnColumnHeaderResized()
    RaiseEvent ColumnsResized(Me)
  End Sub
  '***********************************************************************
  ' Protected Overridable Sub OnScroll(ByVal Direction As
ScrollDirection)
  ' Description: Performs actions and raises events when the ListView
is
  '              scrolled.
  '***********************************************************************
  Protected Overridable Sub OnScroll(ByVal Direction As
ScrollDirection)
    RaiseEvent Scroll(Me, Direction)
  End Sub
  '***********************************************************************
  ' Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
  ' Description: Handles Windows messages
  '***********************************************************************
  Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
    ' Execute parent WndProc.  While we're subclassing anyway, we'll
    ' encapsulate it in a Try block so that we can catch that annoying
    ' NullReferenceException that gets thrown occasionally during a
    ' LabelEdit.  NOTE: This may only be necessary in Beta 2.
    Try
      MyBase.WndProc(m)
    Catch
      Exit Sub
    End Try
    Select Case m.Msg
      ' Catch scroll messages and fire the Scroll event
      Case WindowMessages.WM_HSCROLL :
OnScroll(ScrollDirection.Horizontal)
      Case WindowMessages.WM_VSCROLL :
OnScroll(ScrollDirection.Vertical)
      ' Information about Column resizing comes throught WM_NOTIFY
      Case WindowMessages.WM_NOTIFY
        ' Read in the NMHDR structure from LParam
        With CType(m.GetLParam(GetType(NMHDR)), NMHDR)
          ' See what kind of notification we're dealing with...
          Select Case .code
            ' The user is starting to drag-resize -- abort if not
allowed
            Case HeaderNotifications.HDN_BEGINTRACK
              If mblnAllowColumnResize = False Then m.Result = New
IntPtr(1)
            ' A header is being resized -- fire the event, or abort
            Case HeaderNotifications.HDN_ITEMCHANGING
              Select Case mblnAllowColumnResize
                Case True : OnColumnHeaderResized() ' Fire the event
                Case False : m.Result = New IntPtr(1) ' Abort
              End Select
          End Select
        End With
    End Select
  End Sub
  '*********************************************************************
  ' Public Property AllowColumnResize() As Boolean
  ' Description: Returns/sets a value which determines whether
ListView
  '              columns can be resized, either manually or in code.
  ' NOTE: Setting this property to False prevents resizing Columns
using
  '       their Width property as well as manually.
  '*********************************************************************
  Public Property AllowColumnResize() As Boolean
    Get
      Return mblnAllowColumnResize
    End Get
    Set(ByVal Value As Boolean)
      mblnAllowColumnResize = Value
    End Set
  End Property
End Class
HTH
-- 
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - 
http://www.ugidotnet.org