找回密码
 加入
搜索
查看: 1761|回复: 7

请问GUICtrlCreateListView中怎么实现升级或降序

[复制链接]
发表于 2009-6-7 15:55:45 | 显示全部楼层 |阅读模式
本帖最后由 ddx13 于 2009-6-7 17:54 编辑

请问GUICtrlCreateListView中怎么实现升级或降序
比如我现在想要第二栏(数字栏)进行升序或是降序,请问要用什么函数,
看帮助看了半天也没有找到相应的函数,请会的朋友帮帮忙,谢谢。

如果是第一栏升序降序我知道,主要是指定某栏的不知道要怎么弄。

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$ListView1 = GUICtrlCreateListView("", 0, 0, 630, 450)
GUISetState(@SW_SHOW)
_GUICtrlListView_AddColumn($ListView1, "自动编号", 100)
_GUICtrlListView_AddColumn($ListView1, "数字", 100)
_GUICtrlListView_AddColumn($ListView1, "转换", 100)
_GUICtrlListView_AddColumn($ListView1, "备注", 100)
_GUICtrlListView_JustifyColumn($ListView1, 0, 2)
_GUICtrlListView_JustifyColumn($ListView1, 1, 2)
_GUICtrlListView_JustifyColumn($ListView1, 2, 2)
_GUICtrlListView_JustifyColumn($ListView1, 3, 2)
GUICtrlCreateListViewItem("1|5|e|", $ListView1)
GUICtrlCreateListViewItem("2|3|ee|", $ListView1)
GUICtrlCreateListViewItem("3|8|eg|", $ListView1)
GUICtrlCreateListViewItem("4|7|eg|", $ListView1)
GUICtrlCreateListViewItem("5|6|ej|", $ListView1)
GUICtrlCreateListViewItem("6|5|ek|", $ListView1)
GUICtrlCreateListViewItem("7|2|le|", $ListView1)
GUICtrlCreateListViewItem("8|1|je|", $ListView1)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
发表于 2009-6-7 17:51:17 | 显示全部楼层
本帖最后由 lynfr8 于 2009-6-7 17:55 编辑

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
$Debug_LV = False ;<<<<<<<<<+++
Global $ListView, $B_DESCENDING
_Example1()
Func _Example1()
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE);<<<<<<<<<+++
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER);<<<<<<<<<+++
GUICreate('升级或降序', 633, 454, 192, 114)
$ListView = GUICtrlCreateListView("", 10,10, 630, 450)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES);<<<<<<<<<+++
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT);<<<<<<<<<+++
_GUICtrlListView_AddColumn($ListView, "自动编号", 100)
_GUICtrlListView_AddColumn($ListView, "数字", 100)
_GUICtrlListView_AddColumn($ListView, "转换", 100)
_GUICtrlListView_AddColumn($ListView, "备注", 100)
_GUICtrlListView_JustifyColumn($ListView, 0, 2)
_GUICtrlListView_JustifyColumn($ListView, 1, 2)
_GUICtrlListView_JustifyColumn($ListView, 2, 2)
_GUICtrlListView_JustifyColumn($ListView, 3, 2)
GUICtrlCreateListViewItem("1|5|e|", $ListView)
GUICtrlCreateListViewItem("2|3|ee|", $ListView)
GUICtrlCreateListViewItem("3|8|eg|", $ListView)
GUICtrlCreateListViewItem("4|7|eg|", $ListView)
GUICtrlCreateListViewItem("5|6|ej|", $ListView)
GUICtrlCreateListViewItem("6|5|ek|", $ListView)
GUICtrlCreateListViewItem("7|2|le|", $ListView)
GUICtrlCreateListViewItem("8|1|je|", $ListView)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY");<<<<<<<<<+++
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListView)];<<<<<<<<<+++

Do;<<<<<<<<<+++
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc 

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam);<<<<<<<<<+++
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $ListView
If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $LVN_COLUMNCLICK ; A column was clicked
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
_DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
"-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
; No return value
Case $LVN_KEYDOWN ; A key has been pressed
$tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
_DebugPrint("$LVN_KEYDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @LF & _
"-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
; No return value
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
_DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
"-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
"-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
; No return value
Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
_DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
"-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
"-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
; No return value
Case $NM_KILLFOCUS ; The control has lost the input focus
_DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; No return value
Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
_DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
"-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
"-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
;Return 1 ; not to allow the default processing
Return 0 ; allow the default processing
Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
_DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
"-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
"-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
; No return value
Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
_DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; No return value
Case $NM_SETFOCUS ; The control has received the input focus
_DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; No return value
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;==>_DebugPrint
参考帮助文件_GUICtrlListView_SimpleSort修改了一下
复制的代码好像部分有点乱
如果出错就下附件吧

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +10 收起 理由
ddx13 + 10 谢谢

查看全部评分

 楼主| 发表于 2009-6-7 17:54:33 | 显示全部楼层
谢谢,我去官网找的眼都快瞎了。
发表于 2009-6-7 17:57:29 | 显示全部楼层
呵呵
帮助文件就有
楼主走了点远路了
不过也好啦
柳暗花明又一村
 楼主| 发表于 2009-6-7 18:05:23 | 显示全部楼层
晕呀,锻炼少了,多走走路锻炼一下。~_~
发表于 2009-6-7 18:10:26 | 显示全部楼层
好长的代码啊
发表于 2010-5-7 18:02:06 | 显示全部楼层
在帮助文件中我也没有找到!
发表于 2010-6-6 14:51:34 | 显示全部楼层
学习了!代码好长哟!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-6 12:19 , Processed in 0.081935 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表