bghuang_ 2024-01-22 09:32 采纳率: 0%
浏览 9

CTreeCtrl::InsertItem()和CListCtrl::InsertItem()被重复调用

CTreeCtrl::InsertItem()和CListCtrl::InsertItem()被重复调用
这是使用VC6++MFC开发的数据恢复工具,检查文件(夹)时插入的条目出现部分重复。移植到VS2019情况依旧。

img

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2024-01-22 12:15
    关注

    【以下回答由 GPT 生成】

    ### 问题描述
    我正在进行使用VC6++MFC开发的数据恢复工具,发现在检查文件(夹)时,CTreeCtrl::InsertItem()和CListCtrl::InsertItem()被重复调用,导致插入的条目出现部分重复的情况。我已经尝试将代码移植到VS2019,但问题依旧存在。我想知道可能的原因和解决方法。
    
    ### 问题标签
    c++, VC6, MFC, VS2019
    
    ### 相关信息
    - 已尝试移植到VS2019,问题依旧存在。
    - 使用的是VC6++MFC开发的数据恢复工具。
    - 问题出现在检查文件(夹)时,插入的条目出现部分重复。
    

    解决这个问题可能有几个原因,我列出了一些可能的解决方法:

    1. 检查插入数据的来源,确保每个数据只被插入一次。
    2. 确认在插入数据之前是否检查是否已经存在相同的数据,如果存在则不要重复插入。
    3. 检查插入数据的代码,确保不会在不需要的情况下重复调用InsertItem()。

    以下是一个简单的示例代码来检查和插入数据:

    // Some code to retrieve and insert data into CTreeCtrl
    HTREEITEM hFoundItem = m_treeCtrl.FindItem(hParent, szItemText); // Check if the item already exists
    if (hFoundItem == NULL) {
        // Item not found, insert it
        m_treeCtrl.InsertItem(szItemText, hParent);
    } else {
        // Item found, do something else or just ignore
    }
    
    // Some code to retrieve and insert data into CListCtrl
    int nIndex = m_listCtrl.FindItem(-1, dwData); // Check if the item already exists
    if (nIndex == -1) {
        // Item not found, insert it
        m_listCtrl.InsertItem(LVIF_TEXT | LVIF_PARAM, nItem, szText, 0, 0, 0, (LPARAM)dwData);
    } else {
        // Item found, do something else or just ignore
    }
    

    请尝试检查代码是否满足上述条件,并根据需要修改。希望这些方法能帮助你解决问题。



    【相关推荐】


    • 这篇博客: MFC 树形控件CTreeCtrl类中的 在树形控件中插入一个新节点:InsertItem() 部分也许能够解决你的问题。

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 1月22日