在对话筐上滚动输出文字,经过一段时间后系统所有的中文字体不能显示为什么? 如提 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HFONT CNotesStatusDraw::CreateFont(CString strFont, int nCharHeight, int nCharWidth){ HFONT hFont; hFont= ::CreateFont( //定义字体句柄 nCharHeight, //字体高度 nCharWidth, //系统选取字体最佳宽度 0, //倾斜度为0,表示水平 0, //字体倾斜度为0 560, //字体粗度,400为正常 0, //无斜体字 0, //无下划线 0, //无删除线 ANSI_CHARSET, //所用的字符集 OUT_DEFAULT_PRECIS, //输出粗度为默认值 OUT_DEFAULT_PRECIS, //裁减粗度为默认值 DEFAULT_QUALITY, //输出质量为默认值 DEFAULT_PITCH|FF_DONTCARE, //字间距和字体系列 LPCTSTR(strFont)); //字体名称 return hFont;}void CNotesStatusDraw::DrawNotesStatus(){ HDC hbkDC,hDC,hmemDC; HBITMAP hOldBmpMem,hbkBmp,hOldBmpBk; HFONT holdFont; //定义字体句柄 PAINTSTRUCT ps; //包含绘图信息的结构体变量 RECT rcWnd,rect; SIZE size; HBRUSH hbkBrush; //定义输出的字符串 if(m_strDspValue == "") { m_nPicX = 0; m_strDspValue = m_strDspMem; //m_strDspValue = "我么阿三点放将阿联赛的经费阿三点发送到非"; } //处理绘图消息 GetWindowRect(m_hWnd,&rcWnd); hDC=BeginPaint(m_hWnd,&ps); hmemDC = CreateCompatibleDC(hDC); hbkBmp = CreateCompatibleBitmap(hDC,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top); hOldBmpMem = (HBITMAP)SelectObject(hmemDC,hbkBmp); hbkBrush = CreateSolidBrush(RGB(214,206,198)); rect.left = 0; rect.top = 0; rect.right= rcWnd.right-rcWnd.left; rect.bottom = rcWnd.bottom-rcWnd.top; FillRect(hmemDC,&rect,hbkBrush); //SelectObject(hmemDC,hOldBmpMem); //画背景 hbkDC = CreateCompatibleDC(hDC); hOldBmpBk =(HBITMAP) SelectObject(hbkDC,m_hBitmapBk); StretchBlt(hmemDC, 0, (rcWnd.bottom-rcWnd.top-m_bitmapBk.bmHeight)/2, rcWnd.right-rcWnd.left, (m_bitmapBk.bmHeight+rcWnd.bottom-rcWnd.top)/2+1, hbkDC, 0, 0, m_bitmapBk.bmWidth, m_bitmapBk.bmHeight, SRCCOPY ); SelectObject(hbkDC,hOldBmpBk); DeleteDC(hbkDC); //画字 SetTextColor(hmemDC,m_corWord); SetBkMode(hmemDC,TRANSPARENT); m_hf = CreateFont(m_strFace,m_nFontHeight,m_nFontWidth); holdFont = (HFONT)SelectObject(hmemDC,m_hf); GetTextExtentPoint32(hmemDC,m_strDspValue,m_strDspValue.GetLength(),&size); TextOut(hmemDC,-m_nPicX+rcWnd.right-rcWnd.left,(rcWnd.bottom-rcWnd.top-size.cy)/2,(LPCTSTR)m_strDspValue,m_strDspValue.GetLength()); StretchBlt(hDC,2,0,rcWnd.right-rcWnd.left-2,rcWnd.bottom-rcWnd.top,hmemDC,0,0,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top,SRCCOPY); SelectObject(hmemDC,holdFont); DeleteObject(m_hf); DeleteObject(hbkBrush); DeleteDC(hmemDC); EndPaint(m_hWnd,&ps); if(m_nPicX > size.cx + rcWnd.right-rcWnd.left) { m_nPicX = 0; m_strDspValue = ""; }}DrawNotesStatus() 运行一段时间后,画面不再滚动,我通过spy可以看到还在继续触发这个函数,请问这是为什么? 在任务管理器中看看你的GDI对象是不是一直在增加,考虑GDI泄漏 m_hf = CreateFont(m_strFace,m_nFontHeight,m_nFontWidth);里面创建字体没有删除导致资源耗尽 资源没有释放http://blog.csdn.net/bobob/archive/2005/12/29/565188.aspx 资源管理器中窗口句柄没有明显增加,createfont对象我用deleteobject删除,运行一段时间后报AVCException 错误。重新修改后的代码: void CNotesStatusDraw::DrawNotesStatus(){ HDC hbkDC,hDC,hmemDC; HBITMAP hbkBmp,holdBkBmp,holdMemBmp; // HFONT holdFont; //定义字体句柄 PAINTSTRUCT ps; //包含绘图信息的结构体变量 RECT rcWnd,rect; HBRUSH hbkBrush; BOOL bRet; try{ GetWindowRect(m_hWnd,&rcWnd); //初始化 hDC=BeginPaint(m_hWnd,&ps); if(hDC == NULL) { return; } //创建背景双缓存背景 hmemDC = CreateCompatibleDC(hDC); if(hmemDC == NULL) { DeleteDC(hmemDC); return; } hbkBmp = CreateCompatibleBitmap(hDC,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top); if(hbkBmp == NULL) { DeleteDC(hmemDC); return; } holdMemBmp = (HBITMAP)SelectObject(hmemDC,hbkBmp); hbkBrush = CreateSolidBrush(RGB(214,206,198)); if(hbkBrush == NULL) { DeleteDC(hmemDC); return; } rect.right= rcWnd.right-rcWnd.left; rect.bottom = rcWnd.bottom-rcWnd.top; rect.left = 0; rect.top = 0; FillRect(hmemDC,&rect,hbkBrush); DeleteObject(hbkBmp); DeleteObject(hbkBrush); // //画背景 hbkDC = CreateCompatibleDC(hDC); if(hbkDC == NULL) { DeleteDC(hmemDC); return; } holdBkBmp = (HBITMAP)SelectObject(hbkDC,m_hBitmapBk); bRet = StretchBlt(hmemDC, 0, (rcWnd.bottom-rcWnd.top-m_bitmapBk.bmHeight)/2, rcWnd.right-rcWnd.left, (m_bitmapBk.bmHeight+rcWnd.bottom-rcWnd.top)/2+1, hbkDC, 0, 0, m_bitmapBk.bmWidth, m_bitmapBk.bmHeight, SRCCOPY ); if(bRet == 0) { SelectObject(hbkDC,holdBkBmp); DeleteDC(hmemDC); DeleteDC(hbkDC); return ; } SelectObject(hbkDC,holdBkBmp); DeleteDC(hbkDC); //画字 SetTextColor(hmemDC,m_corWord); SetBkMode(hmemDC,TRANSPARENT); m_hf = CreateFont(m_strFace,m_nFontHeight,m_nFontWidth,m_nFontWidth); if(m_hf == NULL) { DeleteDC(hmemDC); DeleteObject(m_hf); return; } SelectObject(hmemDC,m_hf); // if(holdFont == NULL) // return; bRet = DrawNotesText(hmemDC); if(bRet == 0) { DeleteDC(hmemDC); DeleteObject(m_hf); return ; } bRet = StretchBlt(hDC,2,0,rcWnd.right-rcWnd.left-2,rcWnd.bottom-rcWnd.top,hmemDC,0,0,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top,SRCCOPY); if(bRet == 0) return ; SelectObject(hmemDC,holdMemBmp); DeleteObject(m_hf); DeleteDC(hmemDC); EndPaint(m_hWnd,&ps); } catch(CException e) { char buf[100]={0}; e.GetErrorMessage(buf,100); AfxMessageBox(buf); } }//画出滚动字符BOOL CNotesStatusDraw::DrawNotesText(const HDC &hmemDC){ POSITION pos; ITEMINFOR itemInfor; SIZE size; if(m_nMouseOver == TRUE) return FALSE; try{ //进入互斥 EnterCriticalSection(&m_criticalSection); IncreaseDisplayPos(hmemDC); //退出互斥 LeaveCriticalSection(&m_criticalSection); GetTextExtentPoint32(hmemDC,"模板",4,&size); pos = m_lstCurDisplayItem.GetHeadPosition(); while(pos) { itemInfor = m_lstCurDisplayItem.GetNext(pos); TextOut(hmemDC,itemInfor.nShowLeft,(m_rectWnd.bottom-m_rectWnd.top -size.cy+2)/2,itemInfor.strItemValue,itemInfor.strItemValue.GetLength()); } } catch (...) { CFile file; file.Open("D:\\a.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite); file.SeekToEnd(); file.Write("DrawNotesStatus error \r\n",100); file.Close(); } return TRUE ;} 关于 winsock I/O模型 简单问题求救 WinCE高手请进,难题求救:在线等待 串口通信数据处理,出现异常数据!!! 请教高手 是不是只有动态创建控件才能改变它的风格? 简单问题求教~~快来拿分啊!! 我做了一个基于对话框的程序,我想把对话框加到我的COM的DLL中,DLL注册后实现对话框的功能? 女程序员请进~~ domoal无法实现模态窗口 如何按钮界面的自定义 有关断点调试时字符串显示的问题?急!(现在线)
HFONT CNotesStatusDraw::CreateFont(CString strFont, int nCharHeight, int nCharWidth)
{
HFONT hFont;
hFont= ::CreateFont( //定义字体句柄
nCharHeight, //字体高度
nCharWidth, //系统选取字体最佳宽度
0, //倾斜度为0,表示水平
0, //字体倾斜度为0
560, //字体粗度,400为正常
0, //无斜体字
0, //无下划线
0, //无删除线
ANSI_CHARSET, //所用的字符集
OUT_DEFAULT_PRECIS, //输出粗度为默认值
OUT_DEFAULT_PRECIS, //裁减粗度为默认值
DEFAULT_QUALITY, //输出质量为默认值
DEFAULT_PITCH|FF_DONTCARE, //字间距和字体系列
LPCTSTR(strFont)); //字体名称 return hFont;
}void CNotesStatusDraw::DrawNotesStatus()
{
HDC hbkDC,hDC,hmemDC;
HBITMAP hOldBmpMem,hbkBmp,hOldBmpBk;
HFONT holdFont; //定义字体句柄
PAINTSTRUCT ps; //包含绘图信息的结构体变量
RECT rcWnd,rect;
SIZE size;
HBRUSH hbkBrush;
//定义输出的字符串
if(m_strDspValue == "")
{
m_nPicX = 0;
m_strDspValue = m_strDspMem;
//m_strDspValue = "我么阿三点放将阿联赛的经费阿三点发送到非";
}
//处理绘图消息
GetWindowRect(m_hWnd,&rcWnd); hDC=BeginPaint(m_hWnd,&ps); hmemDC = CreateCompatibleDC(hDC);
hbkBmp = CreateCompatibleBitmap(hDC,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top);
hOldBmpMem = (HBITMAP)SelectObject(hmemDC,hbkBmp);
hbkBrush = CreateSolidBrush(RGB(214,206,198));
rect.left = 0;
rect.top = 0;
rect.right= rcWnd.right-rcWnd.left;
rect.bottom = rcWnd.bottom-rcWnd.top; FillRect(hmemDC,&rect,hbkBrush);
//SelectObject(hmemDC,hOldBmpMem);
//画背景
hbkDC = CreateCompatibleDC(hDC); hOldBmpBk =(HBITMAP) SelectObject(hbkDC,m_hBitmapBk);
StretchBlt(hmemDC,
0,
(rcWnd.bottom-rcWnd.top-m_bitmapBk.bmHeight)/2,
rcWnd.right-rcWnd.left,
(m_bitmapBk.bmHeight+rcWnd.bottom-rcWnd.top)/2+1,
hbkDC,
0,
0,
m_bitmapBk.bmWidth,
m_bitmapBk.bmHeight,
SRCCOPY
); SelectObject(hbkDC,hOldBmpBk); DeleteDC(hbkDC);
//画字
SetTextColor(hmemDC,m_corWord);
SetBkMode(hmemDC,TRANSPARENT);
m_hf = CreateFont(m_strFace,m_nFontHeight,m_nFontWidth); holdFont = (HFONT)SelectObject(hmemDC,m_hf);
GetTextExtentPoint32(hmemDC,m_strDspValue,m_strDspValue.GetLength(),&size);
TextOut(hmemDC,-m_nPicX+rcWnd.right-rcWnd.left,(rcWnd.bottom-rcWnd.top-size.cy)/2,(LPCTSTR)m_strDspValue,m_strDspValue.GetLength());
StretchBlt(hDC,2,0,rcWnd.right-rcWnd.left-2,rcWnd.bottom-rcWnd.top,hmemDC,0,0,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top,SRCCOPY);
SelectObject(hmemDC,holdFont);
DeleteObject(m_hf);
DeleteObject(hbkBrush);
DeleteDC(hmemDC);
EndPaint(m_hWnd,&ps); if(m_nPicX > size.cx + rcWnd.right-rcWnd.left)
{
m_nPicX = 0;
m_strDspValue = "";
}}DrawNotesStatus() 运行一段时间后,画面不再滚动,我通过spy可以看到还在继续触发这个函数,请问这是为什么?
里面创建字体没有删除导致资源耗尽
http://blog.csdn.net/bobob/archive/2005/12/29/565188.aspx
{
HDC hbkDC,hDC,hmemDC;
HBITMAP hbkBmp,holdBkBmp,holdMemBmp;
// HFONT holdFont; //定义字体句柄
PAINTSTRUCT ps; //包含绘图信息的结构体变量
RECT rcWnd,rect;
HBRUSH hbkBrush;
BOOL bRet;
try{
GetWindowRect(m_hWnd,&rcWnd);
//初始化
hDC=BeginPaint(m_hWnd,&ps);
if(hDC == NULL)
{
return;
}
//创建背景双缓存背景
hmemDC = CreateCompatibleDC(hDC);
if(hmemDC == NULL)
{
DeleteDC(hmemDC);
return;
}
hbkBmp = CreateCompatibleBitmap(hDC,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top);
if(hbkBmp == NULL)
{
DeleteDC(hmemDC);
return;
}
holdMemBmp = (HBITMAP)SelectObject(hmemDC,hbkBmp);
hbkBrush = CreateSolidBrush(RGB(214,206,198));
if(hbkBrush == NULL)
{
DeleteDC(hmemDC);
return;
}
rect.right= rcWnd.right-rcWnd.left;
rect.bottom = rcWnd.bottom-rcWnd.top;
rect.left = 0;
rect.top = 0;
FillRect(hmemDC,&rect,hbkBrush);
DeleteObject(hbkBmp);
DeleteObject(hbkBrush);
//
//画背景
hbkDC = CreateCompatibleDC(hDC);
if(hbkDC == NULL)
{
DeleteDC(hmemDC);
return;
}
holdBkBmp = (HBITMAP)SelectObject(hbkDC,m_hBitmapBk);
bRet = StretchBlt(hmemDC,
0,
(rcWnd.bottom-rcWnd.top-m_bitmapBk.bmHeight)/2,
rcWnd.right-rcWnd.left,
(m_bitmapBk.bmHeight+rcWnd.bottom-rcWnd.top)/2+1,
hbkDC,
0,
0,
m_bitmapBk.bmWidth,
m_bitmapBk.bmHeight,
SRCCOPY
);
if(bRet == 0)
{
SelectObject(hbkDC,holdBkBmp); DeleteDC(hmemDC);
DeleteDC(hbkDC);
return ;
}
SelectObject(hbkDC,holdBkBmp); DeleteDC(hbkDC);
//画字
SetTextColor(hmemDC,m_corWord);
SetBkMode(hmemDC,TRANSPARENT);
m_hf = CreateFont(m_strFace,m_nFontHeight,m_nFontWidth,m_nFontWidth);
if(m_hf == NULL)
{
DeleteDC(hmemDC);
DeleteObject(m_hf);
return;
}
SelectObject(hmemDC,m_hf);
// if(holdFont == NULL)
// return;
bRet = DrawNotesText(hmemDC);
if(bRet == 0)
{
DeleteDC(hmemDC);
DeleteObject(m_hf);
return ;
}
bRet = StretchBlt(hDC,2,0,rcWnd.right-rcWnd.left-2,rcWnd.bottom-rcWnd.top,hmemDC,0,0,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top,SRCCOPY);
if(bRet == 0)
return ;
SelectObject(hmemDC,holdMemBmp);
DeleteObject(m_hf);
DeleteDC(hmemDC);
EndPaint(m_hWnd,&ps);
}
catch(CException e)
{
char buf[100]={0};
e.GetErrorMessage(buf,100);
AfxMessageBox(buf);
}
}//画出滚动字符
BOOL CNotesStatusDraw::DrawNotesText(const HDC &hmemDC)
{
POSITION pos;
ITEMINFOR itemInfor;
SIZE size;
if(m_nMouseOver == TRUE)
return FALSE;
try{
//进入互斥
EnterCriticalSection(&m_criticalSection);
IncreaseDisplayPos(hmemDC);
//退出互斥
LeaveCriticalSection(&m_criticalSection);
GetTextExtentPoint32(hmemDC,"模板",4,&size);
pos = m_lstCurDisplayItem.GetHeadPosition();
while(pos)
{
itemInfor = m_lstCurDisplayItem.GetNext(pos);
TextOut(hmemDC,itemInfor.nShowLeft,(m_rectWnd.bottom-m_rectWnd.top -size.cy+2)/2,itemInfor.strItemValue,itemInfor.strItemValue.GetLength());
}
}
catch (...) {
CFile file;
file.Open("D:\\a.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
file.SeekToEnd();
file.Write("DrawNotesStatus error \r\n",100);
file.Close();
}
return TRUE ;
}