HDC = getdc (null); // 1.
HDC hmemdc;
Hbitmap, holdbitmap;
Rect;
Unsigned char * pbits = NULL;
Colorref clrtext = RGB (0, 0 );
Int nwidth, nbpp = 1; // 1bit per pixel
Int nwidthpixel, nheightpixel, ntotalwidth, ntotalheight;
DWORD dwbytesperrow;
Bitmapinfo BMP Info;
Tchar tsztext [1, 256] = {0 ,};
Nwidthpixel = nheightpixel = font_size;
Ntotalwidth = strlen (pstring) * nwidthpixel;
Ntotalheight = nheightpixel;
Hmemdc = createcompatibledc (HDC); // 2
Rect. Left = 0;
Rect. Top = 0;
Rect. Right = ntotalwidth;
Rect. Bottom = ntotalheight;
Setbkmode (hmemdc, transparent );
Settextcolor (hmemdc, clrtext );
Mbstowcs (tsztext, pstring, strlen (pstring ));
// Get the real height and width
Drawtext (hmemdc, tsztext,-1, & rect, dt_calcrect | dt_left | dt_singleline );
Ntotalwidth = rect. right-rect.left;
Ntotalheight = rect. bottom-rect.top;
Dwbytesperrow = widthbytes (ntotalwidth * nbpp );
BMP info. bmiheader. bibitcount = nbpp;
BMP info. bmiheader. biclrimportant = 0;
BMP info. bmiheader. biclrused = 0;
BMP info. bmiheader. bicompression = 0;
BMP info. bmiheader. biheight = ntotalheight;
BMP info. bmiheader. biplanes = 1;
BMP info. bmiheader. bisize = sizeof (bitmapinfoheader );
BMP info. bmiheader. bisizeimage = dwbytesperrow * ntotalheight;
BMP info. bmiheader. biwidth = dwbytesperrow <3;
BMP info. bmiheader. bixpelspermeter = 0;
BMP info. bmiheader. biypelspermeter = 0;
BMP info. bmicolors [0]. rgbblue = 255;
BMP info. bmicolors [0]. rgbgreen = 255;
BMP info. bmicolors [0]. rgbred = 255;
BMP info. bmicolors [0]. rgbreserved = 0;
BMP info. bmicolors [1]. rgbblue = 0;
BMP info. bmicolors [1]. rgbgreen = 0;
BMP info. bmicolors [1]. rgbred = 0;
BMP info. bmicolors [1]. rgbreserved = 0;
Hbitmap = createdibsection (HDC,
& BMP info,
Dib_rgb_colors,
(Void **) & pbits,
Null,
0 );
If (hbitmap)
{
Hbitmap holdbmp;
Memset (pbits, 0, BMP info. bmiheader. bisizeimage );
Holdbmp = (hbitmap) SelectObject (hmemdc, hbitmap );
Rect. Left = 0;
Rect. Top = 0;
Rect. Right = ntotalwidth;
Rect. Bottom = ntotalheight;
Drawtext (hmemdc, tsztext,-1, & rect, dt_left | dt_singleline | dt_noclip );
/*
* Do Something Based on hbitmap buffer --- pbits
*/
SelectObject (hmemdc, holdbmp); // holdbmp = (hbitmap) SelectObject (hmemdc, hbitmap );
}
Deleteobject (hbitmap );
Deletedc (hmemdc); // createcompatibledc (HDC );
Releasedc (null, HDC );