Using TListWindow

Date: 10 January 1998
Author: Christopher Kohlhoff

Overview

This article looks at how to use TListWindow, or the ListView common control. This will be done by creating a simple directory browsing application. You can download the entire project from here. Please note that this is Borland C++ 5.01 (or higher) and 32-bit only.

Steps

Creating the List Window

The list window will be created as a child of another window (called TLWWindow here). There is no need to subclass the TListWindow. To create the list window we write:

//--------------------------------------------------------
// TLWWindow
// ~~~~~~~~~
// Construction/Destruction handling.
//
TLWWindow::TLWWindow(TWindow* parent,
                     const char far* title,
                     TModule* module)
:
  TWindow(parent, title, module)
{
  // create the list window (the size is unimportant - see EvSize)
  //
  List = new TListWindow(this, kListId, 0000, module);
  List->Attr.Style |= LVS_REPORT;
}

and to resize the list window to fill the client area:

DEFINE_RESPONSE_TABLE1(TLWWindow, TWindow)
  //...
  EV_WM_SIZE,
  //...
END_RESPONSE_TABLE;


void TLWWindow::EvSize(uint sizeType, TSize& size)
{
  TWindow::EvSize(sizeType, size);
  List->MoveWindow(GetClientRect(), true);
}

Next Page