Create a device-independent bitmap image brush and draw a rectangle using the paint brush.
HRSRC hRes; <br/> HGLOBAL hData, hLockedData; <br/> CBrush brush; <br/> CDC * pDC = new CClientDC (this ); <br/> // Determines the location of a resource with the specified type and name in the specified module. <br/> hRes =: FindResource (AfxGetResourceHandle (), MAKEINTRESOURCE (IDB_BMP), RT_BITMAP); <br/> if (NULL! = HRes) <br/>{< br/> // Loads the specified resource into global memory. <br/> hData =: LoadResource (AfxGetResourceHandle (), hRes); <br/> if (NULL! = HData) <br/>{< br/> // Locks the specified resource in memory. <br/> hLockedData = (HGLOBAL): LockResource (hData); <br/> if (NULL! = HLockedData) <br/>{< br/> // Creates a logical brush that has the pattern specified by the specified device-independent bitmap (DIB ). <br/> brush. createDIBPatternBrush (hLockedData, DIB_RGB_COLORS); <br/> CBrush * pOldBrush = pDC-> SelectObject (& brush); <br/> pDC-> Rectangle (10, 10,300,200 ); <br/> pDC-> SelectObject (pOldBrush); <br/> brush. deleteObject (); <br/> // Decrements (decreases by one) the reference count of a loaded resource. <br/> // When the reference count reaches zero, the memory occupied by the resource is freed. <br/>: FreeResource (hLockedData); </p> <p >}< br/> delete pDC; <br/> pDC = NULL;
Bitmap used:
Drawn rectangle: