程序运行出错,貌似是说我非法访问。。。请帮忙看看吧,谢谢~

wrhjyx wrhjyx 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
先看我的程序吧
void CMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
CFileDialog openfile(TRUE);
openfile.m_ofn.lpstrFilter="工程文件 (*.GLB)\0*.GLB";
openfile.m_ofn.lpstrTitle="打开文件";

if (openfile.DoModal() == IDOK)
{
CString filepath;
filepath=openfile.GetPathName();//得到完整的文件名,包括目录名和扩展名如:c:\test\test1.txt
if(filepath=="")
return;
SaveOrNot=TRUE;
openProject(filepath);
}
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
void CMainFrame::openProject(CString filepath)//这个函数的内容是把我打开的文件的内容存到一个数组里。

{
//
.......中间是在存数据,存到一个数组中
//
GroupCount = DataNum;//在这儿我把全局变量GroupCount 赋上值,比如说是20

CDataView *pView0=(CDataView *)GetActiveView();//CDataView 说明在下面
pView0->InData();
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
CDataView是我试图分割中的一个视图类
CGridCtrl *m_pGridCtrl;
void CDataView::InData()
{

if ( GroupCount !=0)
{
int rownum;
if ((GroupCount %10) > 0)
{
rownum=GroupCount /10+2;
}
else rownum=GroupCount /10+1;
if(m_pGridCtrl!=NULL)
{
delete m_pGridCtrl;
m_pGridCtrl=NULL;
}
if (m_pGridCtrl == NULL)

{
m_pGridCtrl = new CGridCtrl;
CRect rect;
GetClientRect(rect);
m_pGridCtrl->Create(rect, this, 100);
m_pGridCtrl->SetEditable(false);
m_pGridCtrl->SetBkColor(m_pGridCtrl->GetTextBkColor());
m_pGridCtrl->EnableDragAndDrop(false);
try {
m_pGridCtrl->SetRowCount(rownum); //设置行数为k行
m_pGridCtrl->SetColumnCount(11); //设置列数k列
m_pGridCtrl->SetFixedRowCount(1); //标题行为一行
m_pGridCtrl->SetFixedColumnCount(1); //标题列为1列
}
catch (CMemoryException* e)
{
e->ReportError();
e->Delete();
// return TRUE;
}
//填充列标题
int row=0;
int col=0;
m_pGridCtrl->SetRowHeight(0,30); //设置标题行高
//--------------------------------设置列
for(col=0;col<11;col++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
m_pGridCtrl->SetColumnWidth(col,(rect.Width()-20)/11); //设置11列的列宽
if(col>0){
Item.nFormat = DT_CENTER|DT_WORDBREAK;//|DT_CALCRECT;
// |ES_NUMBER;
Item.strText.Format("%d",col);
}

m_pGridCtrl->SetItem(&Item);
}
// fill rows/cols with text
//----------------------------------------设置行
for (row = 1; row < rownum; row++)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = 0;
Item.nFormat = DT_CENTER|DT_VCENTER
|DT_SINGLELINE|DT_END_ELLIPSIS
|DT_NOPREFIX;//|ES_NUMBER
//|DT_CALCRECT;
// Item.nFormat=Item.nFormat & ~DT_END_ELLIPSIS;
Item.strText.Format("%d",row);
m_pGridCtrl->SetRowHeight(row,30); //设置各行高
m_pGridCtrl->SetItem(&Item);
}
//---------------------------------------------开始在单元格内添加内容

for (int h=0; h<GroupCount; h++)//k=20
{
CString lplbarray;
row=h/10+1;
col=h%10+1;

lplbarray.Format(_T("%d"),CoverL.GJContent.at(0).GJData.at(h));
m_pGridCtrl->SetItemText(row,col,lplbarray);
}
}
}
// MessageBox("CDataView");
}
我利用CGridCtrl *m_pGridCtrl;制作一个电子表格,然后添加数据进去。添加的数据是在CMainFrame::OnFileOpen()中打开的原来存储好的数据。(读取的数据内容是没错的,我单步运行过。)只有运行到红色字体处会出现错误。
unhandled exception in XXX.exe:0xc0000005:Access violation。的错误。貌似是非法访问了。。。可是我不知道为什么。。。请大家指教。。。我的分不多了:(
不知道我说清楚了没有

...全文

相关推荐

评论 17
收藏 已收藏
分享
返回顶部
wrhjyx
VC/MFC 16,550 成员 421,606 内容