讓字體有陰影代碼
效果圖:
本文引用地址:http://www.ex-cimer.com/article/201609/303401.htm代碼:
LONG OnPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
int nSmooth;
LOGFONT If;
HFONT hFontNew,hFontOld;
//定義要顯示的內(nèi)容
TCHAR str[] = TEXT(show a Shadow Text);
//獲得系統(tǒng)設(shè)備環(huán)境
hdc = BeginPaint(hWnd,ps);
//獲得窗體區(qū)域
GetClientRect(hWnd,rect);
//初始化自定義字體結(jié)構(gòu)
memset(If,0,sizeof(LOGFONT));
//設(shè)置字體圓滑顯示
nSmooth =1000;
//設(shè)置系統(tǒng)參數(shù)信息
SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST,0,nSmooth,TRUE);
//設(shè)置字體的顯示質(zhì)量
If.lfQuality = CLEARTYPE_QUALITY;
//設(shè)置字體的傾斜度
If.lfEscapement = 450;
//創(chuàng)建自定義字體
hFontNew = CreateFontIndirect(If);
//選入到設(shè)備環(huán)境
hFontOld = (HFONT) SelectObject(hdc,hFontNew);
//設(shè)置背景模式
SetBkMode(hdc,TRANSPARENT);
//設(shè)置顏色為紅色
SetTextColor(hdc,RGB(0xff,0x00,0x00));
//繪制文字
DrawText(hdc,str,-1,rect,DT_VCENTER | DT_CENTER | DT_SINGLELINE);
//移動(dòng)矩形區(qū)域
OffsetRect(rect,-2,-2);
//重新設(shè)置字體顏色為黑色
SetTextColor(hdc,RGB(0,0,0));
DrawText(hdc,str,-1,rect,DT_VCENTER | DT_CENTER | DT_SINGLELINE);
//清楚使用過(guò)的資源
SelectObject(hdc,hFontOld);
DeleteObject(hFontNew);
//釋放設(shè)備環(huán)境
EndPaint(hWnd,ps);
return 0;
}
評(píng)論