WTL自绘CListViewCtrl

来源:互联网 发布:网络硬盘 免费 编辑:程序博客网 时间:2024/05/09 00:44
//自绘的控件从CWindowImpl和COwnerDraw 继承class CListViewCtrlEx : public CWindowImpl<CListViewCtrlEx,CListViewCtrl>,public COwnerDraw<CListViewCtrlEx>
void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/){// must be implementedATLASSERT(FALSE);}void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct){if(lpMeasureItemStruct->CtlType != ODT_MENU){HWND hWnd = GetDlgItem(lpMeasureItemStruct->CtlID);CClientDC dc(hWnd);TEXTMETRIC tm = { 0 };dc.GetTextMetrics(&tm);lpMeasureItemStruct->itemHeight = tm.tmHeight+30;}elselpMeasureItemStruct->itemHeight = ::GetSystemMetrics(SM_CYMENU);}int CompareItem(LPCOMPAREITEMSTRUCT /*lpCompareItemStruct*/){// all items are equalreturn 0;}void DeleteItem(LPDELETEITEMSTRUCT /*lpDeleteItemStruct*/){// default - nothing}

m_listCtrl.SubclassWindow(GetDlgItem( IDC_LIST1 ));m_listCtrl.ModifyStyle(0, LVS_OWNERDRAWFIXED);

REFLECT_NOTIFICATIONS() //消息反射通知宏 必须要加的
原创粉丝点击