问题描述
我需要使用GDI Textout在屏幕上显示一些文本。使用下面的代码显示屏幕上的文字,但立即消失。任何人都可以纠正我的错误
我尝试了什么:
金额1 =卢比。*******。**
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);
/ *方法定义* /
DisplayAmount(HDC hdc,int XPos,int YPos,char * amount)
{
如果(!hdc)返回-1;
const COLORREF colorRed = RGB (255,255,255);
HFONT hfont;
LOGFONT logFont;
memset(& logFont,0, sizeof(logFont));
logFont.lfHeight = -48; //见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));
//恢复文字颜色和字体
SelectObject(hdc,oldHFont);
SetTextColor(hdc,oldTextColor);
返回0;
}
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;
}
推荐答案
这篇关于使用GDI的textout在屏幕上显示文本并消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!