CListCtrl::SetItemState
Nancy Enright -- Nancy_Enright.IDEA@mailgw.idea.com
Friday, May 03, 1996
[Mini-digest: Question with answer]
Using VC++ 4.1, Win 95.
I have 3 CListCtrls on a Wizard Page. Each control has two items with
icons and labels. There is nothing else in the dialog box. Using:
m_pList->SetItemState(0,LVIS_SELECTED, 0x000F); I am able to set the
default to the first item in the first control during OnInitDialog.
But I am unable to set the default in the other two controls using the
same approach. Any ideas?
More details: The return from all three calls to SetItemState is OK.
SetItemState maps to SetItem in AFXCMN.INL. I have traced into
CListCtrl::SetItem and checked all of the LV_ITEM values and the
control handle passed in. Everything looks fine. CListCtrl::SetItem
calls ::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi); I have
verified that the messages were sent and received using Spy++. Here is
the code that I call at the end of OnInitDialog. The first call works
but the second and third do not.
void CDisplayPg::SetDefaults()
{
m_pListColorMono->SetItemState(DEVICE_COLOR,LVIS_SELECTED, 0x000F);
m_pListCols->SetItemState(DEVICE_80,LVIS_SELECTED, 0x000F);
m_pListGraphics->SetItemState(DEVICE_NON_GRAPHICS,LVIS_SELECTED, 0x000F);
}
I have checked MSDN, online help and all the books I can get my hands on -
without luck. Any help would be really appreciated!!
Nancy Enright
nenright@idea.com
-----From: Nancy Enright
I found the answer: I call CDisplayPg::SetListCtrlSyle() at the end of
OnInitDialog. It sets LVS_SHOWSELALWAYS so that the CListCtrl selection shows
even if the control does not have the focus.
void CDisplayPg::SetListCtrlSyle()
{
LONG lStyle;
// set the LVS_SHOWSELALWAYS so that the selection shows even if the
// control does not have the focus.
// color
lStyle = GetWindowLong (m_pListColorMono->m_hWnd, GWL_STYLE);
lStyle |= LVS_SHOWSELALWAYS;
SetWindowLong (m_pListColorMono->m_hWnd, GWL_STYLE, lStyle);
// cols
lStyle = GetWindowLong (m_pListCols->m_hWnd, GWL_STYLE);
lStyle |= LVS_SHOWSELALWAYS;
SetWindowLong (m_pListCols->m_hWnd, GWL_STYLE, lStyle);
// graphs
lStyle = GetWindowLong (m_pListGraphics->m_hWnd, GWL_STYLE);
lStyle |= LVS_SHOWSELALWAYS;
SetWindowLong (m_pListGraphics->m_hWnd, GWL_STYLE, lStyle);
}
Chuck McCorvey -- chuckm@solutionware.com
Wednesday, May 08, 1996
You migth want to use CWnd::ModifyStyle() in your solution rather than the GetWindowLong/SetWindowLong sequence...
----------
From: Nancy Enright[SMTP:Nancy_Enright.IDEA@idea.com]
Sent: Friday, May 03, 1996 1:07 PM
To: mfc-l
Subject: CListCtrl::SetItemState
[Mini-digest: Question with answer]
Using VC++ 4.1, Win 95.
I have 3 CListCtrls on a Wizard Page. Each control has two items with
icons and labels. There is nothing else in the dialog box. Using:
m_pList->SetItemState(0,LVIS_SELECTED, 0x000F); I am able to set the
default to the first item in the first control during OnInitDialog.
But I am unable to set the default in the other two controls using the
same approach. Any ideas?
More details: The return from all three calls to SetItemState is OK.
SetItemState maps to SetItem in AFXCMN.INL. I have traced into
CListCtrl::SetItem and checked all of the LV_ITEM values and the
control handle passed in. Everything looks fine. CListCtrl::SetItem
calls ::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi); I have
verified that the messages were sent and received using Spy++. Here is
the code that I call at the end of OnInitDialog. The first call works
but the second and third do not.
...code omitted...
I found the answer: I call CDisplayPg::SetListCtrlSyle() at the end of
OnInitDialog. It sets LVS_SHOWSELALWAYS so that the CListCtrl selection shows
even if the control does not have the focus.
void CDisplayPg::SetListCtrlSyle()
{
LONG lStyle;
// set the LVS_SHOWSELALWAYS so that the selection shows even if the
// control does not have the focus.
// color
lStyle = GetWindowLong (m_pListColorMono->m_hWnd, GWL_STYLE);
lStyle |= LVS_SHOWSELALWAYS;
SetWindowLong (m_pListColorMono->m_hWnd, GWL_STYLE, lStyle);
... extra code omitted
}
| Вернуться в корень Архива
|