效果图:
代码:
- LONG OnPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- RECT rect;
- int nSmooth;
- LOGFONT If;
- HFONT hFontNew,hFontOld;
- //定义要显示的内容
- TCHAR str[] = TEXT("show a Shadow Text");
- //获得系统设备环境
- hdc = BeginPaint(hWnd,&ps);
- //获得窗体区域
- GetClientRect(hWnd,&rect);
- //初始化自定义字体结构
- memset(&If,0,sizeof(LOGFONT));
- //设置字体圆滑显示
- nSmooth =1000;
- //设置系统参数信息
- SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST,0,&nSmooth,TRUE);
- //设置字体的显示质量
- If.lfQuality = CLEARTYPE_QUALITY;
- //设置字体的倾斜度
- If.lfEscapement = 450;
- //创建自定义字体
- hFontNew = CreateFontIndirect(&If);
- //选入到设备环境
- hFontOld = (HFONT) SelectObject(hdc,hFontNew);
- //设置背景模式
- SetBkMode(hdc,TRANSPARENT);
- //设置颜色为红色
- SetTextColor(hdc,RGB(0xff,0x00,0x00));
- //绘制文字
- DrawText(hdc,str,-1,&rect,DT_VCENTER | DT_CENTER | DT_SINGLELINE);
- //移动矩形区域
- OffsetRect(&rect,-2,-2);
- //重新设置字体颜色为黑色
- SetTextColor(hdc,RGB(0,0,0));
- DrawText(hdc,str,-1,&rect,DT_VCENTER | DT_CENTER | DT_SINGLELINE);
- //清楚使用过的资源
- SelectObject(hdc,hFontOld);
- DeleteObject(hFontNew);
- //释放设备环境
- EndPaint(hWnd,&ps);
- return 0;
- }