ListCtrl的字体颜色如果直接通过SetTextColour设置的话会改变所有行的字体颜色,sdk的对话框工程想要改变ListCtrl的某一行颜色需要注意一下几点:
1.在ListCtrl的父窗口响应WM_NOTIFY消息。
2.处理WM_NOTIFY的NM_CUSTOMDRAW消息,处理完之后通过SetWindowLong设置对话框返回结果。
3.处理完返回结果后对话框的回调函数要返回1。
具体代码如下:
VOID OnNotify(HWND hdlg, WPARAM wp, LPARAM lp) { NMHDR *header = (LPNMHDR)lp; if (s_dev_list == header->hwndFrom && NM_CUSTOMDRAW == header->code) { LPNMLISTVIEW pnm; pnm = (LPNMLISTVIEW)lp; if(pnm->hdr.hwndFrom == s_dev_list && pnm->hdr.code == NM_CUSTOMDRAW) { SetWindowLong(hdlg, DWL_MSGRESULT, long(TableDraw(lp))); } } } BOOL CALLBACK MainProc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) { int ret = 0; switch(msg) { case WM_INITDIALOG: { OnInitDialog(hdlg); } break; case WM_NOTIFY: { OnNotify(hdlg, wp, lp); ret = 1; } break; case WM_CLOSE: EndDialog(hdlg, 0); break; default: break; } return ret; }
原文地址:http://blog.csdn.net/u011391040/article/details/41483743