Windows interface: oncustomdraw sets the text font color and background color of any line of clistctrol.

Source: Internet
Author: User

1. First, use classwizard to create a clistctrl derived class and add the following to the header file message response function:

// Generated message map Functions
Protected:
// {Afx_msg (cscanfilelist) //} afx_msg
Afx_msg void oncustomdraw (nmhdr * pnmhdr, lresult * presult );

Declare_message_map ()

2. Add the class implementation file accordingly:

Begin_message_map (cscanfilelist, clistctrlex)
// {Afx_msg_map (cscanfilelist)
...
On_policy_reflect (nm_customdraw, oncustomdraw)
...
//} Afx_msg_map
End_message_map ()

3. function implementation:

Void cscanfilelist: oncustomdraw (nmhdr * pnmhdr, lresult * presult)
{
Nmlvcustomdraw * plvcd = reinterpret_cast <nmlvcustomdraw *> (pnmhdr );
 
// Take the default processing unless we
// Set this to something else below.
* Presult = cdrf_dodefault;
 
// First thing-check the draw stage. If it's the control's prepaint
// Stage, then tell windows we want messages for every item.
 
If (cdds_prepaint = plvcd-> nmcd. dwdrawstage)
{
* Presult = cdrf_policyitemdraw;
}
Else if (cdds_itemprepaint = plvcd-> nmcd. dwdrawstage)
{

// Only compare the text here. Note: Index = plvcd-> nmcd. dwitemspec
If (getitemtext (plvcd-> nmcd. dwitemspec, 2) = m_lpszencrypt)
{
Plvcd-> clrtext = RGB (255, 0, 0 );
Plvcd-> clrtextbk = RGB (255, 0, 0 );
}

// Tell windows to paint the control itself.
* Presult = cdrf_dodefault;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.