1、
static HPEN hPen1, hPen2, hPen3 ;
hPen1 = CreatePen (PS_SOLID, 1, 0) ;
hPen2 = CreatePen (PS_SOLID, 3, RGB (255, 0, 0)) ;
hPen3 = CreatePen (PS_DOT, 0, 0) ;
SelectObject (hdc, hPen2) ;
在处理WM_DESTROY期间,删除画笔:
DeleteObject (hPen1) ;
2、
新建画笔并选入设备句柄
SelectObject (hdc, CreatePen (PS_DASH, 0, RGB (255, 0, 0))) ;
因为SelectObject将新画笔选入设备句柄后,会返回原有画笔句柄,所以可以用此句柄来删除上面建立的画笔
DeleteObject (SelectObject (hdc, GetStockObject (BLACK_PEN))) ;
3、
原理同上
hPen = SelectObject (hdc, CreatePen (PS_DASH, 0, RGB (255, 0, 0))) ;
DeleteObject (SelectObject (hdc, hPen)) ;
Other:
如果有一个画笔的句柄,就可以通过呼叫GetObject取得LOGPEN结构各个成员的值:
GetObject (hPen, sizeof (LOGPEN), (LPVOID) &logpen) ;
如果需要目前选进设备内容的画笔句柄,可以:
hPen = GetCurrentObject (hdc, OBJ_PEN) ;