xzf680 发表于 2018-5-5 18:38:55

GuiListView 如何调整使 GUICtrlSetImage 设置的图标变大【已解决】

本帖最后由 xzf680 于 2018-5-6 12:47 编辑

如何调整使 GUICtrlSetImage 设置的图标变大,指定图标大小。


#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Example()

Func Example()
      ; 创建一个 GUI 及其各种控件.
      Local $hGUI = GUICreate("内置函数示例")
      Local $idOK = GUICtrlCreateButton("确定", 310, 370, 85, 25)
                Local $label = GUICtrlCreateLabel("如何调整使 GUICtrlSetImage 设置的图标变大", 15, 270)
                GUICtrlSetColor(-1, 255)
      Global $idListview = GUICtrlCreateListView("列表1|列表2|列表3|列表4|列表5", 15, 15, 365, 200, BitOR($lvs_showselalways, $lvs_nosortheader, $lvs_report, $lvs_singlesel))
      _GUICtrlListView_SetColumnWidth(-1, 0, 70)
      _GUICtrlListView_SetColumnWidth(-1, 1, 70)
      _GUICtrlListView_SetColumnWidth(-1, 2, 70)
      _GUICtrlListView_SetColumnWidth(-1, 3, 70)
      _GUICtrlListView_SetColumnWidth(-1, 4, 70)
      GUICtrlSendMsg(-1, $lvm_setextendedlistviewstyle, $lvs_ex_gridlines, $lvs_ex_gridlines)
      Local $idItem1 = GUICtrlCreateListViewItem("图标1|子目2|子目3|子目4|子目5", $idListview)
      GUICtrlSetImage(-1, "shell32.dll", 22)
       Local $idItem2 = GUICtrlCreateListViewItem("图标2|子目2|子目3|子目4|子目5", $idListview)
      GUICtrlSetImage(-1, "shell32.dll", 23)
       Local $idItem3 = GUICtrlCreateListViewItem("图标3|子目2|子目3|子目4|子目5", $idListview)
      GUICtrlSetImage(-1, "shell32.dll", 24)
       Local $idItem4 = GUICtrlCreateListViewItem("图标4|子目2|子目3|子目4|子目5", $idListview)
      GUICtrlSetImage(-1, "shell32.dll", 25)
       Local $idItem5 = GUICtrlCreateListViewItem("图标5|子目2|子目3|子目4|子目5", $idListview)
      GUICtrlSetImage(-1, "shell32.dll", 26)
       Local $idItem6 = GUICtrlCreateListViewItem("图标6|子目2|子目3|子目4|子目5", $idListview)
      GUICtrlSetImage(-1, "shell32.dll", 27)
      ; 显示 GUI.
      GUISetState(@SW_SHOW, $hGUI)

      ; 循环到用户退出.
      While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE, $idOK
                              ExitLoop

                EndSwitch
      WEnd

      ; 删除先前创建的 GUI 和所有控件.
      GUIDelete($hGUI)
EndFunc   ;==>Example

kk_lee69 发表于 2018-5-6 00:15:26

回复 1# xzf680

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

_Main()

Func _Main()
    Local $hGui, $listview, $hImage
    Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    $hGui = GUICreate("?像列表(ImageList) UDF 函?演示", 400, 300)
    $listview = _GUICtrlListView_Create($hGui, "", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
    GUISetState()

    ; 加?映像
    $hImage = _GUIImageList_Create(64, 64, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; 添加列
    _GUICtrlListView_AddColumn($listview, "列 1", 120)
    _GUICtrlListView_AddColumn($listview, "列 2", 100)
    _GUICtrlListView_AddColumn($listview, "列 3", 100)

    ; 添加??
    _GUICtrlListView_AddItem($listview, "行 1: ? 1", 0)
    _GUICtrlListView_AddSubItem($listview, 0, "行 1: ? 2", 1, 1)
    _GUICtrlListView_AddSubItem($listview, 0, "行 1: ? 3", 2, 2)
    _GUICtrlListView_AddItem($listview, "行 2: ? 1", 1)
    _GUICtrlListView_AddSubItem($listview, 1, "行 2: ? 2", 1, 2)
    _GUICtrlListView_AddItem($listview, "行 3: ? 1", 2)
    _GUICtrlListView_AddItem($listview, "行 4: ? 1", 3)
    _GUICtrlListView_AddItem($listview, "行 5: ? 1", 4)
    _GUICtrlListView_AddSubItem($listview, 4, "行 5: ? 2", 1, 3)
    _GUICtrlListView_AddItem($listview, "行 6: ? 1", 5)
    _GUICtrlListView_AddSubItem($listview, 5, "行 6: ? 2", 1, 4)
    _GUICtrlListView_AddSubItem($listview, 5, "行 6: ? 3", 2, 3)

    ; 循?到用?退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

EndFunc   ;==>_Main

xzf680 发表于 2018-5-6 10:50:07

回复 2# kk_lee69


    感谢kk_lee69 版主的回复
前面也有考虑过用_GUICtrlListView
_GUICtrlListView创建的表没有GUICtrlCreateListView的好看,想和GUICtrlCreateListView一样有个边框,另外GUICtrlCreateListView添加项目一排能搞定比较方便,如GUICtrlCreateListView能指定图标大小就非常完美了。


#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $idListview, $hImage
    Local $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES);项目和子项显示网格.,该项及其所有子项高亮显示.,允许显示子项目图像.

    $hGui = GUICreate("添加图标到图像列表")
        Local $idOK = GUICtrlCreateButton("确定", 310, 370, 85, 25)
    Local $label = GUICtrlCreateLabel("如何调整使 GUICtrlSetImage 设置的图标变大", 15, 270)
        GUICtrlSetColor(-1, 255)

    $idListview = _GUICtrlListView_Create($hGui, "", 15, 15, 365, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT));始终显示被选项目.列标题不作为按钮类型工作.,控件样式为报表视图.
    _GUICtrlListView_SetExtendedListViewStyle($idListview, $iStylesEx)
    GUISetState(@SW_SHOW)

    ; 加载图像
    $hImage = _GUIImageList_Create(20, 20, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; 添加列
    _GUICtrlListView_AddColumn($idListview, "列表 1", 70)
    _GUICtrlListView_AddColumn($idListview, "列表 2", 70)
    _GUICtrlListView_AddColumn($idListview, "列表 3", 70)
    _GUICtrlListView_AddColumn($idListview, "列表 4", 70)
    _GUICtrlListView_AddColumn($idListview, "列表 5", 70)

    ; 添加项目
    _GUICtrlListView_AddItem($idListview, "图标 1", 0)
    _GUICtrlListView_AddSubItem($idListview, 0, "列 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 0, "列 3", 2)
    _GUICtrlListView_AddSubItem($idListview, 0, "列 4", 3)
    _GUICtrlListView_AddSubItem($idListview, 0, "列 5", 4)
    _GUICtrlListView_AddItem($idListview, "图标 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "列 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "列 3", 2)
    _GUICtrlListView_AddSubItem($idListview, 1, "列 4", 3)
    _GUICtrlListView_AddSubItem($idListview, 1, "列 5", 4)
    _GUICtrlListView_AddItem($idListview, "图标 1", 3)
    _GUICtrlListView_AddSubItem($idListview, 2, "列 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 2, "列 3", 2)
    _GUICtrlListView_AddSubItem($idListview, 2, "列 4", 3)
    _GUICtrlListView_AddSubItem($idListview, 2, "列 5", 4)
        _GUICtrlListView_AddItem($idListview, "图标 1", 4)
    _GUICtrlListView_AddSubItem($idListview, 3, "列 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 3, "列 3", 2)
    _GUICtrlListView_AddSubItem($idListview, 3, "列 4", 3)
    _GUICtrlListView_AddSubItem($idListview, 3, "列 5", 4)
        _GUICtrlListView_AddItem($idListview, "图标 1", 5)
    _GUICtrlListView_AddSubItem($idListview, 4, "列 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 4, "列 3", 2)
    _GUICtrlListView_AddSubItem($idListview, 4, "列 4", 3)
    _GUICtrlListView_AddSubItem($idListview, 4, "列 5", 4)
    ; 循环到用户退出.
    Do
                Switch GUIGetMsg()

                        Case $idOK

                                        ExitLoop

                EndSwitch

    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

afan 发表于 2018-5-6 11:46:30

这种一般都是用图像列表调整,很简单也很灵活,至于列表创建方式,用你之前的方式同样可以
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Example()

Func Example()
        ; 创建一个 GUI 及其各种控件.
        Local $hGUI = GUICreate("内置函数示例")
        Local $idOK = GUICtrlCreateButton("确定", 310, 370, 85, 25)
        Local $label = GUICtrlCreateLabel("如何调整使 GUICtrlSetImage 设置的图标变大", 15, 270)
        GUICtrlSetColor(-1, 255)
        Global $idListview = GUICtrlCreateListView("列表1|列表2|列表3|列表4|列表5", 15, 15, 365, 220, BitOR($lvs_showselalways, $lvs_nosortheader, $lvs_report, $lvs_singlesel))
        _GUICtrlListView_SetColumnWidth(-1, 0, 70)
        _GUICtrlListView_SetColumnWidth(-1, 1, 70)
        _GUICtrlListView_SetColumnWidth(-1, 2, 70)
        _GUICtrlListView_SetColumnWidth(-1, 3, 70)
        _GUICtrlListView_SetColumnWidth(-1, 4, 70)
        GUICtrlSendMsg(-1, $lvm_setextendedlistviewstyle, $lvs_ex_gridlines, $lvs_ex_gridlines)
        Local $idItem1 = GUICtrlCreateListViewItem("图标1|子目2|子目3|子目4|子目5", $idListview)
        Local $idItem2 = GUICtrlCreateListViewItem("图标2|子目2|子目3|子目4|子目5", $idListview)
        Local $idItem3 = GUICtrlCreateListViewItem("图标3|子目2|子目3|子目4|子目5", $idListview)
        Local $idItem4 = GUICtrlCreateListViewItem("图标4|子目2|子目3|子目4|子目5", $idListview)
        Local $idItem5 = GUICtrlCreateListViewItem("图标5|子目2|子目3|子目4|子目5", $idListview)
        Local $idItem6 = GUICtrlCreateListViewItem("图标6|子目2|子目3|子目4|子目5", $idListview)

        Local $hImage = _GUIImageList_Create(32, 32, 5, 3)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 22, 1)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 23, 1)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 24, 1)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 25, 1)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 26, 1)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 27, 1)
        _GUICtrlListView_SetItemImage($idListview, 0, 0)
        _GUICtrlListView_SetItemImage($idListview, 1, 1)
        _GUICtrlListView_SetItemImage($idListview, 2, 2)
        _GUICtrlListView_SetItemImage($idListview, 3, 3)
        _GUICtrlListView_SetItemImage($idListview, 4, 4)
        _GUICtrlListView_SetItemImage($idListview, 5, 5)
        GUISetState(@SW_SHOW, $hGUI)

        ; 循环到用户退出.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE, $idOK
                                ExitLoop

                EndSwitch
        WEnd

        ; 删除先前创建的 GUI 和所有控件.
        GUIDelete($hGUI)
EndFunc   ;==>Example

xzf680 发表于 2018-5-6 12:45:05

感谢kk_lee69 版主的回复
感谢 afan 超级版主的回复,问题完美解决

kk_lee69 发表于 2018-5-6 16:12:03

回复 5# xzf680

是你誤解了給你看那個範例 不是要你看 _GUICtrlListView

是要你看
    $hImage = _GUIImageList_Create(64, 64, 5, 3)

圖示大小是這行在控制的

所以你的GUICtrlCreateListView 加上
   $hImage = _GUIImageList_Create(64, 64, 5, 3)

就可以完美了

weeks1 发表于 2018-5-10 09:31:37

学习了。。。。。。。。
页: [1]
查看完整版本: GuiListView 如何调整使 GUICtrlSetImage 设置的图标变大【已解决】