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.

Can someone please give me some guidance as to where to start researching
this?

thanks

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



Re: Create a bitmap from a CString by a

a
Fri Dec 12 17:59:23 CST 2003

Hi.

Maybe you can try this.

create a buffer in memory with a bitmap in it
draw some text in there
save bitmap data to file

I dont know all the details of how you want to do this, but generaly
you'll need to read about the following APIs :

CreateCompatibleDC
CreateCompatibleBitmap
SelectObject
DrawText

as far as dumping bitmap data to a file, i saw a routine in MSDN called:
SaveBitmapFile

If you are using MFC all the way you'll need to figure out the alternative
functions.

Since this a graphics related post, i would like to suggest a news group
that might
have more help for you : microsoft.public.win32.programmer.gdi

cya