Ticket #1690: TestLV.au3

File TestLV.au3, 1.7 KB (added by Authenticity, 14 years ago)

Example of Unicode and ASCII listviews

Line 
1#include <Misc.au3>
2#include <GUIConstantsEx.au3>
3#include <GuiListView.au3>
4#include <WindowsConstants.au3>
5
6Local $hGUI, $hLV, $iIndex
7Local $fUnicode = False
8If _Singleton("TestLV", 1) Then $fUnicode = True
9
10If $fUnicode Then
11 $hGUI = GUICreate("TestLV (Unicode)", 400, 400)
12Else
13 $hGUI = GUICreate("TestLV (ASCII)", 400, 400)
14EndIf
15$hLV = _GUICtrlListView_Create($hGUI, "Header 1|Header 2|Header 3", 10, 10, 380, 380)
16_GUICtrlListView_SetExtendedListViewStyle($hLV, $LVS_EX_FULLROWSELECT)
17_GUICtrlListView_SetUnicodeFormat($hLV, $fUnicode)
18
19_GUICtrlListView_BeginUpdate($hLV)
20 For $i = 0 To 9
21  $iIndex = _GUICtrlListView_InsertItem($hLV, "Item " & $i*3+1)
22  For $j = 1 To 2
23   _GUICtrlListView_AddSubItem($hLV, $iIndex, "Item " & $i*3+$j+1, $j)
24  Next
25 Next
26_GUICtrlListView_EndUpdate($hLV)
27GUISetState()
28GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
29
30Do
31Until GUIGetMsg() = $GUI_EVENT_CLOSE
32
33_GUICtrlListView_Destroy($hLV)
34GUIDelete()
35
36Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
37  Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
38  Local $tInfo, $iIndex
39
40  $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
41  $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
42  $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
43  $iCode = DllStructGetData($tNMHDR, "Code")
44  Switch $hWndFrom
45    Case $hLV
46      Switch $iCode
47        Case $NM_CLICK
48            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
49                    $iIndex = DllStructGetData($tInfo, "Index")
50
51            If $iIndex <> -1 Then _
52              MsgBox(0x40, "Item Text", _GUICtrlListView_GetItemText($hLV, $iIndex))
53        EndSwitch
54    EndSwitch
55    Return $GUI_RUNDEFMSG
56EndFunc