业余编程爱好者向专家求援
用Visual Studio 2012 编了一个字符串显示函数。程序运行时在调用此函数上千次之后会出现错误:
线程 0x1ca0 已退出,返回值为 0 (0x0)。
线程 0x2598 已退出,返回值为 0 (0x0)。
0x0011E26C 处的第一机会异常(在 ksd.exe 中): 0xC0000005: 读取位置 0x00000000 时发生访问冲突。
调试显示问题出在 语句 CFont* pFont=pDC->SelectObject(&font); 这里。
艰苦奋斗几小时解决不了。
恳请专家指教!
CSDN 的新人第一次发帖,请多多包涵。
void CksdView::ShowCString(int index,int irow, int icol, CString string, CString colour)
{
/* 显示一个已知数
index, 盘号,0,1,2.
irow,icol 行和列
string,
colour, 颜色。 可选项:blue(隐含), red.
例: colour=“blue” ; // 或者 colour=“red”
ShowNumber(index,irow,icol,str,colour);
*/
CString str;
int ix,iy,k;
int ired,igreen,iblue;
ired=0;
igreen=0;
iblue=255; // 隐含色是蓝色
if (colour=="red")
{ ired = 255;
igreen=0;
iblue=0; }
// strin=string;
ix = rsize*( 200+index1080+90icol-90);
iy = rsize*( 200+92*irow-92);
CDC *pDC=GetDC();// device context for painting
CFont font; //创建字体对象
font.CreateFont(60,0,0,0,FW_MEDIUM,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,"Arial");
CFont* pFont=pDC->SelectObject(&font);
CFont *pOldFont=pDC->SelectObject(&font);//选入设备描述表
pDC->SelectObject(&font); //选入设备环境
pDC->SetTextColor(RGB(ired,igreen,iblue)); //设置文本颜色
pDC->TextOut(ix,iy,string); // 输出 !!!
font.DeleteObject();
// pDC->SelectStockObject(DEVICE_DEFAULT_FONT);//选择堆字体 // test add
}