1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
void DrawText(string strText,int PosX=0, int PosY=0)
{
// geting the text rectangle
RECT r = { 0, 0, 0, 0 };
char *text=(char*)strText.c_str();
//change the position of the text
::DrawText(HBitmap, text, -1,&r,DT_LEFT | DT_EXPANDTABS | DT_CALCRECT);
r.left+=PosX;
r.top+=PosY;
r.bottom+= PosX;
r.right+= PosY;
SetBkMode(HBitmap,TRANSPARENT);
//draw the text
HBRUSH hBackBrush=imgBrush;
HBRUSH oldBrush=(HBRUSH)SelectObject(HBitmap,hBackBrush);
HPEN hBackPen=(HPEN)imgPen;
HPEN oldPen=(HPEN)SelectObject((HDC)HBitmap,hBackPen);
HFONT hFont=CreateFontIndirect(chFont.lpLogFont);
HFONT holdfont=(HFONT)SelectObject((HDC)HBitmap,hFont);
SetTextColor(HBitmap,chFont.rgbColors);
::DrawText(HBitmap, text, -1,&r,DT_LEFT | DT_EXPANDTABS);
SelectObject(HBitmap,holdfont);
DeleteBrush(hFont);
SelectObject(HBitmap,oldBrush);
DeleteBrush(hBackBrush);
SelectObject(HBitmap,oldPen);
DeleteBrush(hBackPen);
}
|