代码是将输入的文字保存为bmp,并不在dc中显示
CString text = "abcd1123";
RECT rect;
rect.left = 0;
rect.right = 0;
rect.top = 0;
rect.bottom = 0;
HDC hDC = ::GetDC(NULL);
HDC hdcImage;
HDC hdcMEM;
hdcMEM = CreateCompatibleDC(hDC);
hdcImage = CreateCompatibleDC(hDC);
TEXTMETRIC tm;
GetTextMetrics(hdcMEM, &tm);
rect.right = tm.tmAveCharWidth * strlen(text);
rect.bottom = tm.tmHeight;
CImage image;
HBITMAP bmp = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
image.Create(rect.right, rect.bottom, 24);
::SelectObject(hdcMEM, bmp);
::SelectObject(hdcImage, image);
RECT rt;
rt.bottom = 0;
rt.left = 0;
rt.right = 0;
rt.top = 0;
// DrawText(hdcMEM, text, strlen(text), &rt, DT_SINGLELINE|DT_LEFT| DT_CALCRECT);
// DrawText(hdcMEM, text, strlen(text), &rt, DT_SINGLELINE|DT_LEFT);
Rectangle(hdcMEM, 0, 0, 100, 100);
TextOut(hdcMEM, 0, 0, text, strlen(text));
::StretchBlt(hdcImage, 0, 0, rect.right, rect.bottom, hdcMEM, 0, 0, rect.right, rect.bottom, SRCCOPY);
image.Save("e:\\1234.bmp");