>>253 >This is because temporary and permanent Windows handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads. HDC等もハンドルマップを持ってるから、同様な問題があるよ。
void CMyView::OnDraw( CDC* pDC ) { CPen penBlack; // Construct it, then initialize if( newPen.CreatePen( PS_SOLID, 2, RGB(0,0,0) ) ) { // Select it into the device context // Save the old pen at the same time CPen* pOldPen = pDC->SelectObject( &penBlack );
// Draw with the pen pDC->MoveTo(...); pDC->LineTo(...);
// Restore the old pen to the device context pDC->SelectObject( pOldPen ); } else { // Alert the user that resources are low } }