15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Can't SetItemStatus in dialog

Asila Salem -- ASalem_Ideal@nets.com.jo
Tuesday, March 04, 1997

Environment: VC++ 4.0, Windows 95

Hello.
It seem that there is a problem with programmatically setting the status of
an item in a list control in a dialog.
I'm displaying a CListCtrl in a modal dialog, in which I (try to) change
items' user-defined status and display the corresponding status icon.
When I call SetItemState for an item in the corresponding member list
control, I check with GetItemState that it has been set correctly. As soon as
a call to UpdateData(TRUE) or UpdateData(FALSE) is made, the item status is
reset to a value which I've never set(*).

The debugging sessions led to the following:

  //m_lcStatusList is the member variable mapped
  // to the list control in the dialog.
CListCtrl m_lcStatusList;

int nStatus = 0x00002000;
m_lcStatusList.SetItemState(nItem, LVIS_STATEIMAGEMASK, nStatus);
nStatus = m_lcStatusList.GetItemState(nItem , LVIS_STATEIMAGEMASK);
  //nStatus is still 0x00002000;
UpdateData(FALSE);
nStatus = m_lcStatusList.GetItemState(nItem , LVIS_STATEIMAGEMASK);
  //nStatus becomes 0x00003000(*)

So I try the following:

CListCtrl* plcDlgCtrl = (CListCtrl*) GetDlgItem(IDC_STATUSLIST);
nStatus = plcDlgCtrl->GetItemState(nItem, LVIS_STATEIMAGEMASK);
  //nStatus is 0x00003000
nStatus = 0x00002000;
plcDlgCtrl->SetItemState(nItem, LVIS_STATEIMAGEMASK, nStatus);
  //nStatus is 0x00002000
nStatus = plcDlgCtrl->GetItemState(nItem, LVIS_STATEIMAGEMASK);
  //nStatus is 0x00003000(*)

The debugger shows that the status of the item in plcDlgCtrl never changes.
I'm I doing something wrong?




Oksana Lien -- lien@ares.csd.net
Wednesday, March 05, 1997

[Mini-digest: 2 responses]

To set a state of a list control item to - for instance - LVIS_DROPHILITED,
do this:

m_YourListCtrl.SetItemState(index, LVIS_DROPHILITED, LVIS_DROPHILITED);

VC++ documentation is not clear at all about this, but the second argument
of the function - state bit values - has to match the bit values in the
third argument, the mask. Couldn't they just tell it to us in the documentation?


At 08:31 AM 3/4/97 GMT, you wrote:
>>CListCtrl m_lcStatusList;
>
>int nStatus = 0x00002000;
>m_lcStatusList.SetItemState(nItem, LVIS_STATEIMAGEMASK, nStatus);
>nStatus = m_lcStatusList.GetItemState(nItem , LVIS_STATEIMAGEMASK);
>  //nStatus is still 0x00002000;
>UpdateData(FALSE);
>nStatus = m_lcStatusList.GetItemState(nItem , LVIS_STATEIMAGEMASK);
>  //nStatus becomes 0x00003000(*)
_________________________
Oksana Lien
Dimension Softek, Inc.
lien@ares.csd.net

-----From: ASalem_Ideal@nets.com.jo (Asila Salem)

Far from UNDERSTANDING, I TRIED this and it DID work:
  
CListCtrl* plcDlgCtrl = (CListCtrl*) GetDlgItem(IDC_STATUSLIST);
LV_ITEM lvItem;
lvItem.iItem = nItem;
lvItem.mask = LVIF_STATE;
lvItem.stateMask =  LVIS_STATEIMAGEMASK;
lvItem.state = nStatus;
plcDlgCtrl ->SetItem(&lvItem);
UpdateData(TRUE);

So, for some reason, GetItemState() does not work on CListCtrl in a dialog,
one should use SetItem() instead.

Asila Salem
ASalem_Ideal@nets.com.jo




Become an MFC-L member | Вернуться в корень Архива |