- /*
- 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堆空間
獲取圖形對象的屬性及選入新的圖形對象
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.