Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


m_List.SetItemText(nItem, 3, "Programming");

lvItem.mask = LVIF_TEXT;
lvItem.iItem = 3;
lvItem.iSubItem = 0;
lvItem.pszText = "Ella Pius Roger";
nItem = m_List.InsertItem(&lvItem);

m_List.SetItemText(nItem, 1, "Architect");
m_List.SetItemText(nItem, 2, "Ping-Pong");
m_List.SetItemText(nItem, 3, "Songo");

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

21.3.5..Views Transition..................................................................................


You can create a list control that displays its items in a single view or you can allow the
user to change from one view to another. As mentioned already, at design time or when
programmatically creating the list control, you can set the initial view using either the
View combo box to select a view’s value or by adding one of the view styles. If you want
to display only that initial view, you can stop there. Otherwise, you can provide a means
of changing views.

Because the view displayed on a list control is part of its style, in order to
programmatically change its view mode, you can first retrieve the control’s style using
the GetWindowLong() function. The GetWindowLong() function only retrieves the
current style of the control. You may need to check it first before changing it. This can be
done by ANDing the value of the GetWindowLong() function with the
LVS_TYPEMASK constant. After checking the view of the control, you can then
change its style by calling the SetWindowLong() function. Here is an example:

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