Windows Practice_闹钟(四)_GDI对象概述
来源:互联网 发布:java api文档在哪里 编辑:程序博客网 时间:2024/05/22 14:07
GDI对象概述
在使用GDI绘制的时候,我们需要注意两套坐标体系,一个是对于当前界面程序的原点坐标,一个是对于桌面(系统)的原点坐标。
所以以后在看到和DC相关的函数时,它都代表和DC有关的坐标,比如TExtOut函数,它的就是和DC相关的函数。
TextOut在指定位置输出指定长度的字符串。函数原型如下:
BOOL TextOut( _In_ HDC hdc, _In_ int nXStart, _In_ int nYStart, _In_ LPCTSTR lpString, _In_ int cchString);
DrawText在指定矩形区域格式化文本,根据指定的方式格式化文本。
函数原型如下:
int DrawText( _In_ HDC hDC, _Inout_ LPCTSTR lpchText, _In_ int nCount, _Inout_ LPRECT lpRect, _In_ UINT uFormat);
简单的例子
case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); // TODO: 在此处添加使用 hdc 的任何绘图代码... // 画线的函数 // TextOut // DrawText() 更多的是在标签上面写字符串,它会随着 RECT rectClient = { 0 }; GetClientRect(hWnd, &rectClient); std::wstring wstrBuffer = L"七夕快乐"; COLORREF oldColor = SetTextColor(hdc, RGB(255, 0, 0)); LOGFONT font = { 0 }; font.lfWidth = 40; font.lfHeight = 80; font.lfCharSet = GB2312_CHARSET; wcscpy_s(font.lfFaceName, L"宋体"); HFONT hFont = CreateFontIndirect(&font); HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); HBRUSH hbrush = CreateHatchBrush(HS_CROSS, RGB(0, 0, 0)); //HBRUSH hbrush = CreateSolidBrush(RGB(0, 0, 0)); HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, hbrush); //SelectObject(hdc, GetStockObject(HOLLOW_BRUSH)); //SelectObject(hdc, GetStockObject(NULL_PEN)); //SelectObject(hdc, GetStockObject(BLACK_PEN)); DrawText(hdc, wstrBuffer.c_str(), wstrBuffer.length(), &rectClient, DT_CENTER | DT_VCENTER | DT_SINGLELINE); Ellipse(hdc, rectClient.left, rectClient.top, rectClient.right, rectClient.bottom); SetTextColor(hdc, oldColor); SelectObject(hdc, hOldFont); SelectObject(hdc, oldBrush); DeleteObject(hFont); DeleteObject(hbrush); // 画点的函数 //SetPixel() SetPixel(hdc, 100, 100, RGB(0, 0, 0)); // 阴影 EndPaint(hWnd, &ps); }
通过这个小示例我们基本了解了一些GDI对象。其中包括字体、画笔、画刷(包括系统画刷以及自定义的画刷)等GDI对象。需要注意的是,这些我们创建的GDI对象都需要我们手动的去释放掉,否则会造成内存泄漏。
虽然GDI目前不是很流行了,但是我们还是需要了解这些基础的绘制方法,这对于以后学习其它的绘制工具。
阅读全文
1 0
- Windows Practice_闹钟(四)_GDI对象概述
- Windows Practice_闹钟(五)_GDI绘制工具
- Windows Practice_闹钟(六)_控件对象
- Windows Practice_闹钟(三)_作业讲解和GDI概述
- Windows Practice_闹钟(一)_简易记事本
- Windows Practice_闹钟(二)_简易记事本
- Windows Practice_文件搜索器(四)_封装文件扫描器
- (四)javascript 对象概述
- Windows Practice_文件搜索器(一)递归
- Windows Practice_文件搜索器(二)_多线程调试
- Windows Practice_文件搜索器(三)_线程池
- Windows Practice_文件_内存映射(一)
- Windows Practice_文件_文件分割器(一)
- Windows Practice_文件_文件分割器(二)
- Windows Practice_文件_文件分割器(三)
- 面向对象(小闹钟)
- 图形编程基础_GDI对象基类
- Windows Practice_文件_文件基础操作
- Windows Practice_闹钟(二)_简易记事本
- react-native 一种简明构建复杂三元运算逻辑的方法
- PHP基础(一) 表单传值 以及 文件上传
- yii2.0.12
- Windows Practice_闹钟(三)_作业讲解和GDI概述
- Windows Practice_闹钟(四)_GDI对象概述
- Python中的join()函数的用法
- 我的TI之路
- python—如何使用post进行登录操作与非对称加密的破解
- 从CRP(关键渲染路径)优化中谈浏览器渲染原理
- python 指定版本号
- HashMap
- Mysql动态操作表或者列
- PHP post数据传输部分缺失