在列表视图中打印选定的项目

在列表视图中打印选定的项目

本文介绍了在列表视图中打印选定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;





实际上,可以在列表视图中选择子项目.但是,在我添加了上面的代码之后,子项目变成了不可选择的行.我要做的是当用户单击子项"1"时在editbox(hMlb)中设置文本.此源代码怎么了?





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?

推荐答案

//LI.iItem=nlv->iItem;
//LI.iSubItem=1;
//ListView_GetItem(hMlb,&LI);



如果确实需要调用ListView_GetItem,则需要指定掩码.在使用C结构之前,对它们进行ZeroMemory也是一个好主意.

在旁注中,似乎您分配nlv=(LPNMLISTVIEW)lParam;的时间过早.建议您在case LVN_ITEMCHANGED:行之后将此行进一步下移.



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.


这篇关于在列表视图中打印选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:59