1.CPtrArray指针数组

2.CPtrArray返回void指针,需要做类型转换

3.View类中的OnPaint调用OnPrepareDC和OnDraw,如果覆盖OnPaint,就不会调用OnDraw(除非显式调用)

4.坐标空间

Coordinate Spaces and Transformations

Win32®-based applications use coordinate spaces and transformations to scale, rotate, translate, shear, and reflect graphics output. A coordinate space is a planar space that locates two-dimensional objects by using two reference axes that are perpendicular to each other. There are four coordinate spaces: world, page, device, and physical device (client area, desktop, or page of printer paper).

A transformation is an algorithm that alters ("transforms") the size, orientation, and shape of objects. Transformations also transfer a graphics object from one coordinate space to another. Ultimately, the object appears on the physical device, which is usually a screen or printer.

About Coordinate Spaces and Transformations

Coordinate spaces and transformations are used by the following types of applications:

Desktop publishing applications (to "zoom" parts of a page or to display adjacent pages in a window).

Computer-aided design (CAD) applications (to rotate objects, scale drawings, or create perspective views).

Spreadsheet applications (to move and size graphs).

The following illustrations show successive views of an object created in a drawing application. The first illustration shows the object as it appears in the original drawing; the succeeding five illustrations show the effects of applying various transformations.

Using Coordinate Spaces and Transformations

This section contains an example that demonstrates the following tasks:

Drawing graphics with predefined units.

Centering graphics in the application's client area.

Scaling graphics output to half its original size.

Translating graphics output 3/4 of an inch to the right.

Rotating graphics 30 degrees.

Shearing graphics output along the x-axis.

Reflecting graphics output about an imaginary horizontal axis drawn through its midpoint.

The following example was used to create the illustrations that appear earlier in this overview.

void TransformAndDraw(int iTransform, HWND hWnd)

{

HDC hDC;

XFORM xForm;

RECT rect;

// Retrieve a DC handle for the application's window.

hDC = GetDC(hWnd);

// Set the mapping mode to LOENGLISH. This moves the

// client area origin from the upper left corner of the

// window to the lower left corner (this also reorients

// the y-axis so that drawing operations occur in a true

// Cartesian space). It guarantees portability so that

// the object drawn retains its dimensions on any display.

SetGraphicsMode(hDC, GM_ADVANCED);

SetMapMode(hDC, MM_LOENGLISH);

// Set the appropriate world transformation (based on the

// user's menu selection).

switch (iTransform)

{

case SCALE:        // Scale to 1/2 of the original size.

xForm.eM11 = (FLOAT) 0.5;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 0.5;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case TRANSLATE:   // Translate right by 3/4 inch.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 1.0;

xForm.eDx  = (FLOAT) 75.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case ROTATE:      // Rotate 30 degrees counterclockwise.

xForm.eM11 = (FLOAT) 0.8660;

xForm.eM12 = (FLOAT) 0.5000;

xForm.eM21 = (FLOAT) -0.5000;

xForm.eM22 = (FLOAT) 0.8660;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case SHEAR:       // Shear along the x-axis with a

// proportionality constant of 1.0.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 1.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 1.0;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case REFLECT:     // Reflect about a horizontal axis.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) -1.0;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

case NORMAL:      // Set the unity transformation.

xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;

xForm.eM21 = (FLOAT) 0.0;

xForm.eM22 = (FLOAT) 1.0;

xForm.eDx  = (FLOAT) 0.0;

xForm.eDy  = (FLOAT) 0.0;

SetWorldTransform(hDC, &xForm);

break;

}

// Find the midpoint of the client area.

GetClientRect(hWnd, (LPRECT) &rect);

DPtoLP(hDC, (LPPOINT) &rect, 2);

// Select a hollow brush.

SelectObject(hDC, GetStockObject(HOLLOW_BRUSH));

// Draw the exterior circle.

Ellipse(hDC, (rect.right / 2 - 100), (rect.bottom / 2 + 100),

(rect.right / 2 + 100), (rect.bottom / 2 - 100));

// Draw the interior circle.

Ellipse(hDC, (rect.right / 2 -94), (rect.bottom / 2 + 94),

(rect.right / 2 + 94), (rect.bottom / 2 - 94));

// Draw the key.

Rectangle(hDC, (rect.right / 2 - 13), (rect.bottom / 2 + 113),

(rect.right / 2 + 13), (rect.bottom / 2 + 50));

Rectangle(hDC, (rect.right / 2 - 13), (rect.bottom / 2 + 96),

(rect.right / 2 + 13), (rect.bottom / 2 + 50));

// Draw the horizontal lines.

MoveToEx(hDC, (rect.right/2 - 150), (rect.bottom / 2 + 0), NULL);

LineTo(hDC, (rect.right / 2 - 16), (rect.bottom / 2 + 0));

MoveToEx(hDC, (rect.right / 2 - 13), (rect.bottom / 2 + 0), NULL);

LineTo(hDC, (rect.right / 2 + 13), (rect.bottom / 2 + 0));

MoveToEx(hDC, (rect.right / 2 + 16), (rect.bottom / 2 + 0), NULL);

LineTo(hDC, (rect.right / 2 + 150), (rect.bottom / 2 + 0));

// Draw the vertical lines.

MoveToEx(hDC, (rect.right/2 + 0), (rect.bottom / 2 - 150), NULL);

LineTo(hDC, (rect.right / 2 + 0), (rect.bottom / 2 - 16));

MoveToEx(hDC, (rect.right / 2 + 0), (rect.bottom / 2 - 13), NULL);

LineTo(hDC, (rect.right / 2 + 0), (rect.bottom / 2 + 13));

MoveToEx(hDC, (rect.right / 2 + 0), (rect.bottom / 2 + 16), NULL);

LineTo(hDC, (rect.right / 2 + 0), (rect.bottom / 2 + 150));

ReleaseDC(hWnd, hDC);

}

5.SetScrollSizes设置滚动条大小

第一个参数是映射模式:

6.SetMapMode可以改变映射模式

7.逻辑坐标和设备坐标转换

8. OnInitialUpdate是窗口创建完成之后第一个被调用的函数(在OnDraw之前),可以在这里设置滚动条大小

9.视口和窗口原点的改变

10.DPtoLP将设备点转换为逻辑点

11.LPtoDP将逻辑点转换为设备点

12.利用CMetaFileDC类保存与重现画布

13.CMetaFileDC::Create会创建一个源文件,如果参数为NULL,会创建一个内存文件

14.CMetaFileDC::Close方法会关闭DC,返回HMETAFILE(源文件句柄)对象

15.PlayMetaFile重现画布

16.DeleteMetaFile删除源文件

17.CopyMetaFile将源文件保存至文件

18.GetMetaFile(GetEnhMetaFile)从文件或取Meta File

19.CreateCompatibleBitmap 初始化一个位图与指定DC兼容

20.兼容DC也是内存DC,在窗口中不可见

21.

22.总结:

保存图像的三种方法:

*1.保存绘图操作步骤

*2.使用CMetaFileDC重现画布

*3.使用兼容位图,复制位图到当前DC

 用菊子曰博客,就是爽!

最新文章

  1. fenxi
  2. Links for Introduction To Calculus
  3. 扫描项目里没有使用的图片mac工具,删除没有使用的图片以减小包的体积
  4. Delphi的Win32的API调用简单介绍
  5. 10gRAC运行srvctl报错error while loading shared libraries:
  6. SSRS用自定义对象绑定报表
  7. 记录asp.net网站停止运行原因的代码
  8. MVC中的Startup.Auth.cs、BundleConfig.cs、FilterConfig.cs和RouteConfig.cs
  9. chrome浏览器tab页内存占用变大,网站变慢为哪般?
  10. 微信小程序支付及退款流程详解
  11. 零基础如何自学java开发?
  12. HTML DOM querySelector() 方法
  13. 今天刚学到truncate和delete的区别,做个总结吧
  14. echo() print() printf() print_r() 的区别
  15. 虚拟机安装linux系统无法上网的解决方法
  16. Java md5加密 控制台传入与web传入参数 结果不匹配 || 相同字符串加密结果不同,如何保证JAVA MD5加密结果在不同的环境下都相同
  17. django之admin设置
  18. 深入学习c++--左值引用和右值引用
  19. Visual Studio最常用的快捷键
  20. [SDOI2016 Round1] 数字配对

热门文章

  1. ASP.NET Web API 应用教程(一) ——数据流使用
  2. 230行实现一个简单的MVVM
  3. 【管理心得之三十二】PMP杂谈---------爱情必胜术
  4. Django的Model上都有些什么
  5. 快速入门系列--WCF--07传输安全、授权与审核
  6. 【WP开发】手电筒
  7. 【WP开发】使用磁倾仪
  8. MyEclipse使用总结——MyEclipse10安装SVN插件
  9. 拓扑排序(三)之 Java详解
  10. MySQL的学习--join和union的用法