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.

SelectObject(hdc,GetStockObject(DC_PEN));
SetDCPenColor(hdc,RGB(00,0xff;00);
Rectangle(0,0,20,20);
SetDCPenColor(hdc,RGB(00,00,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,0x0) 

// Provides the same flexability as:

SelectObject(hDC,GetStockOBject(BLACK_BRUSH));

// It is not necessary to call DeleteObject to delete stock objects.