Jump to content

ListView with $LVS_ICON and $LVS_LIST


Recommended Posts

#Include <GuiListView.au3>
#Include <GuiImageList.au3>

$g = GUICreate("")
$hList = _GUICtrlListView_Create($g, "",2,2, 200, 200, BitOR($lvs_icon, $lvs_list))
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, "myicon.ico")
_GUICtrlListView_SetImageList($hList, $hImage)
_GUICtrlListView_AddItem($hList, "Item", 0)
GUISetState()

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

what am I doing wrong?

Link to comment
Share on other sites

The $iType parameter for _GUICtrlListView_SetImageList() does not seem to be as optional as I thought :blink:...

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

$g = GUICreate("")
$hList = _GUICtrlListView_Create($g, "", 2, 2, 200, 200, BitOR($lvs_icon, $lvs_list))
$hImage = _GUIImageList_Create(16, 16, 5, 3, 1)
ConsoleWrite($hImage & @CRLF)
$res = _GUIImageList_AddIcon($hImage, @ScriptDir & "\myicon.ico")
ConsoleWrite($res & @CRLF)
$res = _GUICtrlListView_SetImageList($hList, $hImage,1)
ConsoleWrite($res & @CRLF)
$res = _GUICtrlListView_AddItem($hList, "Item", 0)
ConsoleWrite($res & @CRLF)
GUISetState()

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd
Link to comment
Share on other sites

awesome, thanks ;)

One more question, how can I increase the size of the listview items?

I used to use GUICtrlSetFont() on ListBox controls but it doesn't seem to work with ListViews :blink:

Edited by Info
Link to comment
Share on other sites

Thats easy :blink:...

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <Winapi.au3>
#include <FontConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

$h_Report_ListView_Font = _WinAPI_CreateFont(30, 0, 0, 0, 600, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _
        $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, 0, "Tahoma")
OnAutoItExitRegister("_OnAutoItExitRegister")
Func _OnAutoItExitRegister()
    _WinAPI_DeleteObject($h_Report_ListView_Font)
EndFunc

$g = GUICreate("")
$hList = _GUICtrlListView_Create($g, "", 2, 2, 200, 200, BitOR($lvs_icon, $lvs_list))
$hImage = _GUIImageList_Create(16, 16, 5, 3, 1)
$res = _GUIImageList_AddIcon($hImage, @ScriptDir & "\myicon.ico")
$res = _GUICtrlListView_SetImageList($hList, $hImage, 1)
$res = _GUICtrlListView_AddItem($hList, "Item", 0)

GUIRegisterMsg($WM_NOTIFY, "My_WM_NOTIFY")

GUISetState()

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd


Func My_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hList
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
                    Switch DllStructGetData($tCustDraw, "dwDrawStage")
                        Case $CDDS_PREPAINT
                            Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    EndSwitch
                    Local $hDC = DllStructGetData($tCustDraw, 'hdc')
                    _WinAPI_SelectObject($hDC, $h_Report_ListView_Font)
                    Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>My_WM_NOTIFY
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...