本帖最后由 blue_dvd 于 2012-11-25 21:24 编辑
看下面代码#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Const $width = 280, $height = 320
$Form1 = GUICreate("Test", $width, $height, (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2)
$Listview = GUICtrlCreateListView('Column 1|Column 2|Column 3', 7, 60, 266, 161, BitOR($LVS_SINGLESEL, $LVS_REPORT))
$hListView = GUICtrlGetHandle($Listview)
_GUICtrlListView_SetExtendedListViewStyle($hListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_BORDERSELECT, $LVS_EX_FULLROWSELECT))
For $col = 0 To 2
; Set Text-Centered format for all three columns
_GUICtrlListView_JustifyColumn($hListview, $col, 2)
Next
For $row = 0 To 9
_GUICtrlListView_AddItem($hListview, $row) ; 1st column
_GUICtrlListView_AddSubItem($hListview, $row, 'x_' & $row, 1) ; 2nd column
_GUICtrlListView_AddSubItem($hListview, $row, 'y_' & $row, 2) ; 3rd column
Next
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState(@SW_SHOW)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; http://msdn.microsoft.com/en-us/library/windows/desktop/bb775583(v=vs.85).aspx
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iCode
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam) ; $tagNMHDR - Contains information about a notification message
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when user clicks an item with left mouse button
$aHit = _GUICtrlListView_SubItemHitTest($hListView)
MsgBox(0, "", "Item " & $aHit[0] & " is selected") ; Item index is zero based
EndSwitch
EndSwitch
EndFunc
帮忙解释下Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iCode
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam) ; $tagNMHDR - Contains information about a notification message
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK
$aHit = _GUICtrlListView_SubItemHitTest($hListView)
MsgBox(0, "", "Item " & $aHit[0] & " is selected") ; Item index is zero based
EndSwitch
EndSwitch
EndFunc
都没有声明怎么就可以赋值呢?Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK
$aHit = _GUICtrlListView_SubItemHitTest($hListView)
这些变量时什么意思?恳请写过的老师解释下!万分感谢! |