Welcome

首页 / 软件开发 / VC.NET / Windows界面编程(8) listbox彩色显示隔行变色

Windows界面编程(8) listbox彩色显示隔行变色2014-01-09在CSDN论坛上看到很多询问如何设置listbox的颜色,如何让listbox隔行变色等等。因此专门写了一篇《Windows界面编程第八篇 listbox彩色显示隔行变色》来为大家解惑。

首先看看下图(如果看不到,可以通过地址http://blog.csdn.net/morewindows/article/details/8656061访问)。

要设置listbox的颜色及让listbox隔行变色主要是通过处理WM_DRAWITEM消息,这个消息在MSDN的解释如下:

The WM_DRAWITEM message is sent to the parent window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the button, combo box, list box, or menu has changed.

通过这个消息最主要可以得到一个DRAWITEMSTRUCT类型的结构体。这个结构体的原型如下:

//By MoreWindows-(http://blog.csdn.net/MoreWindows)

typedef struct tagDRAWITEMSTRUCT {

   UINTCtlType;

   UINTCtlID;

   UINTitemID;

   UINTitemAction;

   UINTitemState;

   HWNDhwndItem;

   HDChDC;

   RECT rcItem;

   ULONG_PTR itemData;

} DRAWITEMSTRUCT;