Jump to content

[Solved] Listview in Tile mode - Height not correct


KaFu
 Share

Recommended Posts

HiHo Forum,

I've been playing around with Listview in Tile mode. Populating and switching style works fine, but (at least on the XP machine tested on) the tiles still seem to overlap. Row1 and Row2 look fine, but when you click Row3 you'll see that it overlaps with Row1.

Anyone :)? Maybe as a bonus question, how do I change to amount of tiles per row (I've not started to look into that)?

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
$GUI = GUICreate("ListView Example - Tile View", 400, 300)
$hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
For $i = 0 To 2
_GUICtrlListView_AddItem($hListView, "Row " & $i + 1 & ": Col 1")
_GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i + 1 & ": Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i + 1 & ": Col 3", 2)
Next
_GUICtrlListView_SetView($hListView, 4)
; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774768(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb774768(v=vs.85).aspx[/url]
Global $tag_LVTILEVIEWINFO = "UINT cbSize;DWORD dwMask;DWORD dwFlags;STRUCT;LONG Size_cx;LONG Size_cy;ENDSTRUCT;INT cLines;STRUCT;LONG RECT_left;LONG RECT_top;LONG RECT_right;LONG RECT_bottom;ENDSTRUCT;"
$t_Struct2 = DllStructCreate($tag_LVTILEVIEWINFO)
DllStructSetData($t_Struct2, "cbSize", DllStructGetSize($t_Struct2))
#cs
Const LVTVIM_TILESIZE = &H00000001
Const LVTVIM_COLUMNS     = &H00000002
Const LVTVIM_LABELMARGIN = &H00000004
#ce
DllStructSetData($t_Struct2, "dwMask", BitOR(0x2, 0x4))
#cs
public const int LVTVIF_AUTOSIZE = 0;
public const int LVTVIF_FIXEDWIDTH = 1;
public const int LVTVIF_FIXEDHEIGHT = 2;
public const int LVTVIF_FIXEDSIZE = 3;
#endregion
#ce
DllStructSetData($t_Struct2, "dwFlags", 0)
DllStructSetData($t_Struct2, "Size_cx", 160) ; Width
DllStructSetData($t_Struct2, "Size_cy", 50) ; Height
DllStructSetData($t_Struct2, "cLines", 2) ; cLines
DllStructSetData($t_Struct2, "RECT_left", 1) ; Margin Left
DllStructSetData($t_Struct2, "RECT_top", 10) ; Margin Top
DllStructSetData($t_Struct2, "RECT_right", 1) ; Margin Right
DllStructSetData($t_Struct2, "RECT_bottom", 10) ; Margin Bottom
$p_Struct2 = DllStructGetPtr($t_Struct2)
; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761212(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb761212(v=vs.85).aspx[/url]
ConsoleWrite(_SendMessage($hListView, $LVM_SETTILEVIEWINFO, 0, $p_Struct2) & @CRLF)
For $iItem = 0 To 2
; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774766(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb774766(v=vs.85).aspx[/url]
Global $tag_LVTILEINFO = "UINT cbSize;INT iItem;UINT cColumns;PTR puColumns;" ;PTR piColFmt;"
$t_Struct = DllStructCreate($tag_LVTILEINFO)
DllStructSetData($t_Struct, "cbSize", DllStructGetSize($t_Struct)) ; cbSize
DllStructSetData($t_Struct, "iItem", $iItem) ; 0-based
DllStructSetData($t_Struct, "cColumns", 2) ; cColumns
$t_Struct_Cols = DllStructCreate("int;int")
DllStructSetData($t_Struct_Cols, 1, 2) ; show third column first
DllStructSetData($t_Struct_Cols, 2, 1) ; show second column last
DllStructSetData($t_Struct, "puColumns", DllStructGetPtr($t_Struct_Cols))
$p_Struct = DllStructGetPtr($t_Struct)
; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761210(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb761210(v=vs.85).aspx[/url]
ConsoleWrite(_SendMessage($hListView, $LVM_SETTILEINFO, 0, $p_Struct) & @CRLF)
Next
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Regards

Edited by KaFu
Link to comment
Share on other sites

Link to comment
Share on other sites

Reordered the calls to

LVM_SETTILEVIEWINFO

_GUICtrlListView_SetView

LVM_SETTILEINFO

and now it works :)...

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

$GUI = GUICreate("ListView Example - Tile View", 400, 300)

$hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT))

; Load images
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))

_GUICtrlListView_SetImageList($hListView, $hImage, 1)
_GUICtrlListView_SetImageList($hListView, $hImage, 0) ; for Tile View

_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

For $i = 0 To 19
    _GUICtrlListView_AddItem($hListView, "Row " & $i + 1 & ": Col 1", mod($i,3))
    _GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i + 1 & ": Col 2", 1)
    _GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i + 1 & ": Col 3", 2)
Next


; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774768(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb774768(v=vs.85).aspx[/url]
Global $tag_LVTILEVIEWINFO = "UINT cbSize;DWORD dwMask;DWORD dwFlags;STRUCT;LONG Size_cx;LONG Size_cy;ENDSTRUCT;INT cLines;STRUCT;LONG RECT_left;LONG RECT_top;LONG RECT_right;LONG RECT_bottom;ENDSTRUCT;"
$t_Struct2 = DllStructCreate($tag_LVTILEVIEWINFO)
DllStructSetData($t_Struct2, "cbSize", DllStructGetSize($t_Struct2))
#cs
    Const LVTVIM_TILESIZE    = &H00000001
    Const LVTVIM_COLUMNS    = &H00000002
    Const LVTVIM_LABELMARGIN = &H00000004
#ce
DllStructSetData($t_Struct2, "dwMask", 7)
#cs
    public const int LVTVIF_AUTOSIZE = 0;
    public const int LVTVIF_FIXEDWIDTH = 1;
    public const int LVTVIF_FIXEDHEIGHT = 2;
    public const int LVTVIF_FIXEDSIZE = 3;
    #endregion
#ce
DllStructSetData($t_Struct2, "dwFlags", 3)
DllStructSetData($t_Struct2, "Size_cx", 180) ; Width
DllStructSetData($t_Struct2, "Size_cy", 80) ; Height

DllStructSetData($t_Struct2, "cLines", 2) ; cLines

DllStructSetData($t_Struct2, "RECT_left", 10) ; Margin Left
DllStructSetData($t_Struct2, "RECT_top", 5) ; Margin Top
DllStructSetData($t_Struct2, "RECT_right", 10) ; Margin Right
DllStructSetData($t_Struct2, "RECT_bottom", 5) ; Margin Bottom
$p_Struct2 = DllStructGetPtr($t_Struct2)
; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761212(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb761212(v=vs.85).aspx[/url]
ConsoleWrite(_SendMessage($hListView, $LVM_SETTILEVIEWINFO, 0, $p_Struct2) & @CRLF)

_GUICtrlListView_SetView($hListView, 4)

For $iItem = 0 To 19
    ; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774766(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb774766(v=vs.85).aspx[/url]
    Global $tag_LVTILEINFO = "UINT cbSize;INT iItem;UINT cColumns;PTR puColumns;" ;PTR piColFmt;"
    $t_Struct = DllStructCreate($tag_LVTILEINFO)
    DllStructSetData($t_Struct, "cbSize", DllStructGetSize($t_Struct)) ; cbSize
    DllStructSetData($t_Struct, "iItem", $iItem) ; 0-based
    DllStructSetData($t_Struct, "cColumns", 2) ; cColumns
    $t_Struct_Cols = DllStructCreate("int;int")
    DllStructSetData($t_Struct_Cols, 1, 2) ; show third column first
    DllStructSetData($t_Struct_Cols, 2, 1) ; show second column last
    DllStructSetData($t_Struct, "puColumns", DllStructGetPtr($t_Struct_Cols))
    $p_Struct = DllStructGetPtr($t_Struct)
    ; [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761210(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb761210(v=vs.85).aspx[/url]
    ConsoleWrite(_SendMessage($hListView, $LVM_SETTILEINFO, 0, $p_Struct) & @CRLF)
Next

_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE )

GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Edited by KaFu
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

×
×
  • Create New...