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

  • Home
  • SEARCH
  • 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 3990628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:31:05+00:00 2026-05-20T06:31:05+00:00

I was writing an app using the Windows API, and I wanted to know

  • 0

I was writing an app using the Windows API, and I wanted to know how to make a listview with subitems that contain multi-colored text.

To clarify, here is a picture of how it is implemented in API Monitor:

Notice that in the “API” column, the text has multiple colors, like it is rich text or something. I was wondering how I would do this.

Someone told me to do something with custom-drawing, but he wasn’t sure. I looked into it, and I handled NM_CUSTOMDRAW. Here is the result of my test:

And here is the code:

inline LRESULT HandleWM_NOTIFY(LPARAM lParam)
{
   switch (((LPNMHDR)lParam)->code)
   {
      case NM_CUSTOMDRAW:
      {
         switch (((LPNMHDR)lParam)->idFrom)
         {
            case ID_LISTVIEW1:
            {
               LPNMLVCUSTOMDRAW lpNMLVCD = (LPNMLVCUSTOMDRAW)lParam;
               if (lpNMLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
               {
                  return CDRF_NOTIFYITEMDRAW;
               }
               else if (lpNMLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
               {
                  COLORREF crText;
                  switch (lpNMLVCD->nmcd.dwItemSpec % 3)
                  {
                     case 0:
                        crText = RGB(255, 0, 0);
                        break;
                     case 1:
                        crText = RGB(0, 255, 0);
                        break;
                     case 2:
                        crText = RGB(0, 0, 255);
                        break;
                  }

                  lpNMLVCD->clrText = crText;
                  lpNMLVCD->
               }

               return CDRF_DODEFAULT;
            }
            default: break;
         }

         break;
      }

      default: break;
   }

   return 0;
}

Using the NM_CUSTOMDRAW method, I can’t modify the font colors of individual characters; I can only modify the font color of everything in the subitem, which is not what I want.

How can I achieve what API monitor does? I have a feeling this is going to be very difficult, but any suggestions are welcome.

  • 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-05-20T06:31:06+00:00Added an answer on May 20, 2026 at 6:31 am

    NM_CUSTOMDRAW is the solution. Sorry to say there’s no easy solution here. You simply need to ownerdraw the text you want in different colours sequentially rather than collectively, use the GetTextExtentPoint32 API to assist in the text drawing. You return CDRF_SKIPDEFAULT to tell the listview not to render the text, you took care of it.

    if (lpNMHdr->code == NM_CUSTOMDRAW)
    {
        LPNMLVCUSTOMDRAW lpCD = (LPNMLVCUSTOMDRAW)lpNMHdr;
        if (lpCD->nmcd.dwDrawStage == CDDS_PREPAINT)
        {
            return CDRF_NOTIFYITEMDRAW;
        }
    
        if (lpCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
        {
            return CDRF_NOTIFYSUBITEMDRAW;
        }
    
        if (lpCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT|CDDS_SUBITEM))
        {
            if (lpCD->iSubItem == 0) //detect which subitem is being drawn
            {
                LPCTSTR lpcszBuf1 = _T("example");
                LPCTSTR lpcszBuf2 = _T("text");
    
                RECT iR = { 0 };
                ListView_GetSubItemRect(lpCD->nmcd.hdr.hwndFrom, lpCD->nmcd.dwItemSpec, lpCD->iSubItem, LVIR_BOUNDS, &iR);
    
                SetBkMode(lpCD->nmcd.hdc, TRANSPARENT);
    
                SIZE sz = { 0 };
                GetTextExtentPoint32(lpCD->nmcd.hdc, lpcszBuf1, 7, &sz);
    
                SetTextColor(lpCD->nmcd.hdc, RGB(255, 0, 0));                   
                DrawText(lpCD->nmcd.hdc, lpcszBuf1, -1, &iR, DT_LEFT);
    
                iR.left += sz.cx;
    
                SetTextColor(lpCD->nmcd.hdc, RGB(0, 255, 0));                   
                DrawText(lpCD->nmcd.hdc, lpcszBuf2, -1, &iR, DT_LEFT);                  
    
                return CDRF_SKIPDEFAULT;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Windows Form app that uses an API (the smartFOCUS API, to
I`m writing client-server app for windows using WinSock and I have class for server.
I'm writing my first Windows CE app using the .NET Compact Framework v3.5. I
I am writing a web app using TurboGears, and in that app the users
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually
I'm writing a java app using eclipse which references a few external jars and
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I'm writing a client-server app using BSD sockets. It needs to run in the
I am writing a simple web app using Linq to Sql as my datalayer
I've been writing a java app on my machine and it works perfectly using

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.