Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:15:13+00:00 2026-06-04T05:15:13+00:00

I’m working on a win32/MFC project. I have a custom CListCtrl control that I

  • 0

I’m working on a win32/MFC project.
I have a custom CListCtrl control that I must to add, from time to time, some strings of characters.
I absolutely need to perform some manipulations on items dynamically added to my CListCtrl.

Ultra-Basically, I need to:

  1. Detect adding of single elements;
  2. Retrieve _single items_ IMMEDIATELY AFTER(ideally, shortly after InsertItem() invocation);
  3. Store values of single items in a map, which I will use to perform other manipulations.

I thought about doing this overriding the method DrawItem(). but OnDraw event seems not to be available for my CListCtrl.

Event is never generated.

IMPORTANT: Please note that MyCustomCListCtrl have “On Draw Fixed” property set to True, but “View” property is NOT set as a report.

So, I have decided to handle NW_CUSTOMDRAW event, writing my CustomDraw Handler, as explained here and here:

Here you can view another code example.

Then, I need a way to retrieve single itemIDs from my CListCtrl.
More precisely, I need a way to get single item IDs from NMHDR struct.

How can I do this?
I am only able to obtain the ID of the LAST item that I have added.
I am sure it’s a simple mistake I can’t find.

A sample piece of code below:

Source of Dialog that contains CList Ctrl:

/* file MyDlg.cpp */

#include "stdafx.h"
#include "MyDlg.h"

// MyDlg dialog

IMPLEMENT_DYNAMIC(MyDlg, CDialog)

MyDlg::MyDlg(CWnd* pParent)
    : CDialog(MyDlg::IDD, pParent)
{
}

MyDlg::~MyDlg()
{
}

void MyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST1, listView); /* listView is a MyCustomCListCtrl object */
}

BEGIN_MESSAGE_MAP(MyDlg, CDialog)
    ON_BN_CLICKED(IDC_BUTTON1, &MyDlg::OnBnClickedButton1) 
END_MESSAGE_MAP()

BOOL MyDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    return TRUE;
}

/* OnBnClickedButton1 handler add new strings to MyCustomCListCtrl object */

void MyDlg::OnBnClickedButton1()
{
    listView.InsertItem(0, "Hello,");
    listView.InsertItem(1, "World!");
}

My Custom CList Ctrl source:

/* file MyCustomCListCtrl.cpp */

#include "stdafx.h"
#include "MyCustomCListCtrl.h"

MyCustomCListCtrl::MyCustomCListCtrl()
{
}

MyCustomCListCtrl::~MyCustomCListCtrl()
{
}

BEGIN_MESSAGE_MAP(MyCustomCListCtrl, CListCtrl)
    //{{AFX_MSG_MAP(MyCustomCListCtrl)
    //}}AFX_MSG_MAP
    // ON_WM_DRAWITEM()                             /* WM_DRAWITEM NON-AVAILABLE */
    ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
END_MESSAGE_MAP()

// 'Owner Draw Fixed' property is already TRUE
/*  void CTranslatedCListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    bool inside = true; /* Member function removed: I never enter here... */
}  */

void MyCustomCListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    /* Here, I must retrieve single strings added to my MyCustomCListCtrl object */

    LPNMLISTVIEW plvInfo = (LPNMLISTVIEW)pNMHDR;
    LVITEM lvItem;

    lvItem.iItem = plvInfo->iItem;          /* Here I always get _the same_ ID: ID of last element...*/
    lvItem.iSubItem = plvInfo->iSubItem;    // subItem not used, for now...

    int MyID = 0;

    this->GetItem(&lvItem); // There mai be something error here?
    MyID = lvItem.iItem;

    CString str = this->GetItemText(MyID, 0); /* ...due to previous error, here I will always get the last string I have added("World!") */

    // Immediately after obtaining ALL IDS, I can Do My Work

    *pResult = 0;
}

Any help is appreciated!

P.S.
Please do not give me tips like:

  1. Set your “Own Draw Fixed” Property to True;
  2. Check you have inserted the line “ON_WMDRAWITEM()”
  3. Convert your CListCtrl as a report;

I have already tried everything… 🙂

Thanks to all!

IT

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:15:14+00:00Added an answer on June 4, 2026 at 5:15 am

    first of all… Thank you wasted your precious time with this stupid question.
    I never found anything about LVN_INSERT event.
    I write scientific software(most on Linux platform); I am not a long-time Win32 developer, so I don’t know Win32 APIs in depth.
    I have modified source file of MyCustomCListCtrl class, as you have suggested.
    Code below seems to be the best( and faster )way to achieve what I want:

        /* file MyCustomCListCtrl.cpp */
    
        #include "stdafx.h"
        #include "MyCustomCListCtrl.h"
    
        MyCustomCListCtrl::MyCustomCListCtrl()
        {
        }
    
        MyCustomCListCtrl::~MyCustomCListCtrl()
        {
        }
    
        BEGIN_MESSAGE_MAP(MyCustomCListCtrl, CListCtrl)
            //{{AFX_MSG_MAP(MyCustomCListCtrl)
            //}}AFX_MSG_MAP
            ON_NOTIFY_REFLECT(LVN_INSERTITEM, OnLvnInsertItem)
        END_MESSAGE_MAP()
    
        ...
    
        afx_msg void CTranslatedListCtrl::OnLvnInsertItem(NMHDR* pNMHDR, LRESULT* pResult)
        {
            LPNMLISTVIEW plvInfo = (LPNMLISTVIEW)pNMHDR;
            CString str = this->GetItemText(plvInfo->iItem, 0);
    
            // Add Some Logic
    
            *pResult = 0;
        }
    

    Can You confirm?
    From what I can see, it seems to work. 🙂
    Thanks again!

    IT

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.