I. Modify the background color and font color
① Create a project based on the dialog box, name it test, and add a ListBox control to the dialog box.
② Add a member variable in testdlg. h: hbrush m_hbrush;
③ In oninitdialog (), add m_hbrush = createsolidbrush (RGB (, 0). The RGB value set here can change the background color of ListBox. To view the color changes of the words in the ListBox, add a few words to the ListBox: Use the Class Wizard to add a control type member variable m_ctrllistbox To The ListBox, and then add the following to oninitdialog ():Code:
M_ctrllistbox.addstring ("first line ");
M_ctrllistbox.addstring ("second row ");
④ Click Class Wizard, add the wm_ctlcolor event to testdlg, click the edit code button, and replace the content of the function with the following code:
If (nctlcolor = ctlcolor_listbox)
{
PDC-> setbkmode (transparent );
// Set the font color here
PDC-> settextcolor (RGB (255,255,255 ));
Return m_hbrush;
}
Else
Return cdialog: onctlcolor (PDC, pwnd, nctlcolor );
Compile and run change nowProgram, You can see that the list box has become black and the word has become white!
1. Add dataM_listbox.addstring ("fadsfasdfsdaf ");
2. Calculate the number of data entriesM_listbox.getcount ();
3. Clear the list boxM_listbox.resetcontent ();
Http://blog.csdn.net/halibobo520/article/details/3372099