Quantcast
Channel: codexpert blog
Viewing all articles
Browse latest Browse all 85

Tiles-View List Control

$
0
0

Tiles View in Windows Explorer

Using Windows Explorer we can notice, aside others, the Tile View mode.

Tiles View (Windows Explorer)

Tiles View (Windows Explorer)

It looks like icon views but, beside a title (that shows the file name), it displays some additional info (file type and size).
This articles describe how to set Tiles View in our own listview (SysListView32) Windows control.

Set Tiles View in a list control

Let’s say, we’ve placed a list control in a dialog template. Possible, the first attempt is to search for a “Tile” value of the “View” property. No luck: we can see only “Icon”, “Small icon”, “List”, and “Report” (LVS_ICON, LVS_SMALLICON, LVS_LIST, and LVS_REPORT types).

However, there is a solution: send LVM_SETVIEW message or use ListView_SetView macro or (if using MFC) call CListCtrl::SetView.

Examples

HWND hWndList = ::GetDlgItem(hWndDlg, IDC_LISTVIEW_DEMO);
    ::SendMessage(hWndList, LVM_SETVIEW, (WPARAM)LV_VIEW_TILE, 0);

HWND hWndList = ::GetDlgItem(hWndDlg, IDC_LISTVIEW_DEMO);
    ListView_SetView(hWndList, LV_VIEW_TILE);

// CDemoListView is derived from CListView MFC class
void CDemoListView::OnViewTile()
{
    // get the list control
    CListCtrl& listCtrl = GetListCtrl();
    // set Tile View mode
    listCtrl.SetView(LV_VIEW_TILE);
}

In the same way, we can switch to the other view types, by passing LV_VIEW_ICON, LV_VIEW_SMALLICON, LV_VIEW_LIST, or LV_VIEW_DETAILS.
That’s pretty easy. However there are a little bit more things to do.

Set information for the list-view control in Tile View

For this purpose we can send LVM_SETTILEVIEWINFO message or use ListView_SetTileViewInfo or call CListCtrl::SetTileViewInfo.

Example

// Set the maximum number of text lines in each item label, not including the title.
BOOL CDemoListView::_SetTilesViewLinesCount(int nCount)
{
    CListCtrl& listCtrl = GetListCtrl();

     LVTILEVIEWINFO lvtvwi = {0};
     lvtvwi.cbSize = sizeof(LVTILEVIEWINFO);
     lvtvwi.dwMask = LVTVIM_COLUMNS;
     lvtvwi.cLines = nCount;

     return listCtrl.SetTileViewInfo(&lvtvwi);
}

Set information for each item in Tile View

This can be done when the item is inserted or later, by sending LVM_SETTILEINFO, using ListView_SetTileInfo or calling CListCtrl::SetTileInfo.

Example

// Displays columns 1, 3 and 5 for the item 2.
void CDemoListView::_InitAndFillList()
{
   // ...
   // ....
   UINT arrColumns[3] = {1, 3, 5};
   VERIFY(_SetItemTileLines(2, arrColumns, 3));

}

BOOL CDemoListView::_SetItemTileLines(int nItem, UINT* parrColumns, UINT nCount)
{
    CListCtrl& listCtrl = GetListCtrl();

    LVTILEINFO lvti = {0};
    lvti.cbSize = sizeof(LVTILEINFO);
    lvti.cColumns = nCount;
    lvti.iItem = nItem;
    lvti.puColumns = parrColumns;

    return listCtrl.SetTileInfo(&lvti);
}

Demo Application

This is just a brief presentation. You can find more hints and details in the links below and in the demo project attached here.

Tiles View (Demo Application)

Tiles View (Demo Application)

Download: Tiles View List Control [Demo Project] (67)

Resources


Viewing all articles
Browse latest Browse all 85

Trending Articles