一个单文挡多视图问题 CUpView2,CFileInfoView都是继承CListView,现在要实现点击
CUpView2中一Item,就能把该Item中所有内容显示在CFileInfoView上。我的问题是不知道如何得到Item的内容,然后通过SendMessage(,,XXX)传递。XXX应该怎么实现!以下是部分程序!请帮忙!void CUpView2::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
// TODO: Add your control notification handler code here
CListCtrl* pList=&GetListCtrl();
POSITION pos = pList->GetFirstSelectedItemPosition();
    if (pos == NULL)
TRACE0("No items were selected!\n");
    else
{
while (pos)
{
int nItem = pList->GetNextSelectedItem(pos);
                        TRACE1("Item %d was selected!\n", nItem);
                        // you could do your own processing on nItem here

                        //##########################

需要插入代码
                        //##########################                        CMainFrame* pMain = (CMainFrame *) AfxGetMainWnd();
                        CFileInfoView* pView = (CFileInfoView *)(pMain->m_wndSplitter2.GetPane(1,0)); pView->SendMessage(WM_MYMESSAGE,0,NULL);//NULL需要修改 }
} *pResult = 0;
}

解决方案 »

  1.   

    SetItemData()和GetItemData()//这里设置的不仅仅是文本,数值,而且可以是结构体信息。
    再把获得DWORD数据作为WPARAM发送出去。
      

  2.   

    请问cxjlw(老为) ,SetItemData()和GetItemData()怎么用?不太理解这两个函数和返回值
      

  3.   

    返回的是DWORD类型的,我要CString 类的数据!能转吗?
      

  4.   

    方法一:需要做的是,保存一个结构数组,每次根据点击的Item的Index ,取数组里的数据显示出来。
    方法二: 同样还是保存结构数组(或者链表),并且把链表,或数组的每个元素的首地址用SetItemData() 保存在每个Item里面,然后点击后取了Index 以后取 ItemData, 取出来直接用它的首地址访问该结构。
      

  5.   

    GetItemData()和SetItemData()处理的是每个Item的一个不可见的参数。一般用来绑定特定的数据到Item。
    另外,如果要对CListCtrl对象进行排序操作,必须保证每个Item有一个唯一的ItemData。因为MFC在对CListCtrl排序的时候需要用ItemData来定位每个Item。
      

  6.   

    定义了一个结构,编译时通过 ,运行时却出现“MFC42。DLL”错误。请指教!很急!
      

  7.   

    就是添加该结构
    typedef struct tagItemData
    {
    int type;
    CString filename;
    DWORD filesize;
    int bl;
    DWORD speed;
    int threadnum;
    CString url;
    BOOL suc; 
    CString intro;
    float dwtime;
    }ItemData;
    出现的问题
      

  8.   

    请教winthegame那么应如何把保存起来又提取出来的DWORD类型参数转换为我的那个结构呢?程序就在这里死掉。
    以下是部分代码
    void CUpView2::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    // TODO: Add your control notification handler code here
    CListCtrl* pList=&GetListCtrl();
    POSITION pos = pList->GetFirstSelectedItemPosition();
        if (pos == NULL)
    TRACE0("No items were selected!\n");
        else
    {
    while (pos)
    {
    int nItem = pList->GetNextSelectedItem(pos);
                TRACE1("Item %d was selected!\n", nItem);
                // you could do your own processing on nItem here
       CMainFrame* pMain = (CMainFrame *) AfxGetMainWnd();
                CFileInfoView* pView = (CFileInfoView *)(pMain->m_wndSplitter2.GetPane(1,0));
                //MessageBox("send message");
    pView->SendMessage(WM_MYMESSAGE,nItem,NULL);
                
    }
    } *pResult = 0;
    }
      

  9.   

    void CUpView2::SaveItem(int iItem, CString localfile, DWORD filesize, DWORD speed, CString url, BOOL suc, CString intro,float dwtime,BOOL sResume)
    {
    //保存结构数组

    pItem[iItem]->filename=localfile;
    pItem[iItem]->filesize=filesize;

    pItem[iItem]->speed=speed;

    pItem[iItem]->url=url;
    pItem[iItem]->suc=suc;
    pItem[iItem]->intro=intro;
    pItem[iItem]->dwtime=dwtime;
    pItem[iItem]->sResume=sResume;
    MessageBox("save succeed");
    DWORD dwData=(DWORD)pItem[iItem];
    GetListCtrl().SetItemData(iItem,dwData);
    }以下是接收消息的那个视图类函数void CFileInfoView::OnShow(WPARAM wParam, LPARAM lParam)
    { CMainFrame* pMain = (CMainFrame *) AfxGetMainWnd();
        CUpView2* pView = (CUpView2 *)(pMain->m_wndSplitter2.GetPane(0,0));
        CListCtrl* pList=&GetListCtrl();
    DWORD dwData=pList->GetItemData(wParam);


    MyItemData *pItem;
    pItem=(MyItemData *)dwData;

    if(pItem->suc)
    {
    MessageBox("0");
    CString str;
        str.Empty();
        str=pItem->url;
        GetListCtrl().SetItemText(0,1,str);
           
        str.Empty();
        str=pItem->filename;
        GetListCtrl().SetItemText(1,1,str);
            
        str.Empty();
        str.Format("%d Byte",pItem->filesize);
        GetListCtrl().SetItemText(4,1,str);

    if(pItem->sResume)
    GetListCtrl().SetItemText(5,1,"支持");
    else
    GetListCtrl().SetItemText(5,1,"不支持");     str.Empty();
        str=pItem->intro;
        GetListCtrl().SetItemText(6,1,str); str.Empty();
    str.Format("%d s",pItem->dwtime*0.25);
    GetListCtrl().SetItemText(7,1,str);
            
    str.Empty();
    str.Format("%d KB/s",pItem->speed*4/1000);
    GetListCtrl().SetItemText(8,1,str);
    }}
    结构定义如下typedef struct tagItemData
    {
    CString filename;
    DWORD filesize;
    DWORD speed;
    CString url;
    BOOL suc; 
    CString intro;
    float dwtime;
    BOOL sResume;
    }MyItemData;
      

  10.   

    请大侠帮忙!是不是SetItemData() ,GetItemData()用错了?编译连接都行。运行到OnShow函数的if(pItem->suc)就中奖!很急!拜托!
      

  11.   

    昨天玩去了,今天才看见. 不好意思, 偶看了看, 第一个,你的SaveItem 在哪儿调用的,偶不知道啊. 你这样会出现空指针的, 弹个框出来显示什么 access 什么 0x000000000 什么的乱七八糟的东西啊.
    能不能说明一下你的 SaveItem 在哪里调用的呢? 能看看你调用SaveItem  的代码吗? 偶估计你可能没有保存数据, 或者数据保存以后生存期太短,已经释放了。 
      

  12.   

    pItem指向的对象还在吗?pItem指向的对象应该是new出来的,或者是CUpView2的成员变量。
    指针对象的有效性可以用IsBadCodPtr()检查。
      

  13.   

    void CUpView2::AddItem(int type, CString filename, DWORD filesize, int bl, DWORD speed, int threadnum, CString url, BOOL suc, CString intro,float dwtime,CString localfile,BOOL sResume)
    {
    CListCtrl* pListCtrl=&GetListCtrl();

    int iItem = pListCtrl->GetNextItem(0,LVNI_BELOW);

    //添加状态
    switch(type)
    {
    case 0:
    pListCtrl->SetItemText(iItem,0,"未开始");
    break;
    case 1:
    pListCtrl->SetItemText(iItem,0,"下载中");
    break;
    case 2:
    pListCtrl->SetItemText(iItem,0,"已完成");
                 // ##########################
    SaveItem(iItem,localfile,filesize,speed,url,suc,intro,dwtime,sResume);
                 // ##########################
                      break;
    case 3:
    pListCtrl->SetItemText(iItem,0,"未完成");
    }
    //添加文件名
    pListCtrl->SetItemText(iItem,1,filename);
    //添加文件大小
    CString str;
    str.Empty();
    str.Format("%d KB",filesize/1000);
    pListCtrl->SetItemText(iItem,2,str);
    //添加已下文件比率
        str.Empty();
    str.Format("%d ",bl*100);
    pListCtrl->SetItemText(iItem,3,str);
    //添加下载速率
    str.Empty();
    str.Format("%d KBps" ,speed*4/1000);
    pListCtrl->SetItemText(iItem,4,str);
    //添加已用时
        str.Empty();
    str.Format("%d s",dwtime*0.25);
    pListCtrl->SetItemText(iItem,5,str);
    //添加剩余时间
    //添加线程数
    str.Empty();
    str.Format("%d",threadnum);
    pListCtrl->SetItemText(iItem,7,str);
    //添加目标url
    pListCtrl->SetItemText(iItem,8,url);
    //添加有无错误
    if(suc !=TRUE)
    pListCtrl->SetItemText(iItem,9,"出错");
    else
    pListCtrl->SetItemText(iItem,9,"");
    //添加注释
    pListCtrl->SetItemText(iItem,10,intro);
    }
      

  14.   

    用winthegame(120斤重的大青蛙)的第一种方法,已经成功!