函數(shù)SetTextColor()設(shè)置方法淺析
來源:程序員人生 發(fā)布時(shí)間:2015-04-10 08:22:49 閱讀次數(shù):4224次
函數(shù)SetTextColor聲明以下:
WINGDIAPI COLORREF WINAPI SetTextColor(__in HDC hdc, __in COLORREF color);
hdc是當(dāng)前裝備的句柄。
color是設(shè)置當(dāng)前裝備字符輸出色彩。
調(diào)用這個(gè)函數(shù)的例子以下:
#001 //
#002 //界面顯示輸出.
#006 void CCaiWinMsg::OnDraw(HDC hDC)
#007 {
#008 //
#009 std::wstring strShow(_T("C++窗口類的實(shí)現(xiàn),2007-08⑴3"));
#010 TextOut(hDC,10,10,strShow.c_str(),(int)strShow.length());
#011
#012 //設(shè)置輸出字符串的色彩.
#013 COLORREF crOld = SetTextColor(hDC,RGB(255,0,0));
#014 TextOut(hDC,10,30,strShow.c_str(),(int)strShow.length());
#015
#016 SetTextColor(hDC,RGB(0,255,0));
#017 TextOut(hDC,10,50,strShow.c_str(),(int)strShow.length());
#018
#019 SetTextColor(hDC,RGB(0,0,255));
#020 TextOut(hDC,10,70,strShow.c_str(),(int)strShow.length());
#021
#022 //
#023 SetTextColor(hDC,crOld);
#024 }
第13行設(shè)置字符的色彩為紅色。
第16行設(shè)置字符的色彩為綠色。
第19行設(shè)置字符的色彩為藍(lán)色。
第23行恢復(fù)原來的色彩,這個(gè)1定要記得做,否則后面顯示會(huì)出錯(cuò)。

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)