Tải bản đầy đủ (.pdf) (6 trang)

AutoIT Help part 57 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (19.6 KB, 6 trang )

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
Local $date, $del, $msg

GUICreate("My GUI delete control", 200, 200, 800, 200)
$date = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20)
$del = GUICtrlCreateButton("Delete control", 50, 50, 70, 20)
GUISetState()

; Run the GUI until the dialog is closed
Do
$msg = GUIGetMsg()
If $msg = $del Then
GUICtrlDelete($date)
GUICtrlDelete($del)
EndIf
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example



Function Reference
GUICtrlRegisterListViewSort
Register a user defined function for an internal listview sorting callback function.
GUICtrlRegisterListViewSort ( controlID, "function" )
Parameters


controlID The listview controlID for which the user function should proceed.
function The name of the user function to call when the sorting callback runs.

Return Value
Success:

1
Failure:

0

Remarks
!!! To make the user function workable you have to define it with maximum 4
function parameters otherwise the function won't be called !!!
i.e:
Func MySortFunction($nListViewID, $LParam1, $LParam2, $nColumn)

EndFunc

Or

Func MySortFunction($nListViewID, $LParam1, $LParam2)

EndFunc

When the user function is called then these 4 parameters have the following values:
Position

Parameter


Meaning

1 controlID
The controlID of the listview control for which the callback
function is used.
2 lParam1
The lParam value of the first item (by default the item
controlID).
3 lParam2
The lParam value of the second item (by default the item
controlID).
4 column
The column that was clicked for sorting (the first column
number is 0).

The following values have to be Returned to change the behaviour of the sorting
callback:
Return value

Meaning

-1 1st item should precede the 2nd.
0 No Change.
1 1st item should follow the 2nd.

See also examples for sorting with selfcreated GUI listview items.
Related
GUICtrlCreateListView
Example


#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

Opt('MustDeclareVars', 1)

Global $nCurCol = -1
Global $nSortDir = 1
Global $bSet = 0
Global $nCol = -1

Example1()
Example2()

; *******************************************************
; Example 1 - sorting 3 column's different
; *******************************************************
Func Example1()
Local $hGUI, $lv, $lvi1, $lvi2, $lvi3, $msg

$hGUI = GUICreate("Test", 300, 200)

$lv = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180)
GUICtrlRegisterListViewSort(-1, "LVSort") ; Register the function "SortLV"
for the sorting callback

$lvi1 = GUICtrlCreateListViewItem("ABC|666|10.05.2004", $lv)
GUICtrlSetImage(-1, "shell32.dll", 7)
$lvi2 = GUICtrlCreateListViewItem("DEF|444|11.05.2005", $lv)
GUICtrlSetImage(-1, "shell32.dll", 12)
$lvi3 = GUICtrlCreateListViewItem("CDE|444|12.05.2004", $lv)

GUICtrlSetImage(-1, "shell32.dll", 3)

GUISetState()

While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop

Case $lv
$bSet = 0
$nCurCol = $nCol
GUICtrlSendMsg($lv, $LVM_SETSELECTEDCOLUMN,
GUICtrlGetState($lv), 0)
DllCall("user32.dll", "int", "InvalidateRect", "hwnd",
GUICtrlGetHandle($lv), "int", 0, "int", 1)
EndSwitch
WEnd

GUIDelete()
EndFunc ;==>Example1

; Our sorting callback funtion
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
Local $nSort, $val1, $val2, $nResult

; Switch the sorting direction
If $nColumn = $nCurCol Then
If Not $bSet Then

$nSortDir = $nSortDir * - 1
$bSet = 1
EndIf
Else
$nSortDir = 1
EndIf
$nCol = $nColumn

$val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
$val2 = GetSubItemText($hWnd, $nItem2, $nColumn)

; If it is the 3rd colum (column starts with 0) then compare the dates
If $nColumn = 2 Then
$val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2)
$val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2)
EndIf

$nResult = 0 ; No change of item1 and item2 positions

If $val1 < $val2 Then
$nResult = -1 ; Put item2 before item1
ElseIf $val1 > $val2 Then
$nResult = 1 ; Put item2 behind item1
EndIf

$nResult = $nResult * $nSortDir

Return $nResult
EndFunc ;==>LVSort



; Retrieve the text of a listview item in a specified column
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int")
Local $nIndex, $stBuffer, $stLvi, $sItemText

DllStructSetData($stLvfi, 1, $LVFI_PARAM)
DllStructSetData($stLvfi, 3, $nItemID)

$stBuffer = DllStructCreate("char[260]")

$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1,

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×