创建与设备无关的位图画刷,并利用这个画刷绘制一个矩形。 HRSRC hRes; HGLOBAL hData, hLockedData; CBrush brush; CDC *pDC = new CClientDC(this); // Determines the location of a resource with the specified type and name in the specified module. hRes = ::FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BMP), RT_BITMAP); if (NULL != hRes) { // Loads the specified resource into global memory. hData = ::LoadResource(AfxGetResourceHandle(), hRes); if (NULL != hData) { // Locks the specified resource in memory. hLockedData = (HGLOBAL)::LockResource(hData); if (NULL != hLockedData) { // Creates a logical brush that has the pattern specified by the specified device-independent bitmap (DIB). brush.CreateDIBPatternBrush(hLockedData, DIB_RGB_COLORS); CBrush *pOldBrush = pDC->SelectObject(&brush); pDC->Rectangle(10, 10, 300, 200); pDC->SelectObject(pOldBrush); brush.DeleteObject(); // Decrements (decreases by one) the reference count of a loaded resource. // When the reference count reaches zero, the memory occupied by the resource is freed. ::FreeResource(hLockedData); } } } delete pDC; pDC = NULL; 使用的位图: 绘制的矩形: