Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 21: Tree and List Controls Visual C++ and MFC Fundamentals


void COthersDlg::OnSmallIconBtn()
{
// TODO: Add your control notification handler code here
LONG mListStyle = GetWindowLong(m_List.m_hWnd, GWL_STYLE);
mListStyle &= ~LVS_TYPEMASK;
mListStyle |= LVS_SMALLICON;
SetWindowLong(m_List.m_hWnd, GWL_STYLE, mListStyle);
}

void COthersDlg::OnListBtn()
{
// TODO: Add your control notification handler code here
LONG mListStyle = GetWindowLong(m_List.m_hWnd, GWL_STYLE);
mListStyle &= ~LVS_TYPEMASK;
mListStyle |= LVS_LIST;
SetWindowLong(m_List.m_hWnd, GWL_STYLE, mListStyle);
}

void COthersDlg::OnReportBtn()
{
// TODO: Add your control notification handler code here
LONG mListStyle = GetWindowLong(m_List.m_hWnd, GWL_STYLE);
mListStyle &= ~LVS_TYPEMASK;
mListStyle |= LVS_REPORT;
SetWindowLong(m_List.m_hWnd, GWL_STYLE, mListStyle);
}

21.3.6..List Control and Icons........................................................................


A list control can be configured to display pictures that accompany either the columns,
the list items, or both. If you want to display a bitmap on the column, you should declare
and initialize a CImageList variable. Then call the CListCtrl::SetImageList() method
and pass it as argument. If you plan to do this, and if you are using the first version of the
CListCtrl::InsertColumn() method that takes an LVCOLUMN pointer as argument, then
add the LVCF_IMAGE value to the mask variable and add the LVCFMT_IMAGE
value to the fmt variable. To specify the image that will display on the column header,
assign its index to the value of the iImage variable. Here is an example:

BOOL COthersDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
LVCOLUMN lvColumn;

CImageList *ImgHeaders = new CImageList;

ImgHeaders->Create(16, 16, ILC_MASK, 1, 1);
ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_UP));
ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_LOSANGE));

m_List.SetImageList(ImgHeaders, LVSIL_SMALL);

lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_IMAGE;
lvColumn.fmt = LVCFMT_LEFT | LVCFMT_IMAGE;
lvColumn.cx = 120;
lvColumn.pszText = "Full Name";
Free download pdf