找回密码
 加入
搜索
查看: 9646|回复: 11

[原创] 关于ListView的基础学习笔记

 火.. [复制链接]
发表于 2010-11-10 16:29:35 | 显示全部楼层 |阅读模式
挂个原创吧!毕竟上今天的学习成果,大家别笑话!有许多错误理解,请大家多多指教.
#cs
功能:获取媒体文件的相关信息
所需文件:MediaInfo.dll

目的:学习对ListView的相关操作(感谢3mile的热情帮助)
      GUICtrlCreateListView();GUICtrlCreateListViewItem();GUICtrlSetData();GUICtrlDelete();_GUICtrlListView_DeleteAllItems();
          _GUICtrlListView_SetExtendedListViewStyle($ListView1, $exStyles)  设置ListView的显示风格,添加CheckBox风格等
          _GUICtrlListView_DeleteItem;_GUICtrlListView_DeleteItemsSelected();
          _GUICtrlListView_AddArray() 把数组添加到ListView中;
          _GUICtrlListView_AddColumn() 为ListView添加新的 列,可设置列的宽度
          _GUICtrlListView_AddItem() 为ListView添加新的 项
          _GUICtrlListView_AddSubItem()  不是为Item添加SubItem,在我看来和上面的函数是一样的功能,不知对不对?
          _GUICtrlListView_SetItemSelected() 设置哪个列表项被选择,注意列表项序号是从 0 开始
          _GUICtrlListView_GetSelectedIndicates()  获得被选列表项的 索引号
          _GUICtrlListView_SetItem() 编辑列表项的某列数据,注意 列 也是 从 0 开始
          _GUICtrlListView_SetItemText() 编辑列表项的某列数据
          _GUICtrlListView_GetItemText() 获取列表项某列的文本内容
          _GUICtrlListView_DeleteColumn() 删除ListView 的某列
          _GUICtrlListView_DeleteItem() 删除列表项
          _GUICtrlListView_DeleteAllItems() 删除所有列表项
          _GUICtrlListView_DeleteItemsSelected() 删除被选择的列表项
          _GUICtrlListView_GetView()和_GUICtrlListView_SetView不是很懂!以何种方式查看listview?可通过后者具体设置,有0 到  4 方式的选择
          等同于 _GUICtrlListView_GetViewDetails;_GUICtrlListView_GetViewLarge();_GUICtrlListView_GetViewSmall;_GUICtrlListView_GetViewList
          _GUICtrlListView_BeginUpdate()和_GUICtrlListView_EndUpdate()
          _GUICtrlListView_GetColumn() 选定某列
          _GUICtrlListView_SetColumn() 对选定的列进行编辑,如修改  列宽
          _GUICtrlListView_HideColumn 隐藏列
          _GUICtrlListView_CancelEditLabel() 取消ListView的Label编辑状态
          _GUICtrlListView_FindInText() 查找包含指定文本内容的列表项
          
1。如果该$FileList=_FileListToArray($Target,'*.*',1)语句换成$FileList=_FileListToArray($Target,'*.avi',1)
   ,就只是获取AVI类型媒体文件的信息;
2。将ListViewItem项拖动到用GUICtrlSetState(-1, $GUI_DROPACCEPTED)设置的编辑框或输入框控件上;
3. 注意该 $sRL=_GetInfoArray($Target&$Filelist[$i])语句的路径问题,我就是忘了$Target了,所以没获得任何信息;
#ce



#include<Array.au3>
#include <file.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>;GUICtrlSetState(-1,$GUI_DROPACCEPTED)需要
#include <GuiImageList.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


Dim $Target="F:\家庭录象";要查看的媒体文件所在目录
Dim $FileList[1];用于接收文件夹内的文件的数组
Dim $i,$Number=1;用于计数的变量
Dim $ListView1;第1个ListView变量
Dim $Item[1];ListView的项变量
Dim $iSubItem 
Dim  $exStyles=BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES)

$Form1_1 = GUICreate("显示同一文件夹下多个AVI的媒体信息", 787, 401, 210, 154)
$ListView1 = GUICtrlCreateListView("序号 |文件格式    |视频格式    |音频格式    |音频编码    |视频编码    |总码率    "&  _
                                   "|视频码率    |音频码率    |视频分辨率    |视频分辨率    ", 0, 32, 785, 241)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $exStyles)
GUISetState(@SW_SHOW, $Form1_1)

$hImage = _GUIImageList_Create(32,32)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($ListView1, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($ListView1, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($ListView1, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($ListView1, $hImage,1)
$FileList=_FileListToArray($Target,'*.avi',1);将指定类型的媒体类型文件送到数组中,也可以是 *.*
If IsArray($FileList)=0 Then;送入到数组失败处理
        MsgBox(0,'','目标文件夹里没有文件')
        Exit
Else;送入到数组成功处理,显示获得的相关信息
        ;_GUICtrlListView_BeginUpdate($ListView1);开始更新ListView,不使用他ListView会逐条项的更新,而不是等ListView完全更新后再显示
    For $i=1 To $FileList[0]  Step 1
            $sRL=_GetInfoArray($Target&$Filelist[$i])
                ;_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1));设置$ListView之前,先清除它里面的所有项
                GUICtrlCreateListViewItem($Number&"|" & $sRL[0]&"|"&$sRL[1]&"|"&$sRL[2]&"|"&$sRL[3]&"|"&$sRL[4] & _
                                                  "|"&$sRL[5]&"|"&$sRL[6]&"|"&$sRL[7]&"|"&$sRL[8]&"|"&$sRL[9],$ListView1)
                ;$Item & $i =GUICtrlCreateListViewItem($Number&"|" & $sRL[0]&"|"&$sRL[1]&"|"&$sRL[2]&"|"&$sRL[3]&"|"&$sRL[4] & _
                 ;                                 "|"&$sRL[5]&"|"&$sRL[6]&"|"&$sRL[7]&"|"&$sRL[8]&"|"&$sRL[9],$ListView1)                                                                  
                $Number +=1
                Sleep(1000)
                ;MsgBox(0,'',$sRL[0]&"|"&$sRL[1]&"|"&$sRL[2]&"|"&$sRL[3]&"|"&$sRL[4]&"|"&$sRL[5]&"|"&$sRL[6]&"|"&$sRL[7]&"|"&$sRL[8]&"|"&$sRL[9])
        ;_ArrayDisplay($sRL)
                ;MsgBox(0,'',$FileList[$i])
    Next
        ;_GUICtrlListView_EndUpdate($ListView1);停止ListView的更新
EndIf
;   ;把listview的项拖动到用GUICtrlSetState(-1, $GUI_DROPACCEPTED)设置的输入框或编辑框控件内
_GUICtrlListView_GetColumn($ListView1,0);选取0列
_GUICtrlListView_SetColumn($ListView1,0,"",150);修改0列的宽度为150
_GUICtrlListView_AddColumn($ListView1,"添加的新列",100);注意 设置了列的宽度
_GUICtrlListView_InsertColumn($ListView1,2,"在第3列之前插入新的1列")
_GUICtrlListView_AddItem($ListView1,"添加的新项")
_GUICtrlListView_AddSubItem($ListView1,1,"添加的新子项",1)
$Search=_GUICtrlListView_FindInText($ListView1,"添加的新子项")
_GUICtrlListView_SetItemSelected($ListView1,$Search)
_GUICtrlListView_SetItemSelected($ListView1,1);选定第2个列表项,注意列表项序号是从 0  开始
;$Index=_GUICtrlListView_GetSelectedIndices($ListView1)
;_GUICtrlListView_SetItem($ListView1, "需要修改的内容", $Index , $iSubItem = 0])
;$iSubItem = 0为子项0基索引,如序号为0,文件格式为1....
$Index=_GUICtrlListView_GetSelectedIndices($ListView1);获得被选定的列表项的索引号
Sleep(1000)
MsgBox(0,'获取列表项的文字内容',_GUICtrlListView_GetItemText($ListView1,2,2));获得第3个列表项第3列的内容
if $index>0 then _GUICtrlListView_SetItem($ListView1, "需要修改的内容1", $Index , 2)
;如果$index大于0,修改被选列表项的第3列内容为"需要修改的内容1"
Sleep(1000)
_GUICtrlListView_SetItem($ListView1,"需要修改的内容4",$index,4);修改被选列表项的第5列内容为"需要修改的内容4"
Sleep(1000)
_GUICtrlListView_SetItemText($ListView1,$index,"|需要修改的内容2");修改被选列表项的第0列内容为"需要修改的内容2"
Sleep(1000)
_GUICtrlListView_SetItemText($ListView1,$index,"|需要修改的内容5",5)
Sleep(1000)
_GUICtrlListView_SetItemText($ListView1,2,"需要修改的内容3")
Sleep(1000)
_GUICtrlListView_DeleteItem($ListView1,$index)
_GUICtrlListView_AddSubItem($ListView1,4,2,1);2表示向SubItem添加的文本内容,1表示修改的是哪一列
Sleep(1000)
;MsgBox(0,'开始隐藏列','')
;_GUICtrlListView_HideColumn($ListView1,0)
Sleep(1000)
_GUICtrlListView_SetItemSelected($ListView1,0)
_GUICtrlListView_SetItemSelected($ListView1,1)
Sleep(1000)
_GUICtrlListView_DeleteItemsSelected($ListView1)
Sleep(1000)


While 1
        Sleep(100)
WEnd

Func _GetInfoArray($sMediaFile)
Local $sRL[1]
$sDLL = DllOpen("MediaInfo.dll")
$sHandle = DllCall($sDLL, "ptr", "MediaInfo_New")
$Open_Result = DllCall($sDLL, "int", "MediaInfo_Open", "ptr", $sHandle[0], "wstr", $sMediaFile)
;获取文件格式
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "General;%Format/String%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
$sRL[0] = $Inform[0]
;获取视频格式
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "General;%Video_Format_List%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取音频格式
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "General;%Audio_Format_List%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取音频编码
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "General;%Audio_Codec_List%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取视频编码
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "General;%Video_Codec_List%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取总码率
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "General;%BitRate/String%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取视频码率
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "Video;%BitRate/String%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取音频码率
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "Audio;%BitRate/String%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])
;获取视频分辨率
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "Video;%Width%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
$sWidth = $Inform[0]
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "Video;%Height%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
$sHigh = $Inform[0]
If $sHigh <> '' And $sWidth <> '' Then
_ArrayAdd($sRL, $sWidth & ' X ' & $sHigh)
Else
_ArrayAdd($sRL, '')
EndIf
;获取视频刷新率
DllCall($sDLL, "wstr", "MediaInfo_Option", "ptr", 0, "wstr", "Inform", "wstr", "Video;%FrameRate/String%")
$Inform = DllCall($sDLL, "wstr", "MediaInfo_Inform", "ptr", $sHandle[0], "int", 0)
_ArrayAdd($sRL, $Inform[0])

;删除Handle和DLL
$sHandle = DllCall($sDLL, "none", "MediaInfoList_Delete", "ptr", $sHandle[0])
DllClose($sDLL)
Return $sRL
EndFunc ;==>_GetInfoArray
发表于 2010-11-10 16:32:40 | 显示全部楼层
支持楼主,不错的例子,很全面,很强大。多谢了
发表于 2010-11-10 22:11:04 | 显示全部楼层
不错,注释得很清楚了
发表于 2010-11-25 08:33:16 | 显示全部楼层
LZ这个代码不错,感谢提供.
发表于 2010-12-13 23:08:45 | 显示全部楼层
代码很不错的,收藏
发表于 2011-1-27 23:29:40 | 显示全部楼层
不错的例子,很全面,很强大。多谢
发表于 2011-4-2 12:16:44 | 显示全部楼层
支持楼主,不错的例子,很全面,很强大。多谢了
发表于 2011-5-12 00:07:51 | 显示全部楼层
收藏此贴,学习,谢谢分享..
发表于 2011-5-15 19:25:34 | 显示全部楼层
收藏此贴,学习
发表于 2011-9-4 09:05:29 | 显示全部楼层
收藏此贴,学习
发表于 2011-9-8 14:39:13 | 显示全部楼层
不錯的啊    學到了很多
发表于 2013-8-1 07:30:54 | 显示全部楼层
不错,学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 21:18 , Processed in 0.081993 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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