- /*
- 2:获取图形对象的属性及选入新的图形对象
- 应用程序可以使用函数GetCurrentObject和GetObject来获得图形对象的属性。前者
- 用于返回唯一标识刚刚被选入到DC中的图形对象的句柄,后者会返回一个描述图形对象
- 属性的结构体。
- 下面的例子演示了程序如何获得画刷的属性并通过与其相关的信息来决定是否有必要重新
- 选入一个新的画刷。
- */
- HDC hdc; // display DC handle
- HBRUSH hbrushNew, hbrushOld; // brush handles
- HBRUSH hbrush; // brush handle
- LOGBRUSH lb; // logical-brush structure
- //通过此函数获得当前画刷的句柄
- hbrush = GetCurrentObject(hdc, OBJ_BRUSH);
- //根据画刷的句柄来获取与其相关的信息,放之于一个结构体中
- GetObject(hbrush, sizeof(LOGBRUSH), &lb);
- // If the current brush is not a solid-black brush,
- // replace it with the solid-black stock brush.
- if ((lb.lbStyle != BS_SOLID)
- || (lb.lbColor != 0x000000))
- {
- hbrushNew = GetStockObject(BLACK_BRUSH);
- hbrushOld = SelectObject(hdc, hbrushNew);
- }
- // Perform painting operations with the white brush.
- // After completing the last painting operation with the new
- // brush, the application should select the original brush back
- // into the device context and delete the new brush.
- // In this example, hbrushNew contains a handle to a stock object.
- // It is not necessary (but it is not harmful) to call
- // DeleteObject on a stock object. If hbrushNew contained a handle
- // to a brush created by a function such as CreateBrushIndirect,
- // it would be necessary to call DeleteObject.
- //用完新选入的图形对象后的常规处理,重新选入默认的并删除新创建的。
- SelectObject(hdc, hbrushOld); //重新选入默认的对象
- DeleteObject(hbrushNew); //删除新对象,释放GDI堆空间