Search code examples
c++winapigdi

Can a Pattern Brush fill any rectangle in win32?


Ok now suppose I have a Bitmap, called smile.bmp.

And then I load the bitmap with a width of 100px and a height of 100px.

HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,
                     L"C:/MyImages/smile.bmp",
                     IMAGE_BITMAP,
                     100 /*Width of Image*/,
                     100 /*Height of Image*/,
                     LR_LOADFROMFILE);
// Loading the Bitmap with a width and height of 100px.

And then I create a pattern brush using the Bitmap.

HBRUSH hBrush = CreatePatternBrush(hBitmap /*The Bitmap*/);

Now if I use FillRect using this brush, could I using any RECT structure? For example,

RECT rect1 = {0, 0, 200, 200};
FillRect(hdc, &rect1, hBrush);
// Would it stretch the Bitmap or not even bother drawing it?

If you can recall I loaded the Bitmap with a width and height of 100px. But now I am filling a rectangle with a width and height of 200px.


So here is my question, would it even fill the area, or would it stretch the pixels to match the area?


Solution

  • It will tile the brush pattern to fill the area. The documentation shows an example.