您的位置:首页 > 其它

Setting the Pen or Brush Color

2013-05-08 07:54 295 查看
Setting the Pen or Brush Color
The following example shows how an application can change the DC pen color by using the GetStockObject function or SetDCPenColor and the SetDCBrushColor functions.

HGDIOBJ original = NULL;

//Save original object.
original = SelectObject(hdc,GetStockObject(DC_PEN));

//Change the DC pen color
SetDCPenColor(hdc,RGB(0x00,0xff,0x00));
Rectangle(0,0,20,20);
SetDCPenColor(hdc,RGB(0x00,0x00,0xff));
Rectangle(0,0,20,20);

// The brush color can be changed in a similar manner. SetDCPenColor 
// and SetDCBrushColor can be used interchangeably with GetStockObject 
// to change the current color.  

SelectObject(hDC,GetStockObject(DC_BRUSH));
SetDCBrushColor(hDC,RGB(0x00,0x00,0x00)); 

// Provides the same flexibility as:

SelectObject(hDC,GetStockObject(BLACK_BRUSH));

//Restore original object.
SelectObject(hDc,original);

// It is not necessary to call DeleteObject to delete stock objects.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐