VC之列表控制項背景色設定

2021-06-29 14:30:53 字數 2729 閱讀 6259

本文簡單介紹下vc程式中list列表控制項的背景設定。

首先,新建對話方塊應用程式,然後新增兩個list列表控制項

自定義clistctrl類並重寫列表oncustomdraw函式。

在mfc中找不到nm_customdraw,只好手動新增了。

標頭檔案

protected:

//}afx_msg

private:

colorref m_colrow1;

colorref m_colrow2;

原始檔

cmylistctrl::cmylistctrl()

cmylistctrl::~cmylistctrl()

begin_message_map(cmylistctrl, clistctrl)

//}afx_msg_map

end_message_map()

/// cmylistctrl message handlers

void cmylistctrl::oncustomdraw(nmhdr *pnmhdr, lresult *presult)

// modify item text and or background

case cdds_itemprepaint:

// modify sub item text and/or background

case cdds_subitem | cdds_prepaint | cdds_item:

else

*presult = cdrf_dodefault;

return;

} }}

標頭檔案

protected:

//}afx_msg

private:

colorref m_colrow1;

colorref m_colrow2;

原始檔

cmylistctrl2::cmylistctrl2()

cmylistctrl2::~cmylistctrl2()

begin_message_map(cmylistctrl2, clistctrl)

//}afx_msg_map

end_message_map()

/// cmylistctrl2 message handlers

bool cmylistctrl2::onerasebkgnd(cdc* pdc)

//onerasebkgnd和onpaint一起設定整個大的背景

vc 設定控制項的背景色

過載onctlcolor函式,這個是必須的 設定控制項的背景顏色 第一 afx msg hbrush onctlcolor cdc pdc,cwnd pwnd,uint nctlcolor 在標頭檔案中宣告 在主檔案中 第二 begin message map cok1dlg,cdialog afx...

EDIT控制項設定字型,背景色

截獲wm ctlcolorstatic訊息 gdiplus bitmap pbitmap gdiplus bitmap cmiuiutils loadimage idb png license bg if pbitmap null lresult onctlcolor uint umsg wpara...

MFC 控制項背景色

由於需要,要講groupbox控制項和文字控制項static的背景色設為一致。onctrlcolor中設定groupbox背景色 if pwnd getdlgctrlid idc g if pwnd getdlgctrlid idc static1 設定後效果 有個白色背景不符合要求 需要新增此句 ...