This test works for me with 1 bpp bitmap =>
int nWidth = 256, nHeight = 256;
COLORREF clrBackground = RGB(0, 0, 255);
COLORREF clrForeground = RGB(255, 255, 0);
HBITMAP hBitmap = CreateMonochromeBitmap(nWidth, nHeight, clrBackground, clrForeground);
HDC hDC = GetDC(NULL);
HDC hDCMem = CreateCompatibleDC(hDC);
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDCMem, hBitmap);
RECT rc = { 0, 0, nWidth, nHeight };
SetTextColor(hDCMem, clrForeground);
SetBkColor(hDCMem, clrBackground);
DrawText(hDCMem, L"This is a test", -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
for (int i = 10; i <= nWidth - 10; i++)
SetPixel(hDCMem, i, 10, clrForeground);
// Test copy bitmap on screen
BitBlt(hDC, 0, 0, nWidth, nHeight, hDCMem, 0, 0, SRCCOPY);
SelectObject(hDCMem, hBitmapOld);
DeleteDC(hDCMem);
DeleteObject(hBitmap);
ReleaseDC(NULL, hDC);
Utility function :
HBITMAP CreateMonochromeBitmap(int cx, int cy, COLORREF clrBackground, COLORREF clrForeground)
{
struct
{
BITMAPINFOHEADER bi;
RGBQUAD bmiColors[2];
} dib = { 0 };
dib.bi.biSize = sizeof(dib.bi);
dib.bi.biWidth = cx;
dib.bi.biHeight = cy;
dib.bi.biPlanes = 1;
dib.bi.biBitCount = 1;
dib.bi.biCompression = BI_RGB;
dib.bmiColors[0].rgbBlue = GetBValue(clrBackground);
dib.bmiColors[0].rgbGreen = GetGValue(clrBackground);
dib.bmiColors[0].rgbRed = GetRValue(clrBackground);
dib.bmiColors[1].rgbBlue = GetBValue(clrForeground);
dib.bmiColors[1].rgbGreen = GetGValue(clrForeground);
dib.bmiColors[1].rgbRed = GetRValue(clrForeground);
HBITMAP hBitmap = NULL;
HDC hDC = CreateCompatibleDC(NULL);
if (hDC)
{
hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)&dib, DIB_RGB_COLORS, NULL, NULL, 0);
DeleteDC(hDC);
}
return hBitmap;
}