kk_lee69 发表于 2017-9-1 09:30:01

回复 59# chzj589

可以................. 做個手腳

譬如第二 列表框的數據 請加上所謂的序號而所謂的序號其實就是第一列表框的 INDEX

kk_lee69 发表于 2017-9-1 09:37:10

回复 60# chzj589

回复 59# chzj589
刚才问题没说清楚。

能不用左键单击第二列表框条目,直接右键单击第一列表框选择高亮条目,就能删除第二列表框对应条目吗?
-----------------------------------------------------------------------

方法一   比對   第二列表框的所有內容 當 跟 第一列表框 一模一樣就刪除   缺點是如果有兩筆資料 都是 一模一樣就會出問題

方法二當一開始 將資料複製到第二列裱框的時候 就請先將資料回寫到 第一列表框   備註好 INDEX

chzj589 发表于 2017-9-1 09:42:17

回复 62# kk_lee69

谢谢解答,我试试

chzj589 发表于 2017-9-1 11:21:02

回复 62# kk_lee69
谢谢!解决了!

yamakawa 发表于 2017-9-1 11:29:27

回复 64# chzj589


    第二列表添加一个宽为0的列(列宽为0就会自动隐藏),保存第一个列表的索引。然后就好办了

yamakawa 发表于 2017-9-1 11:30:53

回复 57# kk_lee69


    搞不定。那个vb改au3的。。。奇怪。vb改状态可以,用au3就不行?

yamakawa 发表于 2017-9-1 12:18:41

本帖最后由 yamakawa 于 2017-9-1 12:26 编辑

回复 62# kk_lee69


    拼拼凑凑弄成这个样子。。我要出门下,暂时没空试。。你有空试试??#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>

Opt('GUIOnEventMode', 1)

Global $idListView, $hListView, $pListViewFunc, $idAddSingleSel, $idDelSingleSel
Global $rListView, $hrListView
Example()
While 1
        Sleep(1000)
WEnd

Func Example()
        ; Create GUI
        GUICreate("ctrl+single-click --> single-click", 820, 200)
        GUISetOnEvent(-3, '_Exit')
        ;右边再建一个listview
        $rListView = GUICtrlCreateListView("", 390, 10, 360, 180, $GUI_SS_DEFAULT_LISTVIEW - $LVS_SINGLESEL - $LVS_SHOWSELALWAYS, $WS_EX_CLIENTEDGE)
        _GUICtrlListView_SetExtendedListViewStyle($rListView, $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT)
       
        _GUICtrlListView_InsertColumn($rListView, 0, "Column 1", 75)
        _GUICtrlListView_InsertColumn($rListView, 1, "Column 2", 75)
        _GUICtrlListView_InsertColumn($rListView, 2, "Column 3", 75)
        _GUICtrlListView_InsertColumn($rListView, 3, "Column 4", 75)
        For $i = 0 To 100
                GUICtrlCreateListViewItem($i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $rListView)
        Next
        ; Create ListView
        $idListView = GUICtrlCreateListView("", 10, 10, 360, 180, $GUI_SS_DEFAULT_LISTVIEW - $LVS_SINGLESEL, $WS_EX_CLIENTEDGE)
        _GUICtrlListView_SetExtendedListViewStyle($idListView, $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT)
        $hListView = GUICtrlGetHandle($idListView)
        ; Add columns to ListView
        _GUICtrlListView_InsertColumn($idListView, 0, "Column 1", 75)
        _GUICtrlListView_InsertColumn($idListView, 1, "Column 2", 75)
        _GUICtrlListView_InsertColumn($idListView, 2, "Column 3", 75)
        _GUICtrlListView_InsertColumn($idListView, 3, "Column 4", 75)
        ; Fill ListView
        Local $iItems = 100
        For $i = 0 To $iItems - 1
                GUICtrlCreateListViewItem($i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $idListView)
        Next

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

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

        ;GUIRegisterMsg
        GUIRegisterMsg($WM_NOTIFY, "wm_notify")
        ; Show GUI
        GUISetState(@SW_SHOW)
EndFunc   ;==>Example


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

        Switch $iMsg
                Case $WM_LBUTTONDOWN;单键实现多选
                        Switch $wParam
                                Case 0x0001
                                        GUISetState($hWnd, 256)
                                        If _GUICtrlListView_GetSelectedCount($idListView) Then
                                                Local $aHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($idListView), BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
                                                If Not (@error Or $aHit = -1) Then
                                                        If _GUICtrlListView_GetItemSelected($idListView, $aHit) Then
                                                                GUICtrlSendToDummy($idDelSingleSel, $aHit)
                                                        Else
                                                                GUICtrlSendToDummy($idAddSingleSel, $aHit)
                                                        EndIf
                                                EndIf
                                                Return 0
                                        EndIf
                                Case 0x0009
                                        Return 0
                        EndSwitch
                Case $WM_SETFOCUS
             Local $i = 0
                       do
                               _GUICtrlListView_SetItemState($hWnd, $i, 0, $LVIS_DROPHILITED)
                               $i = _GUICtrlListView_GetNextItem($hWnd,$i,0,2)
                               If $i <> -1 Then _GUICtrlListView_SetItemState($hWnd, $i, 0, $LVIS_DROPHILITED)
                       Until $i = -1
                Case $WM_KILLFOCUS
                        Local $selArray = _GUICtrlListView_GetSelectedIndices($hWnd,True)
                        For $i = 1 To $selArray
                          _GUICtrlListView_SetItemSelected($hWnd, $selArray[$i], False)
                          _GUICtrlListView_SetItemState($hWnd, $selArray[$i], $LVIS_DROPHILITED, $LVIS_DROPHILITED)
            Next
        EndSwitch
       
        Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
        If Not @error Then
                Return $result
        Else
                Return
        EndIf
        #forceref $iSubclassId, $pData
EndFunc   ;==>ListViewFunc

Func _AddSingleSel()
        Local $iItem = GUICtrlRead($idAddSingleSel)
        _GUICtrlListView_SetItemSelected($idListView, $iItem, True)
        _GUICtrlListView_SetItemFocused($idListView, $iItem)
EndFunc   ;==>_AddSingleSel
Func _DelSingleSel()
        Local $iItem = GUICtrlRead($idDelSingleSel)
        _GUICtrlListView_SetItemSelected($idListView, $iItem, False)
        _GUICtrlListView_SetItemFocused($idListView, $iItem)
EndFunc   ;==>_DelSingleSel
Func _Exit()
        _WinAPI_RemoveWindowSubclass($hListView, $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 Then Return SetError(1000, 0, 0)

        Return $aRet
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
EndFunc   ;==>_WinAPI_RemoveWindowSubclass


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg, $wParam
        Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
        $hWndListView = $idListView
        If Not IsHWnd($idListView) Then $hWndListView = GUICtrlGetHandle($idListView)

        $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case $hWndListView
                        Switch $iCode
                                Case $NM_KILLFOCUS
                                       
                                Case $NM_CUSTOMDRAW
                                        $tDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                                        $iDrawStage = DllStructGetData($tDraw, "dwDrawStage")
                                        $iItemSpec = DllStructGetData($tDraw, "dwItemSpec")
                                        Switch $iDrawStage
                                                Case $CDDS_PREPAINT
                                                        Return $CDRF_NOTIFYITEMDRAW
                                                Case $CDDS_ITEMPREPAINT
;~                                                         If BitAND($iItemSpec, 1) = 1 Then
;~                                                                 DllStructSetData($tDraw, "clrTextBk", 0xff00cc)
;~                                                         Else
;~                                                                 DllStructSetData($tDraw, "clrTextBk", 0xccff00)
;~                                                         EndIf
                                                        Return $CDRF_NEWFONT
                                        EndSwitch
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
        ConsoleWrite( _
                        "!===========================================================" & @CRLF & _
                        "+======================================================" & @CRLF & _
                        "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
                        "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

yamakawa 发表于 2017-9-2 10:13:26

回复 62# kk_lee69


    今天翻到这个。。英文官网#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
;#include <APIConstants.au3>
#include <WinAPI.au3> ; from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/

Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
; ####################################
; adjustment of the icon positioning, according to windows version
Global $iAdjustV = 0
If $__WINVER > 0x0600 Then $iAdjustV = 1 ; $__WINVER defined in WinAPIEx, $__WINVER > 0x0600 means Vista+
; ####################################

; WM_MEASUREITEM allows setting the row height
Global $iListView_row_height = 50
GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created
;GUIRegisterMsg($WM_MEASUREITEM, "") ; call this after last ownerdrawn listview created
; ---------------------------------------------------

_GDIPlus_Startup()
$hGUI = GUICreate("ListView Set Item State", 700, 300)
$cButton_CheckAll = GUICtrlCreateButton("Check All", 10, 275, 100, 20)
$cButton_UncheckAll = GUICtrlCreateButton("UnCheck All", 120, 275, 100, 20)
$cButton_StatesToArray = GUICtrlCreateButton("States to Array", 230, 275, 100, 20)
; listview 1 -----------------------------------------------
$iListView_row_height = 25
$cListView = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL))
GUICtrlSetFont(-1, 11, 400, 0, "Calibri", 5)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))
$hIml_Listview = _GUIImageList_Create(16, 16, 5, 3)
$hBitmap_Icon = _Load_BMP_From_Mem(_Icon_Image_Checkbox_Unchecked(), True)
_GUIImageList_Add($hIml_Listview, $hBitmap_Icon)
_WinAPI_DeleteObject($hBitmap_Icon)
$hBitmap_Icon = _Load_BMP_From_Mem(_Icon_Image_Checkbox_Checked(), True)
_GUIImageList_Add($hIml_Listview, $hBitmap_Icon)
_WinAPI_DeleteObject($hBitmap_Icon)

; ##########################################################
; this "breaks" WM_MEASUREITEM
;_GUICtrlListView_SetImageList($hListView, $hIml_Listview, 1)
; why do we need this anyway?
; ##########################################################
; Add columns
_GUICtrlListView_AddColumn($hListView, " ", 0)
For $i = 1 To 3
    _GUICtrlListView_AddColumn($hListView, "Column " & $i, 100)
Next
Local $aItems
For $row = 1 To 30
$aItems[$row-1] = "this won't show up"
$aItems[$row-1] = "Row " & $row & ": Col 1"
$aItems[$row-1] = "Row " & $row & ": Col 2"
$aItems[$row-1] = "Row " & $row & ": Col 3"
Next
; if you add items via _GUICtrlListView_AddArray(), the drawing will become unstable.
; also, the checkboxes don't appear unless you click their respective subitem.
_GUICtrlListView_DeleteAllItems($hListView)
_GUICtrlListView_AddArray($hListView, $aItems)
; -----------------------------------------------------------

; listview 2 -----------------------------------------------
$iListView_row_height = 40
$cListView_2 = GUICtrlCreateListView("", 400, 2, 298, 268, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
GUICtrlSetFont(-1, 11, 400, 0, "Calibri", 5)
$hListView_2 = GUICtrlGetHandle($cListView_2)
_GUICtrlListView_SetExtendedListViewStyle($hListView_2, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
; Add columns
For $i = 1 To 3
    _GUICtrlListView_AddColumn($hListView_2, "2 - Column " & $i, 90)
Next
; Add items
For $row = 1 To 20
    _GUICtrlListView_AddItem($hListView_2, "Row " & $row & ": Col 0", 0)
    _GUICtrlListView_AddSubItem($hListView_2, $row - 1, "Row " & $row & ": Col 1", 1, 0)
    If $row <> 3 Then
_GUICtrlListView_AddSubItem($hListView_2, $row - 1, "Row " & $row & ": Col 2", 2, 0)
Else
; if you comment the line below and click+drag to resize this ListView's columns, the drawing will become unstable
;_GUICtrlListView_AddSubItem($hListView_2, $row - 1, "", 2, 0)
EndIf
Next
; -----------------------------------------------------------

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

; Loop until user exits
While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
            ExitLoop
      Case $cButton_CheckAll
            _LV_ImgCheckboxes_CheckAll($hListView)
      Case $cButton_UncheckAll
            _LV_ImgCheckboxes_UncheckAll($hListView)
      Case $cButton_StatesToArray
            $aLVStates = _LV_ImgCheckboxes_StatesToArray($hListView)
            _ArrayDisplay($aLVStates)
    EndSwitch
WEnd
GUIDelete()
_GUIImageList_Destroy($hIml_Listview)
_GDIPlus_Shutdown()
Exit
Func _LV_ImgCheckboxes_CheckAll($hWnd)
    _GUICtrlListView_BeginUpdate($hWnd)
    For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
      For $y = 0 To _GUICtrlListView_GetColumnCount($hWnd) - 1
            _GUICtrlListView_SetItemImage($hWnd, $i, 1, $y)
      Next
    Next
    _GUICtrlListView_EndUpdate($hWnd)
EndFunc   ;==>_LV_ImgCheckboxes_CheckAll
Func _LV_ImgCheckboxes_UncheckAll($hWnd)
    _GUICtrlListView_BeginUpdate($hWnd)
    For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
      For $y = 0 To _GUICtrlListView_GetColumnCount($hWnd) - 1
            _GUICtrlListView_SetItemImage($hWnd, $i, 0, $y)
      Next
    Next
    _GUICtrlListView_EndUpdate($hWnd)
EndFunc   ;==>_LV_ImgCheckboxes_UncheckAll
Func _LV_ImgCheckboxes_StatesToArray($hWnd)
    Local $iColumns = _GUICtrlListView_GetColumnCount($hWnd)
    If $iColumns = 0 Then Return SetError(1)
    Local $iItems = _GUICtrlListView_GetItemCount($hWnd)
    If $iItems = 0 Then Return SetError(2)
    Local $aStates[$iItems][$iColumns]
    For $i = 0 To $iItems - 1
      For $y = 0 To $iColumns - 1
            $aStates[$i][$y] = _GUICtrlListView_GetItemImage($hWnd, $i, $y)
      Next
    Next
    Return $aStates
EndFunc   ;==>_LV_ImgCheckboxes_StatesToArray
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $nNotifyCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
      Case $hListView
            Switch $nNotifyCode
                Case $NM_CLICK
                  Local $tINFO = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                  Local $iItem = DllStructGetData($tINFO, "Index")
                  Local $iSubitem = DllStructGetData($tINFO, "SubItem")
                  If $iSubitem == 2 And StringLen(_GUICtrlListView_GetItemText($hListView, $iItem, $iSubitem)) > 0 Then
      ;ConsoleWrite("painting row "&$iItem+1&"   col "&$iSubitem+1&@CRLF)
      _GUICtrlListView_SetItemImage($hListView, $iItem, Not _GUICtrlListView_GetItemImage($hListView, $iItem, $iSubitem), $iSubitem)
   EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC
$timer = TimerInit()
    $tagDRAWITEMSTRUCT = DllStructCreate( _
            "uint cType;" & _
            "uint cID;" & _
            "uint itmID;" & _
            "uint itmAction;" & _
            "uint itmState;" & _
            "hwnd hItm;" & _
            "hwnd hDC;" & _
            "int itmRect;" & _
            "dword itmData" _
            , $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    Local $aDefaultVariables = [$tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC]
    Switch $cID ; will look for ControlID, not window handle.
      Case $cListView
            Switch $itmAction
                Case $ODA_DRAWENTIRE
                  Local $aRowColors =
                  Local $aRectMargins =
                  Local $aTextFormatting = [-1, _
       BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS), _
                            BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS), _
                            BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_RIGHT, $DT_END_ELLIPSIS), _
       BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_END_ELLIPSIS)]
                  __WM_DRAWITEM_ListView($hListView, $aDefaultVariables, $aRowColors, $aRectMargins, $aTextFormatting)
    ; end case
   EndSwitch
; end case
Case $cListView_2
   Switch $itmAction
                Case $ODA_DRAWENTIRE
                  Local $aRowColors =
                  Local $aRectMargins =
                  Local $aTextFormatting = [BitOR($DT_VCENTER, $DT_SINGLELINE), _
                            BitOR($DT_VCENTER, $DT_SINGLELINE), _
                            BitOR($DT_VCENTER, $DT_SINGLELINE)]
                  __WM_DRAWITEM_ListView($hListView_2, $aDefaultVariables, $aRowColors, $aRectMargins, $aTextFormatting)
    ; end case
   EndSwitch
; end case
    EndSwitch
ConsoleWrite(Round(TimerDiff($timer),2) & @TAB & "WM_DRAWITEM" & @CRLF)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM
Func __WM_DRAWITEM_ListView($hListView, ByRef $aDefaultVariables, ByRef $aRowColors, ByRef $aRectMargins, ByRef $aTextFormatting)
    Local $iSubItemCount = _GUICtrlListView_GetColumnCount($hListView)
    If UBound($aTextFormatting) < $iSubItemCount Then
      ConsoleWrite("!> Error: invalid parameters in __WM_DRAWITEM_ListView()" & @CRLF)
      Return
    EndIf
    Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC
    $tagDRAWITEMSTRUCT = $aDefaultVariables
    $iBrushColor = $aDefaultVariables
    $cID = $aDefaultVariables
    $itmID = $aDefaultVariables
    $itmAction = $aDefaultVariables
    $itmState = $aDefaultVariables
    $hItm = $aDefaultVariables
    $hDC = $aDefaultVariables
    If _GUICtrlListView_GetItemSelected($hListView, $itmID) Then
      $iBrushColor = $aRowColors
    Else
      $iBrushColor = $aRowColors
    EndIf
    ; create a brush with the desired color:
    Local $aBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iBrushColor)
    ; get the rectangle for the whole row and fill it:
    Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
    DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 0, 1) ; +0 is the left margin
    _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush)
    ; draw the text in each subitem
    For $i = 0 To $iSubItemCount - 1
      ; get subitem text:
      Local $iSubItmText = _GUICtrlListView_GetItemText($hListView, $itmID, $i)
      ; get subitem coordinates for drawing its respective text:
      Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hListView, $itmID, $i)
      ; the function above accepts not only subitems (one-based index), but also main item (index=0)
; pass the coordinates to a DLL struct:
      Local $iSubItmRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
      DllStructSetData($iSubItmRect, 1, $aSubItmRect + $aRectMargins) ; left margin
      DllStructSetData($iSubItmRect, 2, $aSubItmRect + $aRectMargins) ; upper margin
      DllStructSetData($iSubItmRect, 3, $aSubItmRect + $aRectMargins) ; right margin
      DllStructSetData($iSubItmRect, 4, $aSubItmRect + $aRectMargins) ; bottom margin
      Local $tRect = DllStructGetPtr($iSubItmRect)
If $cID == $cListView And StringLen($iSubItmText) > 0 And $aTextFormatting[$i] <> -1 Then
   Local $hIcon = _GUIImageList_GetIcon($hIml_Listview, _GUICtrlListView_GetItemImage($hListView, $itmID, $i))
   If @error Then ConsoleWrite("error 1" & @CRLF)
   If $i = 0 Then ; the first column of a listview needs more handling than the other columns (sub-items)
    #cs
    ; positioning for the icon:
    DllStructSetData($iSubItmRect, "Left", DllStructGetData($iSubItmRect, "Left") + 12)
    _WinAPI_DrawIconEx($hDC, DllStructGetData($iSubItmRect, "Left") - 16, Int((DllStructGetData($iSubItmRect, "Bottom") + DllStructGetData($iSubItmRect, "Top") - 16)/2) + $iAdjustV, $hIcon, 16, 16)
    ; positioning for the text:
    DllStructSetData($iSubItmRect, "Left", DllStructGetData($iSubItmRect, "Left") + 4)
    #ce
   Else
    If $i == 2 Then
   _WinAPI_DrawIconEx($hDC, DllStructGetData($iSubItmRect, "Left"), Int((DllStructGetData($iSubItmRect, "Bottom") + DllStructGetData($iSubItmRect, "Top") - 16)/2) + $iAdjustV, $hIcon, 16, 16)
   ; positioning for the text:
   DllStructSetData($iSubItmRect, "Left", DllStructGetData($iSubItmRect, "Left") + 20)
    EndIf
   EndIf
   _GUIImageList_DestroyIcon($hIcon)
EndIf
      If $aTextFormatting[$i] = -1 Then
   ; do nothing (don't draw any text)
      Else
            _WinAPI_DrawText($hDC, $iSubItmText, $tRect, $aTextFormatting[$i])
      EndIf
    Next
EndFunc   ;==>__WM_DRAWITEM_ListView
Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
DllStructSetData($tMEASUREITEMS, "itmH", $iListView_row_height) ; row height
Return 1
EndFunc   ;==>WM_MEASUREITEM

; Based on File to Base64 String Code Generator
; by UEZ
; http://www.autoitscript.com/forum/topic/...ng-code-generator-v103-build-2
;======================================================================================
; Function Name:      Load_BMP_From_Mem
; Description:    Loads an image which is saved as a binary string and converts it to a bitmap or hbitmap
;
; Parameters:      $bImage:    the binary string which contains any valid image which is supported by GDI+
; Optional:    $hHBITMAP:if false a bitmap will be created, if true a hbitmap will be created
;
; Remark:            hbitmap format is used generally for GUI internal images, $bitmap is more a GDI+ image format
;                  Don't forget _GDIPlus_Startup() and _GDIPlus_Shutdown()
;
; Requirement(s):    GDIPlus.au3, Memory.au3 and _GDIPlus_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Return Value(s):    Success: handle to bitmap (GDI+ bitmap format) or hbitmap (WinAPI bitmap format),
;                  Error: 0
; Error codes:    1: $bImage is not a binary string
;                  2: unable to create stream on HGlobal
;                  3: unable to create bitmap from stream
;
; Author(s):            UEZ
; Additional Code:    thanks to progandy for the MemGlobalAlloc and tVARIANT lines and
;                  Yashied for _GDIPlus_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Version:      v0.97 Build 2012-01-04 Beta
;=======================================================================================
Func _Load_BMP_From_Mem($bImage, $hHBITMAP = False)
    If Not IsBinary($bImage) Then Return SetError(1, 0, 0)
    Local $aResult
    Local Const $memBitmap = Binary($bImage) ;load imagesaved in variable (memory) and convert it to binary
    Local Const $len = BinaryLen($memBitmap) ;get length of image
    Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory($GMEM_MOVEABLE = 0x0002)
    Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
    Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
    DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock countassociated with a memory object that was allocated with GMEM_MOVEABLE
    $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    If @error Then SetError(2, 0, 0)
    Local Const $hStream = $aResult
    $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface
    If @error Then SetError(3, 0, 0)
    Local Const $hBitmap = $aResult
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
            "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak
    $tMem = 0
    $tVARIANT = 0
    If $hHBITMAP Then
      Local Const $hHBmp = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
      _GDIPlus_BitmapDispose($hBitmap)
      Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_Load_BMP_From_Mem
Func _GDIPlus_BitmapCreateDIBFromBitmap111($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret, $Ret, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret)
    DllStructSetData($tBIHDR, 3, $Ret)
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult) Then
      DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult, 'dword', $Ret * $Ret * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
      $hResult = $hResult
    Else
      $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap
Func _Decompress_Binary_String_to_Bitmap($Base64String)
    $Base64String = Binary($Base64String)
    Local $iSize_Source = BinaryLen($Base64String)
    Local $pBuffer_Source = _WinAPI_CreateBuffer($iSize_Source)
    DllStructSetData(DllStructCreate('byte[' & $iSize_Source & ']', $pBuffer_Source), 1, $Base64String)
    Local $pBuffer_Decompress = _WinAPI_CreateBuffer(8388608)
    Local $Size_Decompressed = _WinAPI_DecompressBuffer($pBuffer_Decompress, 8388608, $pBuffer_Source, $iSize_Source)
    Local $b_Result = Binary(DllStructGetData(DllStructCreate('byte[' & $Size_Decompressed & ']', $pBuffer_Decompress), 1))
    _WinAPI_FreeMemory($pBuffer_Source)
    _WinAPI_FreeMemory($pBuffer_Decompress)
    Return $b_Result
EndFunc   ;==>_Decompress_Binary_String_to_Bitmap
Func _Icon_Image_Checkbox_Unchecked()
    Local $Base64String
    $Base64String &= '7rBIAAABABAQEAFwCAAAaAUAABYAAMwAKAAYAJAAIAAYAVwZAQBAAQIYDgCAgAAAANfc3ADZ3t4AANvg4ADe4uIAAOLl5QDl6OgAAOns7ADs7+8AAO/x8QDx8/MAAPT19QD29/cAAPj5+QD6+/sAAPz9/QD+/v7wAP///xNc/wB/AD8A/z8APwA/AD8APwA/AD8ACAAb4HYLAAEJAOEBCgsMAA0ODxAREhISbeIBCQcC4gEIBwLiAQfbBwLiAQYHAuIBBQcC4gG2BAcC4gEDBwLiAQIHAv/jAQcC5AEGAuIB7BceAOCfHgN/AG0A4QZhAA=='
    Return _Decompress_Binary_String_to_Bitmap(_Base64Decode($Base64String))
EndFunc   ;==>_Icon_Image_Checkbox_Unchecked
Func _Icon_Image_Checkbox_Checked()
    Local $Base64String
    $Base64String &= 'z7BIAAABABAQEAFwCAAAaAUAABYAAMwAKAAYAJAAIAAYAVwZAQBAAQIYDgCAgAAAAISEhADe3t5AAN7n5wDnAQbvCO8A7wEG9/cA9/EABv///xN4/wE/AD8A/z8APwA/AD8AHwAMAOB6CwAGAQkA4QEHCAkJCR4KAgDjAQcC5AEHCAKDAwLiAQYHBwICAwI54gEFBsABAwLjAQUCxgIkBOIBBAUCRQbjAVgEBQUCAuQBAwUCCPPkAQUCBwjkAQYC4gHsF3seAOCfA38AbQDhBmEA'
    Return _Decompress_Binary_String_to_Bitmap(_Base64Decode($Base64String))
EndFunc   ;==>_Icon_Image_Checkbox_Checked
Func _Base64Decode($input_string)
    Local $struct = DllStructCreate("int")
    Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call Then Return SetError(1, 0, "")
    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call Then Return SetError(2, 0, "")
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode

chzj589 发表于 2017-9-2 11:54:50

回复 55# yamakawa
55楼Copy很好,受到了启发,
Case $copy
        _GUICtrlListView_BeginUpdate($rListView)
        _GUICtrlListView_DeleteAllItems($rListView)
        For $i = 0 To 99
                If _GUICtrlListView_GetItemChecked($lListView, $i) Then GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($lListView, $i), $rListView)
        Next
        _GUICtrlListView_EndUpdate($rListView)
先清空列表2,再复制。简单又准确。谢谢

yamakawa 发表于 2017-9-2 15:24:53

回复 69# chzj589


    {:face (394):}不都是这么做的么。。

yamakawa 发表于 2017-9-2 22:37:04

回复 69# chzj589


    其实那个循环不好,,如果数据太多会卡顿。
_GUICtrlListView_GetNextItem
用这个比较好。。懒得改了

kk_lee69 发表于 2017-9-2 22:53:07

回复 71# yamakawa

有研究過 虛擬 LISTVIEW 嗎

不會有卡頓 問題

yamakawa 发表于 2017-9-2 23:10:40

回复 72# kk_lee69


    不是,我说的是上面那个代码段。。简单暴力的用for 速度会慢的{:face (303):}
虚拟列表就是看你几个帖子入门的,知道原理,只显示当前显示的,所以不管数据是多少。一次只读取界面显示的,最多几十个。所以快。。

yamakawa 发表于 2017-9-2 23:12:16

回复 72# kk_lee69


    69楼的


回复 55# yamakawa
55楼Copy很好,受到了启发,
Case $copy
      _GUICtrlListView_BeginUpdate($rListView)
      _GUICtrlListView_DeleteAllItems($rListView)
      For $i = 0 To 99
                If _GUICtrlListView_GetItemChecked($lListView, $i) Then GUICtrlCreateListViewItem(_GUICtrlListView_GetItemTextString($lListView, $i), $rListView)
      Next
      _GUICtrlListView_EndUpdate($rListView)
先清空列表2,再复制。简单又准确。谢谢

chzj589 发表于 2017-9-3 12:25:33

本帖最后由 chzj589 于 2017-9-3 12:38 编辑

回复 74# yamakawa
无聊,喜欢折腾。
先清空列表2,再复制。很好用。
但如果有三个列表都要点击条目显示在一个列表,因最后点击的列表一条出错,
现只要清除一条项目,先清空列表2,再复制,因先清空列表2,就把原有的条目全部清除了。
折腾了半天,找不到要清除的ID。
删除列表视图控件项目:
    MsgBox($MB_SYSTEMMODAL, "删除项目", "删除内置函数创建的项目 5")
    _GUICtrlListView_DeleteItem($idListview, 5)

看来只能在己输入的列表直接删除了。
页: 1 2 3 4 [5] 6
查看完整版本: 如何使用左键单点击达成LISTVIEW连续选中状态??