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

[效率算法] kk请进。listview麻烦看看能不能改虚拟列表写法【已解决】

  [复制链接]
 楼主| 发表于 2017-9-5 14:42:37 | 显示全部楼层
回复 15# kk_lee69


    呵呵,,明白了。我继续折腾吧。。你觉得我用的风格怪异那是因为我不用custdraw,而是完全重绘的wm_drawitem,你这样改的话,wm_drawitem不响应了
发表于 2017-9-5 14:48:26 | 显示全部楼层
回复 16# yamakawa

那就肯定要把
Case -150, -177 ;$LVN_GETDISPINFOA = -150, $LVN_GETDISPINFOW = -177   請求顯示資料
        If Not IsArray($dataArray) Then Return
        $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
        $iIndex = Int(DllStructGetData($tInfo, "Item"))
        $iSub = Int(DllStructGetData($tInfo, "SubItem"))

        DllStructSetData($tText, "Text", $dataArray[$iIndex][$iSub]);列資料放入$tText結構
        DllStructSetData($tInfo, "Text", DllStructGetPtr($tText));$tText結構的指標來設置列資料
        DllStructSetData($tInfo, "TextMax", StringLen($dataArray[$iIndex][$iSub]));設置列資料字串長

這段放在 你的 重繪的部分   是因為哪個風格  可以影響重繪的部分呢??
发表于 2017-9-5 14:51:09 | 显示全部楼层
本帖最后由 kk_lee69 于 2017-9-5 14:56 编辑

回复 16# yamakawa

找到了
你用
$lListView = GUICtrlCreateListView("Items|SubItems", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_OWNERDATA))
這樣就可以了

你的重繪一樣有作用

把我前面的範例 風格改成這樣就可以了

   虛擬 LISTVIEW 的概念是  LISTVIEW 只是皮  所以 所有的資訊 可以從 陣列來的 就直接從陣列抓取

折腾好了 完成後  記得分享一下

我看了一下  如果你寫好了 這個 理論上 那些  失去焦點變顏色的問題就不見了........
发表于 2017-9-5 14:58:48 | 显示全部楼层
回复 16# yamakawa

如果我沒想錯的話    用我的範例後  理論上  總行數 用你的方法一樣可以取到 才對
发表于 2017-9-5 15:01:48 | 显示全部楼层
回复 16# yamakawa


   另外請教一下  你把下面這段禁用了

        ;如果用這段代碼,那上面直接寫的資料會在,但是捲軸滾動太快,程式就宕機了
;~ ;========重新填充數據,
;~         For $i = 0 To _GUICtrlListView_GetColumnCount($hItm)
;~                 Local $iItmRect = DllStructCreate($tagRect)
;~                 If $i Then $iItmRect.top = $i ;這句啥意思還不理解。。。。。。怎麼想來想去好像是列索引的意思???可是這個結構中不是指的top麼??
;~                 DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hItm, 'uint', $LVM_GETSUBITEMRECT, 'wparam', $itmID, 'lparam', DllStructGetPtr($iItmRect))
;~                 $iItmRect.left = $i ? $iItmRect.left + 5 : $iItmRect.left + 10 ;首項縮進10,其他縮進5
;~                 _WinAPI_DrawText($hDC, $dataArray[$itmID][$i], $iItmRect, $DT_LEFT)
;~         Next
;~ ;============好像會導致bug,棄用

取而代之的是 哪一段呢
 楼主| 发表于 2017-9-5 17:01:53 | 显示全部楼层
刚到家,浑身臭汗。。大概试了下,改风格,然后不停闪烁。。所以去掉wm_drawitem中绘图过程,OK,不闪了。。。可是设置的效果也没了。。。OMG。无解?
 楼主| 发表于 2017-9-5 20:55:01 | 显示全部楼层
回复 20# kk_lee69


    加了两个风格。。然后可以了。。notify不用 -155那个了
#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
;全局变量定义
Global $hGUI, $lListView, $hlListView, $rListView, $hrListView
Global $btn_test
Global $dataArray[10000][2]
For $i = 0 To 10000 - 1
        $dataArray[$i][0] = "Item " & $i + 1
        $dataArray[$i][1] = "SubItem " & $i + 1
Next

$hGUI = GUICreate("Test GUI", 650, 300)
;===第一个列表
$lListView = GUICtrlCreateListView("", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED,$LVS_OWNERDATA));两个自绘属性都加上!
$hlListView = GUICtrlGetHandle(-1)
_GUICtrlListView_InsertColumn($hlListView, 1, "Item", 120)
_GUICtrlListView_InsertColumn($hlListView, 2, "SubItem", 120)
_GUICtrlListView_SetExtendedListViewStyle($hlListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($hlListView, 0, 120)
_GUICtrlListView_SetColumnWidth($hlListView, 1, 120)
_GUICtrlListView_SetItemCount($lListView, UBound($dataArray))
;第二个列表
$rListView = GUICtrlCreateListView("", 310, 10, 280, 180) 
$hrListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hrListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_InsertColumn($hrListView, 0, "隐藏列", 0)
_GUICtrlListView_InsertColumn($hrListView, 1, "列1", 120)
_GUICtrlListView_InsertColumn($hrListView, 2, "列2", 120)

$btn_test = 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 $btn_test
                        MsgBox(0, "", "do is clicked", 0, $hGUI)
        EndSwitch
WEnd

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
        Local $tagDRAWITEMSTRUCT, $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)
        $cID = $tagDRAWITEMSTRUCT.cID
        $itmID = $tagDRAWITEMSTRUCT.itmID
        $hItm = $tagDRAWITEMSTRUCT.hItm
        $hDC = $tagDRAWITEMSTRUCT.hDC
        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($hDC, $txtcolor)
        ;<=====
        ;>=========
;~         Local $tRect = DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect") ;====这个学习了。。
        Local $tRect = DllStructCreate($tagRect, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect")) ;====这样也可以。好处是可以修改
        Local $iBrushColor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xff7bcc : 0xffffff ;上色
        Local $aBrush = _WinAPI_CreateSolidBrush($iBrushColor)
        Local $aBrushOld = _WinAPI_SelectObject($hDC, $aBrush)
        _WinAPI_FillRect($hDC, $tRect, $aBrush)
        _WinAPI_SelectObject($hDC, $aBrushOld)
        _WinAPI_DeleteObject($aBrush)
        ;<=====画背景
        ;回填数据
        For $i = 0 To _GUICtrlListView_GetColumnCount($hItm) - 1
                Local $iItmRect = DllStructCreate($tagRect)
                If $i Then $iItmRect.top = $i
                DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hItm, 'uint', $LVM_GETSUBITEMRECT, 'wparam', $itmID, 'lparam', DllStructGetPtr($iItmRect))
                $iItmRect.left += $i ? 5 : 10
                _WinAPI_DrawText($hDC, $dataArray[$itmID][$i], $iItmRect, $DT_LEFT)
        Next
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

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 $rListView
                        If $iCode <> $NM_DBLCLK Then Return $GUI_RUNDEFMSG
                        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                        Local $index = DllStructGetData($tInfo, "Index")
                        If _GUICtrlListView_DeleteItem($iIDFrom, $index) Then
                                If _GUICtrlListView_GetItemCount($iIDFrom) > _GUICtrlListView_GetCounterPage($iIDFrom) Then
                                        _GUICtrlListView_SetItemSelected($hrListView, $index - 1)
                                Else
                                        _GUICtrlListView_SetItemSelected($hrListView, $index)
                                EndIf
                        EndIf
                        Return $GUI_RUNDEFMSG
                Case $lListView
                Switch $iCode
                                Case $NM_DBLCLK
                                        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                                        Local $index = DllStructGetData($tInfo, "Index")
                                        If $index = -1 Then Return $GUI_RUNDEFMSG
                                        Local $newIndex = _GUICtrlListView_FindText($hrListView, String($lListView & "," & $index))
                                        If $newIndex <> -1 Then
                                                _GUICtrlListView_DeleteItem($hrListView, $newIndex)
                                        Else
                                                $newIndex = _GUICtrlListView_AddItem($hrListView, String($lListView & "," & $index))
                                                For $i = 0 To UBound($dataArray, 2) - 1
                                                        _GUICtrlListView_AddSubItem($hrListView, $newIndex, $dataArray[$index][$i], $i + 1)
                                                Next
                                                _GUICtrlListView_EnsureVisible($hrListView, $newIndex)
                                                _GUICtrlListView_SetItemSelected($hrListView, $newIndex)
                                        EndIf
                                        Return 0
                        EndSwitch
                        Return $GUI_RUNDEFMSG
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
发表于 2017-9-5 22:37:07 | 显示全部楼层
回复 22# yamakawa

酷喔  非常流暢

可以請教 這樣子 完全自繪 的用意 跟好處是甚麼嗎??
 楼主| 发表于 2017-9-6 10:04:13 | 显示全部楼层
回复 23# kk_lee69


    和custdraw相比,这个做法的好处是,完全控制,可以修改显示过程的一切
发表于 2017-9-8 11:47:24 | 显示全部楼层
回复 24# yamakawa

這個 可以繪製 INPUT框嗎??  有辦法重新繪製 INPUT框嗎??
 楼主| 发表于 2017-9-8 22:48:52 | 显示全部楼层
回复 25# kk_lee69


    WM_DRAWITEM message
Sent to the parent window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the button, combo box, list box, or menu has changed.

好像不行
发表于 2017-9-12 16:53:41 | 显示全部楼层
回复 26# yamakawa
你22楼的例子,读取速度很快。
能修改为左键点击LISTVIEW连续选中状态,
我对自绘还不会,想要修改,不知从那里下手
 楼主| 发表于 2017-9-12 18:18:51 | 显示全部楼层
回复 27# chzj589

这个么
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
Opt('GUIOnEventMode', 1)

#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
;全局变量定义
Global $hGUI, $lListView, $hlListView, $rListView, $hrListView,$idAddSingleSel, $idDelSingleSel
Global $btn_test
Global $dataArray[10000][2]
For $i = 0 To 10000 - 1
        $dataArray[$i][0] = "Item " & $i + 1
        $dataArray[$i][1] = "SubItem " & $i + 1
Next

$hGUI = GUICreate("Test GUI", 650, 300)
        GUISetOnEvent(-3, '_Exit')

;===第一个列表
$lListView = GUICtrlCreateListView("", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_OWNERDATA)) ;两个自绘属性都加上!
$hlListView = GUICtrlGetHandle(-1)
_GUICtrlListView_InsertColumn($hlListView, 1, "Item", 120)
_GUICtrlListView_InsertColumn($hlListView, 2, "SubItem", 120)
_GUICtrlListView_SetExtendedListViewStyle($hlListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($hlListView, 0, 120)
_GUICtrlListView_SetColumnWidth($hlListView, 1, 120)
_GUICtrlListView_SetItemCount($lListView, UBound($dataArray))
;第二个列表
$rListView = GUICtrlCreateListView("", 310, 10, 280, 180)
$hrListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hrListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_InsertColumn($hrListView, 0, "隐藏列", 0)
_GUICtrlListView_InsertColumn($hrListView, 1, "列1", 120)
_GUICtrlListView_InsertColumn($hrListView, 2, "列2", 120)


        ; Subclass ListView to receive keyboard/mouse messages
        $pListViewFunc = DllCallbackGetPtr(DllCallbackRegister("ListViewFunc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))
        _WinAPI_SetWindowSubclass($hlListView, $pListViewFunc, 0, 0) ; $iSubclassId = 0, $pData = 0

        ; Add/del single selection
        $idAddSingleSel = GUICtrlCreateDummy()
        GUICtrlSetOnEvent(-1, '_AddSingleSel')
        $idDelSingleSel = GUICtrlCreateDummy()
        GUICtrlSetOnEvent(-1, '_DelSingleSel')


GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

While 1
        Switch GUIGetMsg()
                Case -3
                        Exit
        EndSwitch
WEnd


Func ListViewFunc($hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData)

        If $iMsg = $WM_LBUTTONDOWN Then

                Switch $wParam
                        Case 0x0001
                                If _GUICtrlListView_GetSelectedCount($hlListView) Then
                                        Local $aHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($lListView), BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
                                        If Not (@error Or $aHit[0] = -1) Then
                                                If _GUICtrlListView_GetItemSelected($hlListView, $aHit[0]) Then
                                                        GUICtrlSendToDummy($idDelSingleSel, $aHit[0])
                                                Else
                                                        GUICtrlSendToDummy($idAddSingleSel, $aHit[0])
                                                EndIf
                                        EndIf
                                        Return 0
                                EndIf
                        Case 0x0009
                                Return 0
                EndSwitch
        ElseIf $iMsg = $WM_KILLFOCUS Then
                ConsoleWrite("WM_KILLFOCUS" & @CRLF)
        Else
                Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
                If Not @error Then
                        Return $result[0]
                Else
                        Return
                EndIf
        EndIf
        
        
        Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
        If Not @error Then
                Return $result[0]
        Else
                Return
        EndIf
        #forceref $iSubclassId, $pData
EndFunc   ;==>ListViewFunc

Func _AddSingleSel()
        Local $iItem = GUICtrlRead($idAddSingleSel)
        _GUICtrlListView_SetItemSelected($hlListView, $iItem, True)
        _GUICtrlListView_SetItemFocused($hlListView, $iItem)
EndFunc   ;==>_AddSingleSel
Func _DelSingleSel()
        Local $iItem = GUICtrlRead($idDelSingleSel)
        _GUICtrlListView_SetItemSelected($hlListView, $iItem, False)
        _GUICtrlListView_SetItemFocused($hlListView, $iItem)
EndFunc   ;==>_DelSingleSel
Func _Exit()
        _WinAPI_RemoveWindowSubclass($hlListView, $pListViewFunc, 0)
        GUIDelete()
        Exit
EndFunc   ;==>_Exit

Func _WinAPI_SetWindowSubclass($hWnd, $pSubclassProc, $idSubClass, $pData = 0)
        Local $aRet = DllCall('comctl32.dll', 'bool', 'SetWindowSubclass', 'hwnd', $hWnd, 'ptr', $pSubclassProc, 'uint_ptr', $idSubClass, _
                        'dword_ptr', $pData)
        If @error Then Return SetError(@error, @extended, 0)
        ; If Not $aRet[0] Then Return SetError(1000, 0, 0)

        Return $aRet[0]
EndFunc   ;==>_WinAPI_SetWindowSubclass
Func _WinAPI_RemoveWindowSubclass($hWnd, $pSubclassProc, $idSubClass)
        Local $aRet = DllCall('comctl32.dll', 'bool', 'RemoveWindowSubclass', 'hwnd', $hWnd, 'ptr', $pSubclassProc, 'uint_ptr', $idSubClass)
        If @error Then Return SetError(@error, @extended, False)
        Return $aRet[0]
EndFunc   ;==>_WinAPI_RemoveWindowSubclass


Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
        Local $tagDRAWITEMSTRUCT, $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)
        $cID = $tagDRAWITEMSTRUCT.cID
        $itmID = $tagDRAWITEMSTRUCT.itmID
        $hItm = $tagDRAWITEMSTRUCT.hItm
        $hDC = $tagDRAWITEMSTRUCT.hDC
        If $tagDRAWITEMSTRUCT.cType <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
        If $tagDRAWITEMSTRUCT.itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG

        ;>=========
;~         Local $tRect = DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect") ;====这个学习了。。
        Local $tRect = DllStructCreate($tagRect, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect")) ;====这样也可以。好处是可以修改
        Local $iBrushColor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xff7bcc : 0xffffff ;上色
        Local $aBrush = _WinAPI_CreateSolidBrush($iBrushColor)
        Local $aBrushOld = _WinAPI_SelectObject($hDC, $aBrush)
        _WinAPI_FillRect($hDC, $tRect, $aBrush)
        _WinAPI_SelectObject($hDC, $aBrushOld)
        _WinAPI_DeleteObject($aBrush)
        ;<=====画背景
        ;>====设置选中项文字颜色
        $txtcolor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xffffff : 0x000000
        _WinAPI_SetTextColor($hDC, $txtcolor)
        ;<=====
        ;回填数据
        For $i = 0 To _GUICtrlListView_GetColumnCount($hItm) - 1
                Local $iItmRect = DllStructCreate($tagRect)
                If $i Then $iItmRect.top = $i
                DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hItm, 'uint', $LVM_GETSUBITEMRECT, 'wparam', $itmID, 'lparam', DllStructGetPtr($iItmRect))
                $iItmRect.left += $i ? 5 : 10
                _WinAPI_DrawText($hDC, $dataArray[$itmID][$i], $iItmRect, $DT_LEFT)
        Next
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

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 $rListView
                        If $iCode <> $NM_DBLCLK Then Return $GUI_RUNDEFMSG
                        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                        Local $index = DllStructGetData($tInfo, "Index")
                        If _GUICtrlListView_DeleteItem($iIDFrom, $index) Then
                                If _GUICtrlListView_GetItemCount($iIDFrom) > _GUICtrlListView_GetCounterPage($iIDFrom) Then
                                        _GUICtrlListView_SetItemSelected($hrListView, $index - 1)
                                Else
                                        _GUICtrlListView_SetItemSelected($hrListView, $index)
                                EndIf
                        EndIf
                        Return $GUI_RUNDEFMSG
                Case $lListView
                        Switch $iCode
                                Case $NM_DBLCLK
                                        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                                        Local $index = DllStructGetData($tInfo, "Index")
                                        If $index = -1 Then Return $GUI_RUNDEFMSG
                                        Local $newIndex = _GUICtrlListView_FindText($hrListView, String($lListView & "," & $index))
                                        If $newIndex <> -1 Then
                                                _GUICtrlListView_DeleteItem($hrListView, $newIndex)
                                        Else
                                                $newIndex = _GUICtrlListView_AddItem($hrListView, String($lListView & "," & $index))
                                                For $i = 0 To UBound($dataArray, 2) - 1
                                                        _GUICtrlListView_AddSubItem($hrListView, $newIndex, $dataArray[$index][$i], $i + 1)
                                                Next
                                                _GUICtrlListView_EnsureVisible($hrListView, $newIndex)
                                                _GUICtrlListView_SetItemSelected($hrListView, $newIndex)
                                        EndIf
                                        Return 0
                        EndSwitch
                        Return $GUI_RUNDEFMSG
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
发表于 2017-9-12 18:42:54 | 显示全部楼层
回复 28# yamakawa

是的。谢谢!
怎么没想到:
$pListViewFunc = DllCallbackGetPtr(DllCallbackRegister("ListViewFunc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))
_WinAPI_SetWindowSubclass($hlListView, $pListViewFunc, 0, 0) ; $iSubclassId = 0, $pData = 0

; Add/del single selection
$idAddSingleSel = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, '_AddSingleSel')
$idDelSingleSel = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, '_DelSingleSel')

Func ListViewFunc($hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData)

        If $iMsg = $WM_LBUTTONDOWN Then

                Switch $wParam
                        Case 0x0001
                                If _GUICtrlListView_GetSelectedCount($hlListView) Then
                                        Local $aHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($lListView), BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
                                        If Not (@error Or $aHit[0] = -1) Then
                                                If _GUICtrlListView_GetItemSelected($hlListView, $aHit[0]) Then
                                                        GUICtrlSendToDummy($idDelSingleSel, $aHit[0])
                                                Else
                                                        GUICtrlSendToDummy($idAddSingleSel, $aHit[0])
                                                EndIf
                                        EndIf
                                        Return 0
                                EndIf
                        Case 0x0009
                                Return 0
                EndSwitch
        ElseIf $iMsg = $WM_KILLFOCUS Then
                ConsoleWrite("WM_KILLFOCUS" & @CRLF)
        Else
                Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
                If Not @error Then
                        Return $result[0]
                Else
                        Return
                EndIf
        EndIf


        Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
        If Not @error Then
                Return $result[0]
        Else
                Return
        EndIf
        #forceref $iSubclassId, $pData
EndFunc   ;==>ListViewFunc

Func _AddSingleSel()
        Local $iItem = GUICtrlRead($idAddSingleSel)
        _GUICtrlListView_SetItemSelected($hlListView, $iItem, True)
        _GUICtrlListView_SetItemFocused($hlListView, $iItem)
EndFunc   ;==>_AddSingleSel
Func _DelSingleSel()
        Local $iItem = GUICtrlRead($idDelSingleSel)
        _GUICtrlListView_SetItemSelected($hlListView, $iItem, False)
        _GUICtrlListView_SetItemFocused($hlListView, $iItem)
EndFunc   ;==>_DelSingleSel
发表于 2017-9-14 09:25:49 | 显示全部楼层
回复 28# yamakawa

读取Excel显示在:$lListView = GUICtrlCreateListView("", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED,$LVS_OWNERDATA))
出现第一行空白,折腾了一天,没办法调整。怪事。

本帖子中包含更多资源

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

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-19 20:46 , Processed in 0.074371 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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