Click here to Skip to main content
12,302,493 members (63,336 online)
Rate this:
 
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
kyleK89363
Edited 29-Nov-12 2:05am
v2
Comments
Richard MacCutchan 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160530.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2016
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