|
本文通过重载WM_NOTIFY消息,实现ListView外观的自定义.
实现结果为奇偶数分别采用不同的背景颜色.同时最后一列加入了一个时钟图标.
该代码为本人的GUI系统(MiniWin)在数字电视机顶盒中的部分实现代码
需要学习WIN32-API开发的人可以参考,可惜eeworld不能够上传图片
其中IDC_EPGSCHEDULE为Listview控件的ID
- case WM_NOTIFY:
- {
- NMHDR *nmhdr = (PVOID)lParam;
- if(nmhdr->code==TCN_SELCHANGE){
- DoServiceChange(hwnd);
- }
- if(nmhdr->idFrom ==IDC_EPGSCHEDULE){
- if(nmhdr->code == NM_CUSTOMDRAW) {
- NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
- SYSTEMTIME stnow;
- FILETIME ft;
- switch(nmlvcd->nmcd.dwDrawStage) {
- case CDDS_PREPAINT:
- return CDRF_NOTIFYITEMDRAW;
- case CDDS_ITEMPREPAINT:
- GetLocalTime(&stnow);
- SystemTimeToFileTime(&stnow,&ft);
- if(nmlvcd->nmcd.lItemlParam
- if(nmlvcd->nmcd.uItemState!=0)
- nmlvcd->clrTextBk =CLR_DEFAULT;
- else{
- nmlvcd->clrTextBk =RGB(200,200,200);
- }
- return CDRF_DODEFAULT;
- }
- return CDRF_NOTIFYSUBITEMDRAW;
- case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
- if(nmlvcd->nmcd.dwItemSpec%2){
- nmlvcd->clrTextBk =CLR_DEFAULT;
- }else
- nmlvcd->clrTextBk =RGB(200,200,250);
- return CDRF_NOTIFYPOSTPAINT;
- case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
- if(nmlvcd->iSubItem==3){
- BITMAP bmp;
- RECT rc=nmlvcd->nmcd.rc;
- HBITMAP hobmp,hbm=LoadBitmap(hInstDVBRes,MAKEINTRESOURCE(IDB_CLOCK));
- HDC hmdc=CreateCompatibleDC(nmlvcd->nmcd.hdc);
- hobmp=(HBITMAP)SelectObject(hmdc,(HGDIOBJ)hbm);
- GetObject((HGDIOBJ)hbm,sizeof(BITMAP),&bmp);
- BitBlt(nmlvcd->nmcd.hdc,rc.left,
- rc.top+(RECTH(&rc)-bmp.bmHeight)/2,24,24,hmdc,0,0,SRCCOPY);
- SelectObject(hmdc,(HGDIOBJ)hobmp);
- DeleteObject((HGDIOBJ)hbm);
- DeleteDC(hmdc);
- return CDRF_SKIPDEFAULT;
- }
- return CDRF_DODEFAULT;
- }
- return CDRF_DODEFAULT;
- }else if(nmhdr->code==LVN_ITEMCHANGED){
- LPNMLISTVIEW lv=(LPNMLISTVIEW)lParam;
- SetWindowLong(lv->hdr.hwndFrom,GWL_USERDATA,lv->iItem);
- }else if(nmhdr->code==LVN_KEYDOWN){
- LPNMLVKEYDOWN lk=(LPNMLVKEYDOWN)lParam;
- CHAR desc[256];
- LVITEM itm;
- itm.mask=LVIF_TEXT;
- itm.iItem=GetWindowLong(lk->hdr.hwndFrom,GWL_USERDATA);
- itm.iSubItem=3;
- itm.pszText=desc;
- itm.cchTextMax=256;
- ListView_GetItem(lk->hdr.hwndFrom,&itm);
- if(lk->wVKey==VK_RETURN)
- MessageBox(hwnd,desc,"节目简介",0);
- }
- }
- }break;
复制代码
|
|