Re: problem iterating over list view items



Steve <sss@xxxxxxx> wrote:
> Using this code:
> <code>
> LVITEM item;
> item.mask = /*LVIF_STATE|*/LVIF_TEXT;
> HWND hList = GetDlgItem(hDlg, IDC_LIST_CHARACTERS);
> int n = ListView_GetItemCount(hList);
> while(ListView_GetItem(hList, &item) == TRUE)
> {
> if(item.state&LVIS_SELECTED)
> {
> // this item is selected
> int y = 5;
> }
> }
> </code>
>
> I am trying to determine if an item is selected. Before I can even
> get that far, I need to get the code that loops through the items to
> work.
> my call(debugging) to ListView_GetItemCount() return 2
> I am inserting/setting the items with the LVIF_TEXT flag.
>
> ListView_GetItem() macro returns FALSE. I've set the correct mask
> (LVIF_TEXT) so I don't understand why it's not getting valid results?

You need to set LVITEM::iItem to the index of the item you are trying to
retrieve, and iSubItem to zero (unless you actually want to retrieve a
subitem). Further, since you are requesting the text of the item, you
need to have pszText point to a buffer and cchTextMax specify the size
of this buffer in characters. Further still, since you have not
requested LVIF_STATE, you have no business checking item.state field -
it was not retrieved and contains garbage.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • implementation details
    ... template class ) ... Retrieve then I'd like to implement some sort of overrun check. ... BUFFER(); ... unsigned int retrieve_count; ...
    (comp.lang.cpp)
  • Re: problem iterating over list view items
    ... >> LVITEM item; ... > retrieve, and iSubItem to zero (unless you actually want to retrieve a ... Further, since you are requesting the text of the item, you ... > of this buffer in characters. ...
    (microsoft.public.vc.language)
  • Re: Simulink store/retrieve values during simulation
    ... Is there really no way that you can store and retrieve data values during a simulink simulation like you can do with a written loop in an standard m-file? ... or in the signal processing blockset look at the buffer or delay line blocks. ...
    (comp.soft-sys.matlab)
  • Serializing a data buffer from C++
    ... The buffer contains some fixed header fields followed by zero or more 'rows' ... The problem that I see is that the serialization process adds contextual ... All of the methods used to retrieve fields from the ... object rather than a raw binary stream. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: GetAsyncKeyState(vKey) & 0x8000
    ... isn't there a function to retrieve a keypress from the ... so the buffer remains 'empty', ... i'm writing a 3d engine. ... out the DirectX docs and groups for a definitive answer. ...
    (microsoft.public.vc.language)

Loading