Re: Create a bitmap from a CString by Igor
Igor
Fri Dec 12 16:37:58 CST 2003
"Mofongo" <123@aol.com> wrote in message
news:GgrCb.7951$Dt6.271300@twister.tampabay.rr.com...
> I need to be able to create a bitmap from a user input string. To
make
> matters more complicated I need the bitmap to be created font
specific.
Pseudocode:
LPCTSTR string; // user input
HFONT hfont = CreateFont(...); // create font as desired
HDC hdcScreen = GetDC(0);
HFONT hfontOld = (HFONT)SelectObject(hdcScreen, hfont);
SIZE sz;
GetTextExtentPoint32(hdcScreen, string, lstrlen(string), &sz);
SelectObject(hdcScreen, hfontOld);
HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, sz.cx, sz.cy);
HDC hdcMem = CreateCompatibleDC(hdcScreen);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbm);
hfontOld = (HFONT)SelectObject(hdcMem, hfont);
TextOut(hdcMem, 0, 0, string, lstrlen(string));
SelectObject(hdcMem, hfontOld);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
ReleaseDC(0, hdcScreen);
DeleteObject(hfont);
// Here, hbm is a handle to the desired bitmap
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken