找回密码
 加入
搜索
查看: 3442|回复: 5

[AU3基础] 下面代码中的 _GUIImageList_Create()为什么没有效果?

[复制链接]
发表于 2010-11-10 14:46:49 | 显示全部楼层 |阅读模式
#cs
功能:获取媒体文件的相关信息

目的:学习对ListView的相关操作(感谢3mile的热情帮助)
      GUICtrlCreateListView();GUICtrlCreateListViewItem();GUICtrlSetData();GUICtrlDelete();_GUICtrlListView_DeleteAllItems();
          _GUICtrlListView_DeleteItem;_GUICtrlListView_DeleteItemsSelected();
          _GUICtrlListView_AddArray() 把数组添加到ListView中;
          _GUICtrlListView_AddColumn() 为ListView添加新的 列,可设置列的宽度
          _GUICtrlListView_AddItem() 为ListView添加新的 项
          _GUICtrlListView_SetItemSelected() 设置哪个列表项被选择,注意列表项序号是从 0 开始
          _GUICtrlListView_GetSelectedIndicates()  获得被选列表项的 索引号
          _GUICtrlListView_SetItem() 编辑列表项的某列数据,注意 列 也是 从 0 开始
          _GUICtrlListView_SetItemText() 编辑列表项的某列数据
          _GUICtrlListView_GetItemText() 获取列表项某列的文本内容
          _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_HideColumn 隐藏列
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>

#include <GuiListView.au3>
#include <GuiImageList.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

$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()
    _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)设置的输入框或编辑框控件内



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 15:14:31 | 显示全部楼层
51行:Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
59-62行:    $hImage = _GUIImageList_Create(32, 32)
    _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap(GUICtrlGetHandle($listview), 0xFF0000, 32, 32))
    _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap(GUICtrlGetHandle($listview), 0x00FF00, 32, 32))
    _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap(GUICtrlGetHandle($listview), 0x0000FF, 32, 32))
 楼主| 发表于 2010-11-10 15:21:07 | 显示全部楼层
回复 2# 3mile
是_GUIImageList_Create(32, 32)的默认 宽和高小了吗?
0xFF0000还是没看到效果颜色啊?
 楼主| 发表于 2010-11-10 15:30:15 | 显示全部楼层
回复 2# 3mile
请看以下代码:
#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $listview, $hImage
    Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
    
    GUICreate("ImageList Create", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
    GUISetState()
    
    ; Load images
    $hImage = _GUIImageList_Create(11, 11)
    _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap(GUICtrlGetHandle($listview), 0xFF0000, 11, 11))
    _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap(GUICtrlGetHandle($listview), 0x00FF00, 11, 11))
    _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap(GUICtrlGetHandle($listview), 0x0000FF, 11, 11))
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($listview, "Items", 120)

    ; Add items
    _GUICtrlListView_AddItem($listview, "Item 1", 0)
    _GUICtrlListView_AddItem($listview, "Item 2", 1)
    _GUICtrlListView_AddItem($listview, "Item 3", 2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
发表于 2010-11-10 16:31:22 | 显示全部楼层
回复 4# newuser
没有问题啊.我这里正常.
 楼主| 发表于 2010-11-10 16:36:22 | 显示全部楼层
回复 5# 3mile
不好意思,我叙述有误,请看楼上代码,它的0列前的颜色块怎么弄的,我照猫画虎想把它弄到1楼的的代码上,怎么看不到有颜色块的出现?
另外,再请教,我为listview添加了$LVS_EX_CHECKBOXES,执行代码后,
0列的数字序列:1 2 3 ...
离CheckBox有点远,我该怎么让它们之间的距离小点呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 18:54 , Processed in 0.090909 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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