找回密码
 加入
搜索
查看: 2216|回复: 4

[AU3基础] 再问,如何监控ListView中某项是否发生改变?

  [复制链接]
发表于 2013-2-22 16:07:32 | 显示全部楼层 |阅读模式
http://www.autoitx.com/forum.php ... ;highlight=ListView
就是想问这个帖子里的问题,不过论坛大大说的太精华了,我完全不明白怎么回事啊。
谁能给详细解释下,这里多谢了。
发表于 2013-2-22 18:28:56 | 显示全部楼层
ListView示例中有啊就是消息处理 点ListView查看调试输出
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

$Debug_LV = False ; 检查传递给 ListView 函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作

Global $hListView

_Main()

Func _Main()

        Local $GUI, $hImage
        $GUI = GUICreate("(UDF Created) ListView Create", 400, 300)

        $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
        GUISetState()

        GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

        ; 加载图像
        $hImage = _GUIImageList_Create()
        _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
        _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
        _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
        _GUICtrlListView_SetImageList($hListView, $hImage, 1)

        ; 添加列
        _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
        _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
        _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

        ; 添加项目
        _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
        _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
        _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
        _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
        _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
        _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

        ; 循环直到用户退出
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>_Main

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

        $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_ITEMCHANGED ; An item has changed
                                         $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                                         _DebugPrint("$LVN_ITEMCHANGED" & @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"))
                        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
 楼主| 发表于 2013-2-27 14:49:24 | 显示全部楼层
本人愚钝,真心不懂,能不能请大家解释稍稍详细些。
发表于 2013-2-27 15:07:15 | 显示全部楼层
项目改变,会产生WM_NOTIFY通知
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774845(v=vs.85).aspx
如果是自身窗口,用2楼的方法就可以直接捕获
如果是第三方进程,必须注入或全局HOOK处理
发表于 2013-2-27 18:21:27 | 显示全部楼层
好复杂,不懂也
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-20 03:27 , Processed in 0.076511 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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