[已解决]用_GUICtrlListView_AddArray将数组写入Listview不成功
本帖最后由 smooth 于 2022-4-1 20:26 编辑用_GUICtrlListView_AddArray将数组写入Listview不成功,且也不报错。我故意的写成_GUICtrlListView_AddArray($hMyGuiList, "a|b|c|d|e"),也不给出任何的错误提示,在它的下一行,Tooltip输出正常。
我将相应的功能模块拿出去单独测试,_GUICtrlListView_AddArray($hMyGuiList, "a|b|c|d|e")会报错, _GUICtrlListView_AddArray($hMyGuiList, $aArrayList)能正常的写入Listview。
由于在脚本里,它不报任何错误就直接跳过,导致无法检查导致不能将数组写入Listview的原因。不知道有没有大佬遇到过这种奇怪的问题,麻烦指点一二。代码很长,如有必要,我再上传上来。
Global $aArrayList = [["状态", $iDateCalc], ["序列号", StringStripWS($aArray, 8)], ["持有者", $aArray], ["指纹", StringStripWS(StringLower($aArray), 8)], ["有效期", "从 " & $aYear & "-" & $raMons & "-" & $aDays & " " & $aTime & " 至 " & $bYear & "-" & $rbMons & "-" & $bDays & " " & $bTime]]
;~ _GUICtrlListView_AddArray($hMyGuiList, $aArrayList)
_GUICtrlListView_AddArray($hMyGuiList, "a|b|c|d|e")
ToolTip($aYear & "-" & $raMons & "-" & $aDays & " " & $aTime & " 至 " & $bYear & "-" & $rbMons & "-" & $bDays & " " & $bTime, 1200, 500)
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Create GUI
GUICreate("ListView Add Array (v" & @AutoItVersion & ")", 400, 300)
Local $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState(@SW_SHOW)
; Set ANSI format
;~ _GUICtrlListView_SetUnicodeFormat($idListview, False)
; Add columns
_GUICtrlListView_AddColumn($idListview, "Items", 100)
_GUICtrlListView_AddColumn($idListview, "SubItems 1", 100)
_GUICtrlListView_AddColumn($idListview, "SubItems 2", 100)
_GUICtrlListView_AddColumn($idListview, "SubItems 3", 100)
_GUICtrlListView_SetItemCount($idListview, 5000)
; One column load
Local $aItems
For $iI = 0 To UBound($aItems) - 1
$aItems[$iI] = "Item " & $iI
Next
Local $hTimer = TimerInit()
_GUICtrlListView_AddArray($idListview, $aItems)
MsgBox($MB_SYSTEMMODAL, "Information", "Load time: " & TimerDiff($hTimer) / 1000 & " seconds")
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($idListview)) ; items added with UDF function can be deleted using UDF function
_GUICtrlListView_DeleteAllItems($idListview) ; items added with UDF function can be deleted using UDF function
; Four column load
Local $aItems
For $iI = 0 To UBound($aItems) - 1
$aItems[$iI] = "Item " & $iI
$aItems[$iI] = "Item " & $iI & "-1"
$aItems[$iI] = "Item " & $iI & "-2"
$aItems[$iI] = "Item " & $iI & "-3"
Next
Local $hTimer2 = TimerInit()
_GUICtrlListView_AddArray($idListview, $aItems)
MsgBox($MB_SYSTEMMODAL, "Information", "Load time: " & TimerDiff($hTimer2) / 1000 & " seconds")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
haijie1223 发表于 2022-4-1 10:44
发哥,这不就是帮助里面的例子么,没有什么特别,我看了很多遍。建立一个数组,然后写入。
我数组没有问题,单独拿出来都可以正常的写入,在脚本里,就不正常。不正常就不正常吧,报个错也好查找原因。可是啥也没有,直接跳到下一行。
帮助文件多学习
_GUICtrlListView_AddArray
从数组向列表视图控件添加项目.
#include <GuiListView.au3>
_GUICtrlListView_AddArray ( $hWnd, ByRef $aItems )
参 数
$hWnd 控件 ID 或句柄.
$aItems 如下格式数组:
- 项目 1 文本.
- 项目 1 子项 1 文本.
- 项目 1 子项 2 文本.
- 项目 1 子项 n 文本.
- 项目 2 文本.
- 项目 2 子项 1 文本.
- 项目 2 子项 2 文本.
- 项目 2 子项 n 文本.
chzj589 发表于 2022-4-1 11:15
帮助文件多学习
_GUICtrlListView_AddArray
从数组向列表视图控件添加项目.
_GUICtrlListView_AddArray($hMyGuiList, "a|b|c|d|e")
"a|b|c|d|e",不是数组 不会是脚本被意外注释了吧,仔细检查检查,或用 ctrl-t 整理代码看看 本帖最后由 smooth 于 2022-4-1 11:34 编辑
afan 发表于 2022-4-1 11:22
不会是脚本被意外注释了吧,仔细检查检查,或用 ctrl-t 整理代码看看
代码整理我一直有做的,没有错误。
先不说写入数组了,我加个表头,都没用。单独测试一切正常。
Global $hMyGuiList = GUICtrlCreateListView("", 10, 238, 400, 136, "", BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetBkColor(-1, 0xFFFBF0)
_GUICtrlListView_AddColumn($hMyGuiList, "值", 60)
_GUICtrlListView_AddColumn($hMyGuiList, "域", 300)
chzj589 发表于 2022-4-1 11:17
_GUICtrlListView_AddArray($hMyGuiList, "a|b|c|d|e")
"a|b|c|d|e",不是数组
那是我故意写错,看它报不报错的。就是没有报错。 smooth 发表于 2022-4-1 11:32
代码整理我一直有做的,没有错误。
先不说写入数组了,我加个表头,都没用。单独测试一切正常。
用精简代码的方式查错,逐步剔除代码,直到代码正常 smooth 发表于 2022-4-1 11:34
那是我故意写错,看它报不报错的。就是没有报错。
本帖最后由 smooth 于 2022-4-7 15:49 编辑
afan 发表于 2022-4-1 11:55
用精简代码的方式查错,逐步剔除代码,直到代码正常
以下代码有问题,做精简的时候只顾着看窗口有没有弹出来,没顾上看下面的报错信息。现在问题已经解决了,也懒得再改了它了。
#NoTrayIcon
#RequireAdmin
Opt("GUIOnEventMode", 1) ;开启事件模式
Opt("GUICloseOnESC", 0) ;关闭“按ESC”退出脚本的功能
Opt("WinTitleMatchMode", 2) ;匹配窗口标题的模式调整为“按子字符串”来匹配
Opt("WinDetectHiddenText", 1) ;指定让隐藏的窗口文本也能被窗口匹配函数检测.
;设置列表视图属性
Global Const $tagLVITEM = "struct;uint Mask;int Item;int SubItem;uint State;uint StateMask;ptr Text;int TextMax;int Image;lparam Param;" & "int Indent;int GroupID;uint Columns;ptr pColumns;ptr piColFmt;int iGroup;endstruct"
Global Const $LVM_FIRST = 0x1000
Global Const $LVM_GETUNICODEFORMAT = 0x2000 + 6
Global $__g_tListViewBuffer, $__g_tListViewBufferANSI ; = DllStructCreate()
Global Const $LVM_INSERTITEMW = ($LVM_FIRST + 77)
Global Const $LVM_SETITEMW = ($LVM_FIRST + 76)
Global $__g_tListViewItem = DllStructCreate($tagLVITEM)
Global Const $LVIF_TEXT = 0x00000001
Global Const $LVM_GETITEMCOUNT = ($LVM_FIRST + 4)
Global Const $__LISTVIEWCONSTANT_WM_SETREDRAW = 0x000B
Global Const $UBOUND_COLUMNS = 2
Global Const $LVM_SETEXTENDEDLISTVIEWSTYLE = ($LVM_FIRST + 54)
Global Const $LVS_REPORT = 0x0001 ; This style specifies report view
Global Const $LVS_EX_GRIDLINES = 0x00000001
Global Const $LVS_EX_FULLROWSELECT = 0x00000020
Global Const $LVS_EX_DOUBLEBUFFER = 0x00010000
Global Const $LVM_GETHEADER = ($LVM_FIRST + 31)
Global Const $LVCFMT_LEFT = 0x0000
Global Const $LVCFMT_RIGHT = 0x0001
Global Const $LVCFMT_CENTER = 0x0002
Global Const $LVM_INSERTCOLUMNW = ($LVM_FIRST + 97)
Global Const $tagLVCOLUMN = "uint Mask;int Fmt;int CX;ptr Text;int TextMax;int SubItem;int Image;int Order;int cxMin;int cxDefault;int cxIdeal"
Global Const $LVCF_FMT = 0x0001
Global Const $LVCF_WIDTH = 0x0002
Global Const $LVCF_TEXT = 0x0004
Global $hGui = GUICreate("V2.9", 420, 416)
Global $hMyGuiList = GUICtrlCreateListView("", 10, 238, 400, 136, "", BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($hMyGuiList, "值", 60)
_GUICtrlListView_AddColumn($hMyGuiList, "域", 300)
GUISetState()
GUISetOnEvent(-3, "_Exit")
_Key_GuiSetData()
While 1 ;主循环
Sleep(10)
WEnd
Func _Key_GuiSetData()
Global $aArrayList = [["状态", "$iDateCalc"], ["序列号", "StringStripWS($aArray, 8)"], ["持有者", "$aArray"], ["指纹", "StringStripWS(StringLower($aArray), 8)"], ["有效期", "从 至 "]]
_GUICtrlListView_AddArray($hMyGuiList, $aArrayList)
EndFunc ;==>_Key_GuiSetData
Func _Exit()
Exit
EndFunc ;==>WM_SYSCOMMAND
;以下为引用的自定义函数
;==============================================================================================================================================================================================
;
Func _SendMessage($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lresult")
Local $aCall = DllCall("user32.dll", $sReturnType, "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, $wParamType, $wParam, $lParamType, $lParam)
If @error Then Return SetError(@error, @extended, "")
If $iReturn >= 0 And $iReturn <= 4 Then Return $aCall[$iReturn]
Return $aCall
EndFunc ;==>_SendMessage
Func __GUICtrl_SendMsg($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement)
If $iElement > 0 Then
DllStructSetData($tItem, $iElement, DllStructGetPtr($tBuffer))
If $iElement = $iElementMax Then DllStructSetData($tItem, $iElement + 1, DllStructGetSize($tBuffer))
EndIf
Local $iRet
If IsHWnd($hWnd) Then
If _WinAPI_InProcess($hWnd, $__g_hGUICtrl_LastWnd) Then
$iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "struct*", $tItem)
Else
Local $iItem = DllStructGetSize($tItem)
Local $tMemMap, $pText
Local $iBuffer = 0
If ($iElement > 0) Or ($iElementMax = 0) Then $iBuffer = DllStructGetSize($tBuffer)
Local $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap)
If $iBuffer Then
$pText = $pMemory + $iItem
If $iElementMax Then
DllStructSetData($tItem, $iElement, $pText)
Else
$iIndex = $pText
EndIf
_MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
EndIf
_MemWrite($tMemMap, $tItem, $pMemory, $iItem)
$iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "ptr", $pMemory)
If $iBuffer And $bRetBuffer Then _MemRead($tMemMap, $pText, $tBuffer, $iBuffer)
If $bRetItem Then _MemRead($tMemMap, $pMemory, $tItem, $iItem)
_MemFree($tMemMap)
EndIf
Else
$iRet = GUICtrlSendMsg($hWnd, $iMsg, $iIndex, DllStructGetPtr($tItem))
EndIf
Return $iRet
EndFunc ;==>__GUICtrl_SendMsg
;================================================================================================================================================================================================================================================
;================================================================================================================================================================================================================================================
;比较两个日期(具体到时间)大小的函数
;================================================================================================================================================================================================================================================
;================================================================================================================================================================================================================================================
;
Func _DateDiff($sType, $sStartDate, $sEndDate)
$sType = StringLeft($sType, 1)
If StringInStr("d,m,y,w,h,n,s", $sType) = 0 Or $sType = "" Then
Return SetError(1, 0, 0)
EndIf
If Not _DateIsValid($sStartDate) Then
Return SetError(2, 0, 0)
EndIf
If Not _DateIsValid($sEndDate) Then
Return SetError(3, 0, 0)
EndIf
Local $asStartDatePart, $asStartTimePart, $asEndDatePart, $asEndTimePart
_DateTimeSplit($sStartDate, $asStartDatePart, $asStartTimePart)
_DateTimeSplit($sEndDate, $asEndDatePart, $asEndTimePart)
Local $aDaysDiff = _DateToDayValue($asEndDatePart, $asEndDatePart, $asEndDatePart) - _DateToDayValue($asStartDatePart, $asStartDatePart, $asStartDatePart)
Local $iTimeDiff, $iYearDiff, $iStartTimeInSecs, $iEndTimeInSecs
If $asStartTimePart > 1 And $asEndTimePart > 1 Then
$iStartTimeInSecs = $asStartTimePart * 3600 + $asStartTimePart * 60 + $asStartTimePart
$iEndTimeInSecs = $asEndTimePart * 3600 + $asEndTimePart * 60 + $asEndTimePart
$iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
If $iTimeDiff < 0 Then
$aDaysDiff = $aDaysDiff - 1
$iTimeDiff = $iTimeDiff + 24 * 60 * 60
EndIf
Else
$iTimeDiff = 0
EndIf
Select
Case $sType = "d"
Return $aDaysDiff
Case $sType = "m"
$iYearDiff = $asEndDatePart - $asStartDatePart
Local $iMonthDiff = $asEndDatePart - $asStartDatePart + $iYearDiff * 12
If $asEndDatePart < $asStartDatePart Then $iMonthDiff = $iMonthDiff - 1
$iStartTimeInSecs = $asStartTimePart * 3600 + $asStartTimePart * 60 + $asStartTimePart
$iEndTimeInSecs = $asEndTimePart * 3600 + $asEndTimePart * 60 + $asEndTimePart
$iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
If $asEndDatePart = $asStartDatePart And $iTimeDiff < 0 Then $iMonthDiff = $iMonthDiff - 1
Return $iMonthDiff
Case $sType = "y"
$iYearDiff = $asEndDatePart - $asStartDatePart
If $asEndDatePart < $asStartDatePart Then $iYearDiff = $iYearDiff - 1
If $asEndDatePart = $asStartDatePart And $asEndDatePart < $asStartDatePart Then $iYearDiff = $iYearDiff - 1
$iStartTimeInSecs = $asStartTimePart * 3600 + $asStartTimePart * 60 + $asStartTimePart
$iEndTimeInSecs = $asEndTimePart * 3600 + $asEndTimePart * 60 + $asEndTimePart
$iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
If $asEndDatePart = $asStartDatePart And $asEndDatePart = $asStartDatePart And $iTimeDiff < 0 Then $iYearDiff = $iYearDiff - 1
Return $iYearDiff
Case $sType = "w"
Return Int($aDaysDiff / 7)
Case $sType = "h"
Return $aDaysDiff * 24 + Int($iTimeDiff / 3600)
Case $sType = "n"
Return $aDaysDiff * 24 * 60 + Int($iTimeDiff / 60)
Case $sType = "s"
Return $aDaysDiff * 24 * 60 * 60 + $iTimeDiff
EndSelect
EndFunc ;==>_DateDiff
Func _DateIsLeapYear($iYear)
If StringIsInt($iYear) Then
Select
Case Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0
Return 1
Case Mod($iYear, 400) = 0
Return 1
Case Else
Return 0
EndSelect
EndIf
Return SetError(1, 0, 0)
EndFunc ;==>_DateIsLeapYear
Func _DateIsValid($sDate)
Local $asDatePart, $asTimePart
_DateTimeSplit($sDate, $asDatePart, $asTimePart)
If Not StringIsInt($asDatePart) Then Return 0
If Not StringIsInt($asDatePart) Then Return 0
If Not StringIsInt($asDatePart) Then Return 0
$asDatePart = Int($asDatePart)
$asDatePart = Int($asDatePart)
$asDatePart = Int($asDatePart)
Local $iNumDays = _DaysInMonth($asDatePart)
If $asDatePart < 1000 Or $asDatePart > 2999 Then Return 0
If $asDatePart < 1 Or $asDatePart > 12 Then Return 0
If $asDatePart < 1 Or $asDatePart > $iNumDays[$asDatePart] Then Return 0
If $asTimePart < 1 Then Return 1
If $asTimePart < 2 Then Return 0
If $asTimePart = 2 Then $asTimePart = "00"
If Not StringIsInt($asTimePart) Then Return 0
If Not StringIsInt($asTimePart) Then Return 0
If Not StringIsInt($asTimePart) Then Return 0
$asTimePart = Int($asTimePart)
$asTimePart = Int($asTimePart)
$asTimePart = Int($asTimePart)
If $asTimePart < 0 Or $asTimePart > 23 Then Return 0
If $asTimePart < 0 Or $asTimePart > 59 Then Return 0
If $asTimePart < 0 Or $asTimePart > 59 Then Return 0
Return 1
EndFunc ;==>_DateIsValid
Func _DateTimeSplit($sDate, ByRef $aDatePart, ByRef $iTimePart)
Local $sDateTime = StringSplit($sDate, " T")
If $sDateTime > 0 Then $aDatePart = StringSplit($sDateTime, "/-.")
If $sDateTime > 1 Then
$iTimePart = StringSplit($sDateTime, ":")
If UBound($iTimePart) < 4 Then ReDim $iTimePart
Else
Dim $iTimePart
EndIf
If UBound($aDatePart) < 4 Then ReDim $aDatePart
For $x = 1 To 3
If StringIsInt($aDatePart[$x]) Then
$aDatePart[$x] = Int($aDatePart[$x])
Else
$aDatePart[$x] = -1
EndIf
If StringIsInt($iTimePart[$x]) Then
$iTimePart[$x] = Int($iTimePart[$x])
Else
$iTimePart[$x] = 0
EndIf
Next
Return 1
EndFunc ;==>_DateTimeSplit
Func _DateToDayValue($iYear, $iMonth, $iDay)
If Not _DateIsValid(StringFormat("%04d/%02d/%02d", $iYear, $iMonth, $iDay)) Then
Return SetError(1, 0, "")
EndIf
If $iMonth < 3 Then
$iMonth = $iMonth + 12
$iYear = $iYear - 1
EndIf
Local $i_FactorA = Int($iYear / 100)
Local $i_FactorB = Int($i_FactorA / 4)
Local $i_FactorC = 2 - $i_FactorA + $i_FactorB
Local $i_FactorE = Int(1461 * ($iYear + 4716) / 4)
Local $i_FactorF = Int(153 * ($iMonth + 1) / 5)
Local $iJulianDate = $i_FactorC + $iDay + $i_FactorE + $i_FactorF - 1524.5
Return $iJulianDate
EndFunc ;==>_DateToDayValue
Func _NowCalc()
Return @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC
EndFunc ;==>_NowCalc
Func _DaysInMonth($iYear)
Local $aDays =
Return $aDays
EndFunc ;==>_DaysInMonth
Local $iDateCalc = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc())
;
;
;================================================================================================================================================================================================================================================
;================================================================================================================================================================================================================================================
;设置列表视图Listview属性
;================================================================================================================================================================================================================================================
;================================================================================================================================================================================================================================================
;
Func _GUICtrlListView_AddArray($hWnd, ByRef $aItems)
Local $tBuffer, $iMsg, $iMsgSet
If _GUICtrlListView_GetUnicodeFormat($hWnd) Then
$tBuffer = $__g_tListViewBuffer
$iMsg = $LVM_INSERTITEMW
$iMsgSet = $LVM_SETITEMW
Else
$tBuffer = $__g_tListViewBufferANSI
$iMsg = $LVM_INSERTITEMA
$iMsgSet = $LVM_SETITEMA
EndIf
Local $tItem = $__g_tListViewItem
DllStructSetData($tItem, "Mask", $LVIF_TEXT)
Local $iLastItem = _GUICtrlListView_GetItemCount($hWnd)
_GUICtrlListView_BeginUpdate($hWnd)
; little less optimal in term of performance due to call thru $pSendMsg
Local $pSendMsg = __GUICtrl_SendMsg_Init($hWnd, $iMsg, 0, $tItem, $tBuffer, False, 6)
For $iI = 0 To UBound($aItems) - 1
DllStructSetData($tItem, "Item", $iI + $iLastItem)
DllStructSetData($tItem, "SubItem", 0)
DllStructSetData($tBuffer, 1, $aItems[$iI])
$pSendMsg($hWnd, $iMsg, 0, $tItem, $tBuffer, False, 6)
For $iJ = 1 To UBound($aItems, $UBOUND_COLUMNS) - 1
DllStructSetData($tItem, "SubItem", $iJ)
DllStructSetData($tBuffer, 1, $aItems[$iI][$iJ])
$pSendMsg($hWnd, $iMsgSet, 0, $tItem, $tBuffer, False, 6)
Next
Next
_GUICtrlListView_EndUpdate($hWnd)
EndFunc ;==>_GUICtrlListView_AddArray
Func _GUICtrlListView_GetUnicodeFormat($hWnd)
If IsHWnd($hWnd) Then
Return _SendMessage($hWnd, $LVM_GETUNICODEFORMAT) <> 0
Else
Return GUICtrlSendMsg($hWnd, $LVM_GETUNICODEFORMAT, 0, 0) <> 0
EndIf
EndFunc ;==>_GUICtrlListView_GetUnicodeFormat
Func _GUICtrlListView_GetItemCount($hWnd)
If IsHWnd($hWnd) Then
Return _SendMessage($hWnd, $LVM_GETITEMCOUNT)
Else
Return GUICtrlSendMsg($hWnd, $LVM_GETITEMCOUNT, 0, 0)
EndIf
EndFunc ;==>_GUICtrlListView_GetItemCount
Func _GUICtrlListView_BeginUpdate($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
Return _SendMessage($hWnd, $__LISTVIEWCONSTANT_WM_SETREDRAW, False) = 0
EndFunc ;==>_GUICtrlListView_BeginUpdate
Func _GUICtrlListView_EndUpdate($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
Return _SendMessage($hWnd, $__LISTVIEWCONSTANT_WM_SETREDRAW, True) = 0
EndFunc ;==>_GUICtrlListView_EndUpdate
Func __GUICtrl_SendMsg_Init($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement)
#forceref $iMsg, $iIndex, $bRetItem, $bRetBuffer
DllStructSetData($tItem, $iElement, DllStructGetPtr($tBuffer))
If $iElement = $iElementMax Then DllStructSetData($tItem, $iElement + 1, DllStructGetSize($tBuffer))
Local $pFunc
If IsHWnd($hWnd) Then
If _WinAPI_InProcess($hWnd, $__g_hGUICtrl_LastWnd) Then
$pFunc = __GUICtrl_SendMsg_InProcess
SetExtended(1)
Else
$pFunc = __GUICtrl_SendMsg_OutProcess
SetExtended(2)
EndIf
Else
$pFunc = __GUICtrl_SendMsg_Internal
SetExtended(3)
EndIf
Return $pFunc
EndFunc ;==>__GUICtrl_SendMsg_Init
Func __GUICtrl_SendMsg_Internal($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement)
#forceref $tBuffer, $bRetItem, $bRetBuffer, $iElementMax
Return GUICtrlSendMsg($hWnd, $iMsg, $iIndex, DllStructGetPtr($tItem))
EndFunc ;==>__GUICtrl_SendMsg_Internal
Func _GUICtrlListView_SetExtendedListViewStyle($hWnd, $iExStyle, $iExMask = 0)
Local $iRet
If IsHWnd($hWnd) Then
$iRet = _SendMessage($hWnd, $LVM_SETEXTENDEDLISTVIEWSTYLE, $iExMask, $iExStyle)
_WinAPI_InvalidateRect($hWnd)
Else
$iRet = GUICtrlSendMsg($hWnd, $LVM_SETEXTENDEDLISTVIEWSTYLE, $iExMask, $iExStyle)
_WinAPI_InvalidateRect(GUICtrlGetHandle($hWnd))
EndIf
Return $iRet
EndFunc ;==>_GUICtrlListView_SetExtendedListViewStyle
Func _GUICtrlListView_DeleteAllItems($hWnd)
; Check if deletion necessary
If _GUICtrlListView_GetItemCount($hWnd) = 0 Then Return True
; Determine ListView type
Local $vCID = 0
If IsHWnd($hWnd) Then
; Check ListView ControlID to detect UDF control
$vCID = _WinAPI_GetDlgCtrlID($hWnd)
Else
$vCID = $hWnd
; Get ListView handle
$hWnd = GUICtrlGetHandle($hWnd)
EndIf
; If native ListView - could be either type of item
If $vCID < $_UDF_STARTID Then
; Try deleting as native items
Local $iParam = 0
For $iIndex = _GUICtrlListView_GetItemCount($hWnd) - 1 To 0 Step -1
$iParam = _GUICtrlListView_GetItemParam($hWnd, $iIndex)
; Check if LV item
If GUICtrlGetState($iParam) > 0 And GUICtrlGetHandle($iParam) = 0 Then
GUICtrlDelete($iParam)
EndIf
Next
; Return if no items left
If _GUICtrlListView_GetItemCount($hWnd) = 0 Then Return True
EndIf
; Has to be UDF Listview and/or UDF items
Return _SendMessage($hWnd, $LVM_DELETEALLITEMS) <> 0
EndFunc ;==>_GUICtrlListView_DeleteAllItems
Func _GUICtrlListView_AddColumn($hWnd, $sText, $iWidth = 50, $iAlign = -1, $iImage = -1, $bOnRight = False)
Return _GUICtrlListView_InsertColumn($hWnd, _GUICtrlListView_GetColumnCount($hWnd), $sText, $iWidth, $iAlign, $iImage, $bOnRight)
EndFunc ;==>_GUICtrlListView_AddColumn
Func _GUICtrlListView_InsertColumn($hWnd, $iIndex, $sText, $iWidth = 50, $iAlign = -1, $iImage = -1, $bOnRight = False)
Local $aAlign = [$LVCFMT_LEFT, $LVCFMT_RIGHT, $LVCFMT_CENTER]
Local $tBuffer, $iMsg
If _GUICtrlListView_GetUnicodeFormat($hWnd) Then
$tBuffer = $__g_tListViewBuffer
$iMsg = $LVM_INSERTCOLUMNW
Else
$tBuffer = $__g_tListViewBufferANSI
$iMsg = $LVM_INSERTCOLUMNA
EndIf
Local $tColumn = DllStructCreate($tagLVCOLUMN)
Local $iMask = BitOR($LVCF_FMT, $LVCF_WIDTH, $LVCF_TEXT)
If $iAlign < 0 Or $iAlign > 2 Then $iAlign = 0
Local $iFmt = $aAlign[$iAlign]
If $iImage <> -1 Then
$iMask = BitOR($iMask, $LVCF_IMAGE)
$iFmt = BitOR($iFmt, $LVCFMT_COL_HAS_IMAGES, $LVCFMT_IMAGE)
EndIf
If $bOnRight Then $iFmt = BitOR($iFmt, $LVCFMT_BITMAP_ON_RIGHT)
DllStructSetData($tBuffer, 1, $sText)
DllStructSetData($tColumn, "Mask", $iMask)
DllStructSetData($tColumn, "Fmt", $iFmt)
DllStructSetData($tColumn, "CX", $iWidth)
DllStructSetData($tColumn, "Image", $iImage)
Local $iRet = __GUICtrl_SendMsg($hWnd, $iMsg, $iIndex, $tColumn, $tBuffer, False, 4)
; added, not sure why justification is not working on insert
If $iAlign > 0 Then _GUICtrlListView_SetColumn($hWnd, $iRet, $sText, $iWidth, $iAlign, $iImage, $bOnRight)
Return $iRet
EndFunc ;==>_GUICtrlListView_InsertColumn
Func _GUICtrlListView_GetColumnCount($hWnd)
;Local Const $HDM_GETITEMCOUNT = 0x1200
Return _SendMessage(_GUICtrlListView_GetHeader($hWnd), 0x1200)
EndFunc ;==>_GUICtrlListView_GetColumnCount
Func _GUICtrlListView_GetHeader($hWnd)
If IsHWnd($hWnd) Then
Return HWnd(_SendMessage($hWnd, $LVM_GETHEADER))
Else
Return HWnd(GUICtrlSendMsg($hWnd, $LVM_GETHEADER, 0, 0))
EndIf
EndFunc ;==>_GUICtrlListView_GetHeader
smooth 发表于 2022-4-1 15:15
A大,已做最简测试,依然找不到问题所在。以下是最简代码:
你这哪是精简,这是整合。精简是精简自己的代码,不是把头文件代入展开精简了…… 还运行不了
#include <GuiListView.au3>
#NoTrayIcon
#RequireAdmin
Opt("GUIOnEventMode", 1) ;开启事件模式
Opt("GUICloseOnESC", 0) ;关闭“按ESC”退出脚本的功能
Global $hGui = GUICreate("V2.9", 420, 416)
Global $hMyGuiList = GUICtrlCreateListView("", 10, 238, 400, 136, "", BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($hMyGuiList, "值", 60)
_GUICtrlListView_AddColumn($hMyGuiList, "域", 300)
GUISetState()
GUISetOnEvent(-3, "_Exit")
_Key_GuiSetData()
While 1 ;主循环
Sleep(10)
WEnd
Func _Key_GuiSetData()
Global $aArrayList = [["状态", "$iDateCalc"], ["序列号", "StringStripWS($aArray, 8)"], ["持有者", "$aArray"], ["指纹", "StringStripWS(StringLower($aArray), 8)"], ["有效期", "从 至 "]]
_GUICtrlListView_AddArray($hMyGuiList, $aArrayList)
EndFunc ;==>_Key_GuiSetData
Func _Exit()
Exit
EndFunc ;==>_Exit
以上才是你的内容,但运行正常,并无重现问题 afan 发表于 2022-4-1 15:28
你这哪是精简,这是整合。精简是精简自己的代码,不是把头文件代入展开精简了…… 还运行不了
以上才 ...
我要插入的头文件有冲突,无奈之下只能整合进去。我精简只能在我的脚本的基础上做精简了。 smooth 发表于 2022-4-1 15:15
A大,已做最简测试,依然找不到问题所在。以下是最简代码:
看不出问题?
本帖最后由 smooth 于 2022-4-1 15:43 编辑
chzj589 发表于 2022-4-1 15:35
看不出问题?
我的代码,你可以直接运行?我运行之后,就这样子:
页:
[1]
2