I need to Display some text on to the screen using GDI Textout. Using the following code displays the text on the screen but immediately disappears.Can any one correct me where i am going wrong
What I have tried:
Amount1 = "Rs.*******.**"
m_hdc = ::GetDC(0);
m_nXPos = m_nYPos = 0;
if(m_hdc)
{
m_nXPos = ::GetDeviceCaps(m_hdc,HORZRES)/2;
m_nYPos = ::GetDeviceCaps(m_hdc,VERTRES)/2;
}
m_nXPos = m_nXPos - 100;
DisplayAmount(m_hdc,m_nXPos,m_nYPos,(LPSTR)(LPCTSTR)Amount1);
DisplayAmount(m_hdc,m_nXPos,m_nYPos,(LPSTR)(LPCTSTR)Amount1);
/*Method Defination*/
DisplayAmount(HDC hdc,int XPos, int YPos, char* amount)
{
if(!hdc) return -1;
const COLORREF colorRed = RGB(255,255,255);
HFONT hfont;
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
logFont.lfHeight = -48; // see PS
logFont.lfWeight = FW_NORMAL;
strcpy(logFont.lfFaceName, "Zurich BT");
hfont = CreateFontIndirect(&logFont);
COLORREF oldTextColor = SetTextColor(hdc, colorRed);
SetBkMode(hdc, TRANSPARENT);
HFONT oldHFont = (HFONT)SelectObject(hdc, hfont);
TextOut(hdc, XPos, YPos, amount, strlen(amount));
// restore text color and font
SelectObject(hdc, oldHFont);
SetTextColor(hdc, oldTextColor);
return 0;
}