找回密码
 加入
搜索
楼主: 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那个了
  1. #include <GuiConstantsEx.au3>
  2. #include <WindowsConstants.au3>
  3. #include <GuiListView.au3>
  4. #include <WinAPI.au3>
  5. #include <ButtonConstants.au3>
  6. #cs
  7.         autoit.com yamakawa
  8.         测试环境 win10 x64
  9.         autoit3 3.3.14.2
  10. #ce
  11. ;版本判断
  12. Local $verArray = StringSplit(@AutoItVersion, ".")
  13. If $verArray[3] < 14 Then MsgBox(4096, "来自Autoit.com -Yamakawa的提示", "本段代码测试于 Autoit 3.3.14.2!" & @CRLF & @CRLF & @CRLF & "当前版本低于3.3.14.2 如果出现问题,请自行修改!")
  14. ;低于3.3.14.2则弹出提示。不兼容可能是版本问题


  15. ;常量定义区
  16. Global Const $ODT_LISTVIEW = 102
  17. Global Const $ODA_DRAWENTIRE = 0x1
  18. Global Const $ODA_SELECT = 0x2
  19. Global Const $ODA_FOCUS = 0x4
  20. Global Const $ODS_SELECTED = 0x0001
  21. ;全局变量定义
  22. Global $hGUI, $lListView, $hlListView, $rListView, $hrListView
  23. Global $btn_test
  24. Global $dataArray[10000][2]
  25. For $i = 0 To 10000 - 1
  26.         $dataArray[$i][0] = "Item " & $i + 1
  27.         $dataArray[$i][1] = "SubItem " & $i + 1
  28. Next

  29. $hGUI = GUICreate("Test GUI", 650, 300)
  30. ;===第一个列表
  31. $lListView = GUICtrlCreateListView("", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED,$LVS_OWNERDATA));两个自绘属性都加上!
  32. $hlListView = GUICtrlGetHandle(-1)
  33. _GUICtrlListView_InsertColumn($hlListView, 1, "Item", 120)
  34. _GUICtrlListView_InsertColumn($hlListView, 2, "SubItem", 120)
  35. _GUICtrlListView_SetExtendedListViewStyle($hlListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
  36. _GUICtrlListView_SetColumnWidth($hlListView, 0, 120)
  37. _GUICtrlListView_SetColumnWidth($hlListView, 1, 120)
  38. _GUICtrlListView_SetItemCount($lListView, UBound($dataArray))
  39. ;第二个列表
  40. $rListView = GUICtrlCreateListView("", 310, 10, 280, 180)
  41. $hrListView = GUICtrlGetHandle(-1)
  42. _GUICtrlListView_SetExtendedListViewStyle($hrListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
  43. _GUICtrlListView_InsertColumn($hrListView, 0, "隐藏列", 0)
  44. _GUICtrlListView_InsertColumn($hrListView, 1, "列1", 120)
  45. _GUICtrlListView_InsertColumn($hrListView, 2, "列2", 120)

  46. $btn_test = GUICtrlCreateButton("text", 10, 250)
  47. GUICtrlSetStyle(-1, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)) ; Set the ownerdrawn flag
  48. GUICtrlCreateLabel("←←←←←←←这个按钮感觉如何(我指的形状)", 50, 255)

  49. GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
  50. GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
  51. GUISetState()

  52. While 1
  53.         Switch GUIGetMsg()
  54.                 Case -3
  55.                         Exit
  56.                 Case $btn_test
  57.                         MsgBox(0, "", "do is clicked", 0, $hGUI)
  58.         EndSwitch
  59. WEnd

  60. Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
  61.         Local $tagDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected, $oldColor
  62.         $tagDRAWITEMSTRUCT = DllStructCreate( _
  63.                         "uint cType;" & _
  64.                         "uint cID;" & _
  65.                         "uint itmID;" & _
  66.                         "uint itmAction;" & _
  67.                         "uint itmState;" & _
  68.                         "hwnd hItm;" & _
  69.                         "handle hDC;" & _
  70.                         "long itmRect[4];" & _
  71.                         "ulong_ptr itmData" _
  72.                         , $lParam)
  73.         $cID = $tagDRAWITEMSTRUCT.cID
  74.         $itmID = $tagDRAWITEMSTRUCT.itmID
  75.         $hItm = $tagDRAWITEMSTRUCT.hItm
  76.         $hDC = $tagDRAWITEMSTRUCT.hDC
  77.         If $tagDRAWITEMSTRUCT.cType <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
  78.         If $tagDRAWITEMSTRUCT.itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG
  79.         ;>====设置选中项文字颜色
  80.         $txtcolor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xffffff : 0x000000
  81.         _WinAPI_SetTextColor($hDC, $txtcolor)
  82.         ;<=====
  83.         ;>=========
  84. ;~         Local $tRect = DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect") ;====这个学习了。。
  85.         Local $tRect = DllStructCreate($tagRect, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect")) ;====这样也可以。好处是可以修改
  86.         Local $iBrushColor = BitAND($tagDRAWITEMSTRUCT.itmState, $ODS_SELECTED) = $ODS_SELECTED ? 0xff7bcc : 0xffffff ;上色
  87.         Local $aBrush = _WinAPI_CreateSolidBrush($iBrushColor)
  88.         Local $aBrushOld = _WinAPI_SelectObject($hDC, $aBrush)
  89.         _WinAPI_FillRect($hDC, $tRect, $aBrush)
  90.         _WinAPI_SelectObject($hDC, $aBrushOld)
  91.         _WinAPI_DeleteObject($aBrush)
  92.         ;<=====画背景
  93.         ;回填数据
  94.         For $i = 0 To _GUICtrlListView_GetColumnCount($hItm) - 1
  95.                 Local $iItmRect = DllStructCreate($tagRect)
  96.                 If $i Then $iItmRect.top = $i
  97.                 DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hItm, 'uint', $LVM_GETSUBITEMRECT, 'wparam', $itmID, 'lparam', DllStructGetPtr($iItmRect))
  98.                 $iItmRect.left += $i ? 5 : 10
  99.                 _WinAPI_DrawText($hDC, $dataArray[$itmID][$i], $iItmRect, $DT_LEFT)
  100.         Next
  101.         Return $GUI_RUNDEFMSG
  102. EndFunc   ;==>WM_DRAWITEM

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

  106.         $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
  107.         $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  108.         $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
  109.         $iCode = DllStructGetData($tNMHDR, "Code")
  110.        
  111.         Switch $iIDFrom
  112.                 Case $rListView
  113.                         If $iCode <> $NM_DBLCLK Then Return $GUI_RUNDEFMSG
  114.                         $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
  115.                         Local $index = DllStructGetData($tInfo, "Index")
  116.                         If _GUICtrlListView_DeleteItem($iIDFrom, $index) Then
  117.                                 If _GUICtrlListView_GetItemCount($iIDFrom) > _GUICtrlListView_GetCounterPage($iIDFrom) Then
  118.                                         _GUICtrlListView_SetItemSelected($hrListView, $index - 1)
  119.                                 Else
  120.                                         _GUICtrlListView_SetItemSelected($hrListView, $index)
  121.                                 EndIf
  122.                         EndIf
  123.                         Return $GUI_RUNDEFMSG
  124.                 Case $lListView
  125.                 Switch $iCode
  126.                                 Case $NM_DBLCLK
  127.                                         $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
  128.                                         Local $index = DllStructGetData($tInfo, "Index")
  129.                                         If $index = -1 Then Return $GUI_RUNDEFMSG
  130.                                         Local $newIndex = _GUICtrlListView_FindText($hrListView, String($lListView & "," & $index))
  131.                                         If $newIndex <> -1 Then
  132.                                                 _GUICtrlListView_DeleteItem($hrListView, $newIndex)
  133.                                         Else
  134.                                                 $newIndex = _GUICtrlListView_AddItem($hrListView, String($lListView & "," & $index))
  135.                                                 For $i = 0 To UBound($dataArray, 2) - 1
  136.                                                         _GUICtrlListView_AddSubItem($hrListView, $newIndex, $dataArray[$index][$i], $i + 1)
  137.                                                 Next
  138.                                                 _GUICtrlListView_EnsureVisible($hrListView, $newIndex)
  139.                                                 _GUICtrlListView_SetItemSelected($hrListView, $newIndex)
  140.                                         EndIf
  141.                                         Return 0
  142.                         EndSwitch
  143.                         Return $GUI_RUNDEFMSG
  144.         EndSwitch
  145.         Return $GUI_RUNDEFMSG
  146. 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

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

  7. #cs
  8.         autoit.com yamakawa
  9.         测试环境 win10 x64
  10.         autoit3 3.3.14.2
  11. #ce
  12. ;版本判断
  13. Local $verArray = StringSplit(@AutoItVersion, ".")
  14. If $verArray[3] < 14 Then MsgBox(4096, "来自Autoit.com -Yamakawa的提示", "本段代码测试于 Autoit 3.3.14.2!" & @CRLF & @CRLF & @CRLF & "当前版本低于3.3.14.2 如果出现问题,请自行修改!")
  15. ;低于3.3.14.2则弹出提示。不兼容可能是版本问题


  16. ;常量定义区
  17. Global Const $ODT_LISTVIEW = 102
  18. Global Const $ODA_DRAWENTIRE = 0x1
  19. Global Const $ODA_SELECT = 0x2
  20. Global Const $ODA_FOCUS = 0x4
  21. Global Const $ODS_SELECTED = 0x0001
  22. ;全局变量定义
  23. Global $hGUI, $lListView, $hlListView, $rListView, $hrListView,$idAddSingleSel, $idDelSingleSel
  24. Global $btn_test
  25. Global $dataArray[10000][2]
  26. For $i = 0 To 10000 - 1
  27.         $dataArray[$i][0] = "Item " & $i + 1
  28.         $dataArray[$i][1] = "SubItem " & $i + 1
  29. Next

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

  32. ;===第一个列表
  33. $lListView = GUICtrlCreateListView("", 10, 10, 280, 180, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_OWNERDATA)) ;两个自绘属性都加上!
  34. $hlListView = GUICtrlGetHandle(-1)
  35. _GUICtrlListView_InsertColumn($hlListView, 1, "Item", 120)
  36. _GUICtrlListView_InsertColumn($hlListView, 2, "SubItem", 120)
  37. _GUICtrlListView_SetExtendedListViewStyle($hlListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
  38. _GUICtrlListView_SetColumnWidth($hlListView, 0, 120)
  39. _GUICtrlListView_SetColumnWidth($hlListView, 1, 120)
  40. _GUICtrlListView_SetItemCount($lListView, UBound($dataArray))
  41. ;第二个列表
  42. $rListView = GUICtrlCreateListView("", 310, 10, 280, 180)
  43. $hrListView = GUICtrlGetHandle(-1)
  44. _GUICtrlListView_SetExtendedListViewStyle($hrListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
  45. _GUICtrlListView_InsertColumn($hrListView, 0, "隐藏列", 0)
  46. _GUICtrlListView_InsertColumn($hrListView, 1, "列1", 120)
  47. _GUICtrlListView_InsertColumn($hrListView, 2, "列2", 120)


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

  51.         ; Add/del single selection
  52.         $idAddSingleSel = GUICtrlCreateDummy()
  53.         GUICtrlSetOnEvent(-1, '_AddSingleSel')
  54.         $idDelSingleSel = GUICtrlCreateDummy()
  55.         GUICtrlSetOnEvent(-1, '_DelSingleSel')


  56. GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
  57. GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
  58. GUISetState()

  59. While 1
  60.         Switch GUIGetMsg()
  61.                 Case -3
  62.                         Exit
  63.         EndSwitch
  64. WEnd


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

  66.         If $iMsg = $WM_LBUTTONDOWN Then

  67.                 Switch $wParam
  68.                         Case 0x0001
  69.                                 If _GUICtrlListView_GetSelectedCount($hlListView) Then
  70.                                         Local $aHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($lListView), BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
  71.                                         If Not (@error Or $aHit[0] = -1) Then
  72.                                                 If _GUICtrlListView_GetItemSelected($hlListView, $aHit[0]) Then
  73.                                                         GUICtrlSendToDummy($idDelSingleSel, $aHit[0])
  74.                                                 Else
  75.                                                         GUICtrlSendToDummy($idAddSingleSel, $aHit[0])
  76.                                                 EndIf
  77.                                         EndIf
  78.                                         Return 0
  79.                                 EndIf
  80.                         Case 0x0009
  81.                                 Return 0
  82.                 EndSwitch
  83.         ElseIf $iMsg = $WM_KILLFOCUS Then
  84.                 ConsoleWrite("WM_KILLFOCUS" & @CRLF)
  85.         Else
  86.                 Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
  87.                 If Not @error Then
  88.                         Return $result[0]
  89.                 Else
  90.                         Return
  91.                 EndIf
  92.         EndIf
  93.        
  94.        
  95.         Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
  96.         If Not @error Then
  97.                 Return $result[0]
  98.         Else
  99.                 Return
  100.         EndIf
  101.         #forceref $iSubclassId, $pData
  102. EndFunc   ;==>ListViewFunc

  103. Func _AddSingleSel()
  104.         Local $iItem = GUICtrlRead($idAddSingleSel)
  105.         _GUICtrlListView_SetItemSelected($hlListView, $iItem, True)
  106.         _GUICtrlListView_SetItemFocused($hlListView, $iItem)
  107. EndFunc   ;==>_AddSingleSel
  108. Func _DelSingleSel()
  109.         Local $iItem = GUICtrlRead($idDelSingleSel)
  110.         _GUICtrlListView_SetItemSelected($hlListView, $iItem, False)
  111.         _GUICtrlListView_SetItemFocused($hlListView, $iItem)
  112. EndFunc   ;==>_DelSingleSel
  113. Func _Exit()
  114.         _WinAPI_RemoveWindowSubclass($hlListView, $pListViewFunc, 0)
  115.         GUIDelete()
  116.         Exit
  117. EndFunc   ;==>_Exit

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

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


  130. Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
  131.         Local $tagDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected, $oldColor
  132.         $tagDRAWITEMSTRUCT = DllStructCreate( _
  133.                         "uint cType;" & _
  134.                         "uint cID;" & _
  135.                         "uint itmID;" & _
  136.                         "uint itmAction;" & _
  137.                         "uint itmState;" & _
  138.                         "hwnd hItm;" & _
  139.                         "handle hDC;" & _
  140.                         "long itmRect[4];" & _
  141.                         "ulong_ptr itmData" _
  142.                         , $lParam)
  143.         $cID = $tagDRAWITEMSTRUCT.cID
  144.         $itmID = $tagDRAWITEMSTRUCT.itmID
  145.         $hItm = $tagDRAWITEMSTRUCT.hItm
  146.         $hDC = $tagDRAWITEMSTRUCT.hDC
  147.         If $tagDRAWITEMSTRUCT.cType <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
  148.         If $tagDRAWITEMSTRUCT.itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG

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

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

  176.         $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
  177.         $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  178.         $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
  179.         $iCode = DllStructGetData($tNMHDR, "Code")
  180.        
  181.         Switch $iIDFrom
  182.                 Case $rListView
  183.                         If $iCode <> $NM_DBLCLK Then Return $GUI_RUNDEFMSG
  184.                         $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
  185.                         Local $index = DllStructGetData($tInfo, "Index")
  186.                         If _GUICtrlListView_DeleteItem($iIDFrom, $index) Then
  187.                                 If _GUICtrlListView_GetItemCount($iIDFrom) > _GUICtrlListView_GetCounterPage($iIDFrom) Then
  188.                                         _GUICtrlListView_SetItemSelected($hrListView, $index - 1)
  189.                                 Else
  190.                                         _GUICtrlListView_SetItemSelected($hrListView, $index)
  191.                                 EndIf
  192.                         EndIf
  193.                         Return $GUI_RUNDEFMSG
  194.                 Case $lListView
  195.                         Switch $iCode
  196.                                 Case $NM_DBLCLK
  197.                                         $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
  198.                                         Local $index = DllStructGetData($tInfo, "Index")
  199.                                         If $index = -1 Then Return $GUI_RUNDEFMSG
  200.                                         Local $newIndex = _GUICtrlListView_FindText($hrListView, String($lListView & "," & $index))
  201.                                         If $newIndex <> -1 Then
  202.                                                 _GUICtrlListView_DeleteItem($hrListView, $newIndex)
  203.                                         Else
  204.                                                 $newIndex = _GUICtrlListView_AddItem($hrListView, String($lListView & "," & $index))
  205.                                                 For $i = 0 To UBound($dataArray, 2) - 1
  206.                                                         _GUICtrlListView_AddSubItem($hrListView, $newIndex, $dataArray[$index][$i], $i + 1)
  207.                                                 Next
  208.                                                 _GUICtrlListView_EnsureVisible($hrListView, $newIndex)
  209.                                                 _GUICtrlListView_SetItemSelected($hrListView, $newIndex)
  210.                                         EndIf
  211.                                         Return 0
  212.                         EndSwitch
  213.                         Return $GUI_RUNDEFMSG
  214.         EndSwitch
  215.         Return $GUI_RUNDEFMSG
  216. EndFunc   ;==>WM_NOTIFY
复制代码
发表于 2017-9-12 18:42:54 | 显示全部楼层
回复 28# yamakawa

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

  3. ; Add/del single selection
  4. $idAddSingleSel = GUICtrlCreateDummy()
  5. GUICtrlSetOnEvent(-1, '_AddSingleSel')
  6. $idDelSingleSel = GUICtrlCreateDummy()
  7. GUICtrlSetOnEvent(-1, '_DelSingleSel')

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

  9.         If $iMsg = $WM_LBUTTONDOWN Then

  10.                 Switch $wParam
  11.                         Case 0x0001
  12.                                 If _GUICtrlListView_GetSelectedCount($hlListView) Then
  13.                                         Local $aHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($lListView), BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
  14.                                         If Not (@error Or $aHit[0] = -1) Then
  15.                                                 If _GUICtrlListView_GetItemSelected($hlListView, $aHit[0]) Then
  16.                                                         GUICtrlSendToDummy($idDelSingleSel, $aHit[0])
  17.                                                 Else
  18.                                                         GUICtrlSendToDummy($idAddSingleSel, $aHit[0])
  19.                                                 EndIf
  20.                                         EndIf
  21.                                         Return 0
  22.                                 EndIf
  23.                         Case 0x0009
  24.                                 Return 0
  25.                 EndSwitch
  26.         ElseIf $iMsg = $WM_KILLFOCUS Then
  27.                 ConsoleWrite("WM_KILLFOCUS" & @CRLF)
  28.         Else
  29.                 Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
  30.                 If Not @error Then
  31.                         Return $result[0]
  32.                 Else
  33.                         Return
  34.                 EndIf
  35.         EndIf


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

  44. Func _AddSingleSel()
  45.         Local $iItem = GUICtrlRead($idAddSingleSel)
  46.         _GUICtrlListView_SetItemSelected($hlListView, $iItem, True)
  47.         _GUICtrlListView_SetItemFocused($hlListView, $iItem)
  48. EndFunc   ;==>_AddSingleSel
  49. Func _DelSingleSel()
  50.         Local $iItem = GUICtrlRead($idDelSingleSel)
  51.         _GUICtrlListView_SetItemSelected($hlListView, $iItem, False)
  52.         _GUICtrlListView_SetItemFocused($hlListView, $iItem)
  53. 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, 2026-9-21 23:16 , Processed in 0.069886 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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