Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ API
case WM_NOTIFY:
    LPNMHDR hdr;
    LPNMLISTVIEW nlv;
     
    hdr=(LPNMHDR)lParam;
    nlv=(LPNMLISTVIEW)lParam;
    if(hdr->hwndFrom==hMlb)
    {
        switch(hdr->code)
        {
        case LVN_ITEMCHANGED:
            if(nlv->uChanged==LVIF_STATE&&nlv->uNewState==(LVIS_SELECTED|LVIS_FOCUSED))
            {
            
                LI.iItem=nlv->iItem;
                LI.iSubItem=1;
                ListView_GetItem(hMlb,&LI);
                
                ListView_GetItemText(hMlb,nlv->iItem,1,buf,20);
                SetDlgItemText(hwnd,IDM_mtitle,buf);
            }
            return TRUE;
        }
    }
    break;

 

Actually, subitem was selectable in listview. But, after I added above code, subitem changed into non-selectable line. What I gonna do is that set text in editbox(hMlb) when user click subitem '1'. what's wrong with this source code?
Posted 29-Nov-12 2:00am
kyleK89356
Edited 29-Nov-12 2:05am
v2
Comments
Richard MacCutchan at 29-Nov-12 8:15am
   
What's wrong with this source code? Well it needs better use of spaces between operators and operands; other than that I have no idea. Maybe you could give us some more clues.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If the code above is complete then it looks like you have not specified the mask before calling ListView_GetItem. This, together with the fact that you haven't "ZeroMemoried" the LI variable means that mask can be anything. If it happens that mask contains LVIF_TEXT flag by any chance then you may easily corrupt your memory.
 
So, the solution in your case will be to comment these three lines like this (what's the purpose of them anyway?):
 
                //LI.iItem=nlv->iItem;
                //LI.iSubItem=1;
                //ListView_GetItem(hMlb,&LI);
 
If you really need to call ListView_GetItem you need to specify mask. It is also always a good idea to ZeroMemory the C structs before using them.
 
On the side note, it looks like that you assigning nlv=(LPNMLISTVIEW)lParam; too early. I recommend you moving this line further down after case LVN_ITEMCHANGED: line.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Sergey Alexandrovich Kryukov 196
3 Mika Wendelius 185
4 CPallini 170


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100