I have been trying to put text onto a bitmap before the bitmap is put to the screen.
I have been searching and trying to program this in C++ for a few days and I do not have it working.
I can now put text onto a bitmap, but the text has a white background.
I load the bitmap as a device independent bitmap and then I want to put this text onto the bitmap before I show the bitmap on the screen.
No Visual Studio and no .net please.
Please tell me if your answer requires an additional header file beyond what make this work as it is.
What I have tried:
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC_of_MainWindow = BeginPaint(hwnd, &ps);
Draw_From_FRONT_BUFFER_001_To_MainWindow();
ADD_TEXT_to_Graph(hwnd, ps.hdc);
HDC buffDC = CreateCompatibleDC(HDC_of_MainWindow);
SetTextColor(buffDC, RGB(0, 0, 0));
SetBkColor(buffDC, RGB(255, 255, 255));
RECT rc;
GetClientRect(hwnd, &rc);
HDC_of_MainWindow = GetDC( Handle_of_MainWindow );
HBITMAP buffBitmap = CreateCompatibleBitmap( HDC_of_MainWindow, rc.right, rc.bottom );
if(buffBitmap == NULL)
{
MessageBox(nullptr,L"failed to create buffBitmap",L"Error!",MB_ICONEXCLAMATION | MB_OK);
}
int savedDC = SaveDC(buffDC);
SelectObject(buffDC, buffBitmap);
HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
FillRect(buffDC, &rc, hBrush);
DeleteObject(hBrush);
TextOut(buffDC, 10, 10, L"Test Text", 9);
BitBlt(HDC_of_MainWindow, 0, 0, rc.right, rc.bottom, buffDC, 0, 0, SRCCOPY);
RestoreDC(buffDC, savedDC);
DeleteObject(buffBitmap);
DeleteDC(buffDC);
return 0;
}
break;
and I am trying this
void ADD_TEXT_to_Graph(HWND hwnd, HDC dc)
{
RECT rc;
GetClientRect(hwnd, &rc);
DrawText(dc, L"Hello!\r\nLine Number 2", -1, &rc, DT_CENTER|DT_VCENTER|DT_WORDBREAK);
}
I see Hello! centered and at the top of my bitmap that they are in front of.
I see Line Number 2 below that and centered.
Both have black text and a white background.
I am trying to get rid of the white background and to be able to see the bitmap that is behind them.
No Visual Studio and no .net please.
Please tell me if your answer requires an additional header file beyond what make this work as it is.
Thank you.