找回密码
 加入
搜索
楼主: kk_lee69

[AU3基础] 如何使用左键单点击达成LISTVIEW连续选中状态??

  [复制链接]
发表于 2017-9-4 10:42:32 | 显示全部楼层
听不懂你意思

另外,这两天经常504,网站不能访问,,,,,郁闷。。因为我在国外?
发表于 2017-9-4 11:04:12 | 显示全部楼层
本帖最后由 chzj589 于 2017-9-4 11:06 编辑

回复 76# yamakawa
昨天下午论坛就不能打开,到刚才才恢复。
我的意思是:
有四个Listview列表,点击Listview1、Listview2、Listview3条目,要显示在Listview4。
己点击了Listview1、Listview2各三条,在点击Listview3列表三条时,其中有一条错误,
想在点击Listview3列表,清除己显示在Listview4列表上的条目。
用: _GUICtrlListView_DeleteAllItems($Listview4),
会把己输入的条目全部删除。
用:_GUICtrlListView_DeleteItem($idListview, 5)
输入的Listview1、Listview2、Listview3条目的序号与Listview4的序号以不一样,
不点击Listview4列表条目,如何获取序号?
怎么才能删除一条Listview4列表条目?
发表于 2017-9-4 12:22:02 | 显示全部楼层
listview创建一个列宽为0的列,保存 (复制来源列表,原index)
然后 _GUICtrlListView_FindText(listview4,string(复制来源列表,原index))就能获取索引了。。
如果这个列索引不是0 。那么得用_GUICtrlListView_FindInText
发表于 2017-9-4 13:26:59 | 显示全部楼层
回复 78# yamakawa
$Index = _GUICtrlListView_GetSelectedIndices($Listview2)
_GUICtrlListView_FindText($Listview1,string($Listview2,$Index));就能获取索引了。。
出现:

"F:\论坛案例\ListView例子资料\ListView 子项目显示到另一个列表.au3"(848,58) : 错误: 语法错误 (非法字符)
_GUICtrlListView_FindInText($Listview1,string($hListview2?
发表于 2017-9-4 14:31:41 | 显示全部楼层
本帖最后由 yamakawa 于 2017-9-4 15:58 编辑

回复 79# chzj589


    。。。晕了。老司机怎么会犯这初级毛病?

正好在玩wm_drawitem,用手头代码改下你看看效果
好像有点bug。。。。和wm_notify同时用,,,如果滚动条滚动过快会停止响应?!
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#cs
autoit.com yamakawa  
测试环境 win10 x64
autoit3 3.3.14.2
#ce
;版本判断
Local $verArray = StringSplit(@AutoItVersion,".")
If $verArray[3] < 14 Then MsgBox(4096,"来自Autoit.com -Yamakawa的提示","本段代码测试于 Autoit 3.3.14.2!" & @CRLF & @CRLF & @CRLF & "当前版本低于3.3.14.2 如果出现问题,请自行修改!")
;低于3.3.14.2则弹出提示。不兼容可能是版本问题

Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001

$hGUI = GUICreate("Test GUI", 650, 300)
;===第一个列表
$lListView = GUICtrlCreateListView("Items|SubItems", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED))
$hlListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hlListView, $LVS_EX_FULLROWSELECT)
For $i = 1 To 15
        _GUICtrlListView_AddItem($hlListView, "Item  " & $i & "   ")
        _GUICtrlListView_AddSubItem($hlListView, $i - 1, "SubItem  " & $i & "   ", 1)
Next
_GUICtrlListView_SetColumnWidth($hlListView, 0, 120)
_GUICtrlListView_SetColumnWidth($hlListView, 1, 120)
;第二个列表
$rListView = GUICtrlCreateListView("", 310, 10, 280, 180)
$hrListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hrListView, $LVS_EX_FULLROWSELECT)

_GUICtrlListView_InsertColumn($hrListView, 0, "隐藏列", 0)
_GUICtrlListView_InsertColumn($hrListView, 1, "列1", 120)
_GUICtrlListView_InsertColumn($hrListView, 2, "列2", 120)


GUICtrlCreateLabel("双击左边列表项," & @CRLF & "如果当前项在右边列表不存在,则建立" & @CRLF & "如果当前项在右边列表存在,则删除",10,200)
$do = GUICtrlCreateButton("text", 10, 250)
GUICtrlSetStyle(-1, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)) ; Set the ownerdrawn flag
GUICtrlCreateLabel("←←←←←←←这个按钮感觉如何(我指的形状)", 50, 255)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

While 1
        Switch GUIGetMsg()
                Case -3
                        Exit
                Case $do
                        MsgBox(0, "", "do is clicked", 0, $hGUI)
        EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        #forceref $hWnd, $iMsg, $iwParam
        Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo

        $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
        $iCode = DllStructGetData($tNMHDR, "Code")
        
        Switch $iIDFrom
                Case $lListView
                        Switch $iCode
                                                        Case $NM_DBLCLK
                                     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                                                                        Local $index = DllStructGetData($tInfo, "Index")
                                                                        Local $newIndex = _GUICtrlListView_FindText($rListView,String($lListView & "," & $index)) 
                                                                        If $newIndex <> -1 Then 
                                                                                _GUICtrlListView_DeleteItem ( $rListView, $newIndex )
                                                                        Else
                                                                                GUICtrlCreateListViewItem(String($lListView & "," & $index) &"|" & _GUICtrlListView_GetItemTextString($lListView, -1), $rListView)
                                                                        EndIf
                                    Return 1 ; not to allow the default processing
             ;~                     Return 0 ; allow the default processing
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam);嘿嘿。新GET的。。。
        Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected, $oldColor
        $tagDRAWITEMSTRUCT = DllStructCreate( _
                        "uint cType;" & _ 
                        "uint cID;" & _ 
                        "uint itmID;" & _ 
                        "uint itmAction;" & _ 
                        "uint itmState;" & _ 
                        "hwnd hItm;" & _ 
                        "handle hDC;" & _ 
                        "long itmRect[4];" & _ 
                        "ulong_ptr itmData" _ 
                        , $lParam)

        If $tagDRAWITEMSTRUCT.cType <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG 
        If $tagDRAWITEMSTRUCT.itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG 
        $txtcolor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xffffff : 0x000000
        _WinAPI_SetTextColor($tagDRAWITEMSTRUCT.hDC, $txtcolor)

        Local $tRect = DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect")
        $iBrushColor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xff7bcc : 0xffffff ;旧版这句可能需要修改
        Local $aBrush = _WinAPI_CreateSolidBrush($iBrushColor)
        Local $aBrushOld = _WinAPI_SelectObject($tagDRAWITEMSTRUCT.hDC, $aBrush)
        _WinAPI_FillRect($tagDRAWITEMSTRUCT.hDC, $tRect, $aBrush)
        _WinAPI_SelectObject($tagDRAWITEMSTRUCT.hDC, $aBrushOld)
        _WinAPI_DeleteObject($aBrush)

        For $i = 0 To _GUICtrlListView_GetColumnCount($tagDRAWITEMSTRUCT.hItm)
                Local $iItmText = _GUICtrlListView_GetItemText($tagDRAWITEMSTRUCT.hItm, $tagDRAWITEMSTRUCT.itmID, $i)
                Local $iItmRect = DllStructCreate($tagRect)
                If $i Then $iItmRect.top = $i ;这句啥意思还不理解。。。。。。怎么想来想去好像是列索引的意思???可是这个结构中不是指的top么??
                DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $tagDRAWITEMSTRUCT.hItm, 'uint', $LVM_GETSUBITEMRECT, 'wparam', $tagDRAWITEMSTRUCT.itmID, 'lparam', DllStructGetPtr($iItmRect))
                $iItmRect.left = $i ? $iItmRect.left + 5 : $iItmRect.left + 10 ;首项缩进10,其他缩进5
                Local $iItmText = _GUICtrlListView_GetItemText($tagDRAWITEMSTRUCT.hItm, $tagDRAWITEMSTRUCT.itmID, $i)
                _WinAPI_DrawText($tagDRAWITEMSTRUCT.hDC, $iItmText, $iItmRect, $DT_LEFT)
        Next
        
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM
发表于 2017-9-5 11:35:54 | 显示全部楼层
回复 80# yamakawa

效果很棒,谢谢!解决问题。
唉,当年考驾照没认真学习科目1与科目2,现在上路老是被扣分.(开玩笑)
基础没学好,这是实话.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 01:23 , Processed in 0.068014 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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