Newsgroup: it.comp.lang.visual-basic
Titolo: Domanda sulle API (per chi sa anche un po' di C++)

Ultimamente ho avuto la necessitą di utilizzare la Listview senza OCX e dopo
un po' di fatica ho capito come creare e aggiungere colonne e oggetti grazie
alla guida del C++. Quello che non so č come fare a intercettare un evento.
Mi spiego: la guida del C++ dice che quando, per esempio, faccio click su un
oggetto della listview, viene mandato il messaggio WM_NOTIFY al form (?) che
la ospita.
Come faccio a intercettare quel messaggio? Ho sbagliato qualcosa?
Qui allego un esempio di come ho fatto a creare una listview:
Const WC_LISTVIEW = "SysListView32"
Public Const ICC_LISTVIEW_CLASSES = &H1 'listview, header
Private  Declare Sub InitCommonControls Lib "comctl32.dll" ()
Private  Declare Function InitCommonControlsEx Lib "comctl32.dll" _
      (lpInitCtrls As tagINITCOMMONCONTROLSEX) As Boolean
Type tagINITCOMMONCONTROLSEX   ' icc
   dwSize As Long   ' size of this structure
   dwICC As Long    ' flags indicating which classes to be initialized.
End Type
 Const WS_VISIBLE = &H10000000
 Const WS_CHILD = &H40000000
Private  Declare Function CreateWindowEx Lib "user32" Alias
"CreateWindowExA" _
  (ByVal dwExStyle As Long, ByVal lpClassName As String, _
   ByVal lpWindowName As String, ByVal dwStyle As Long, _
   ByVal X As Long, ByVal Y As Long, _
   ByVal nWidth As Long, ByVal nHeight As Long, _
   ByVal hWndParent As Long, ByVal hMenu As Long, _
   ByVal hInstance As Long, lpParam As Any) As Long
Private  Declare Function IsWindow Lib "user32" _
  (ByVal hwnd As Long) As Long
Private  Declare Function MoveWindow Lib "user32" _
  (ByVal hwnd As Long, _
   ByVal X As Long, ByVal Y As Long, _
   ByVal nWidth As Long, ByVal nHeight As Long, _
   ByVal bRepaint As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, ByVal wMsg As Long, _
   wParam As Any, lParam As Any) As Long
Const LVCF_FMT = 1
Const LVCF_WIDTH = 2
Const LVCF_TEXT = 4
Const LVCF_SUBITEM = 8
Const LVCFMT_LEFT = 0
Const LVM_FIRST = 4096
Const LVM_SETCOLUMNA = LVM_FIRST + 26
Const LVM_INSERTCOLUMN = LVM_FIRST + 27
Const LVS_REPORT = &H1
Type LV_COLUMN
    mask As Long
    fmt As Long
    cx As Long
    pszText As String
    cchTextMax As Long
    iSubItem As Long
End Type
Type LV_ITEM
    mask As Long
    iItem As Long
    iSubItem As Long
    state As Long
    stateMask As Long
    pszText As String
    cchTextMax As Long
    iImage As Long
    lParam As Myitem
End Type
Const LVIF_TEXT = 1
Const LVIF_IMAGE = 2
Const LVIF_PARAM = 4
Const LVIF_STATE = 8
Const LVM_INSERTITEM = LVM_FIRST + 7
Dim hList As Long
Public Function InitComctl32(dwFlags As Long) As Boolean
   Dim icc As tagINITCOMMONCONTROLSEX
   On Error GoTo Err_OldVersion
   icc.dwSize = Len(icc)
   icc.dwICC = dwFlags
   InitComctl32 = InitCommonControlsEx(icc)
   Exit Function
Err_OldVersion:
   InitCommonControls
End Function
Private Sub Form_Load()
Dim r As Boolean
r = InitComctl32(ICC_LISTVIEW_CLASSES)
hList = CreateWindowEx(512, WC_LISTVIEW, vbNullString, WS_CHILD Or
WS_VISIBLE Or LVS_REPORT, 0, 0, 0, 0, hwnd, 0, App.hInstance, ByVal 0)
Form_Resize
Dim pt As LV_ITEM
pt.mask = LVIF_TEXT Or LVIF_IMAGE Or LVIF_PARAM Or LVIF_STATE
pt.state = 0
pt.stateMask = 0
pt.pszText = "Piero" '   // app. maintains text
pt.iImage = 0 '                   // image list index
pt.iItem = 0 ' iItem
pt.iSubItem = 0
pt.lParam = pItem '() 'pItem '    // item data
s = SendMessage(hList, LVM_INSERTITEM, 0, pt)
End Sub
Private Sub Form_Resize()
'If we have a progress bar, adjust it's width & height w/the form
If IsWindow(hList) Then
MoveWindow hList, 16, 16, ScaleWidth \ 15 - 32, 150, True
End If
End Sub

Ultimamente ho avuto la necessità di utilizzare la Listview senza OCX .
Quello che non so è come fare a intercettare un evento.
