当前位置:首页 » 网络管理 » 如何删除mfc中所有数据
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

如何删除mfc中所有数据

发布时间: 2022-05-07 19:27:24

① 在MFC中怎么删除外存文件中的内容

CFile::Remove

static void PASCAL Remove(LPCTSTR lpszFileName);
throw(CFileException);

参数: lpszFileName 表示所需文件的路径字符串。路径可为相对或绝对,但不可包含网络名。

说明:
此静态函数删除由路径指定的文件,但不可移去一个目录。
如果相关联的文件打开或文件不可移去,则函数产生一个异常,它等价于DEL命令。

示例:
// example for CFile::Remove
char* pFileName ="test.dat";
TRY
{
CFile::Remove(pFileName);
}

CATCH(CFileException,e)
{
#ifdef _DEBUG
afxDump <<"File"<<pFileName<<"cannot be removed\n";
#endif
}
END_CATCH

② 怎么在mfc 列表控件中删除数据(数据库中所对应的数据也要删除)

列表显示只是一个表象,二者没有设定好的关联。实际的删除操作应该在数据库中进行,也就是执行删除工作后,你得把列表数据刷新一下,重新显示。
具体的函数实现,如果需要我再贴上来。

void CMCTTView::ListItem()//刷新列表
{
int i = 0;
if(!m_pSet->IsOpen())
AfxMessageBox("数据源未打开");
m_Item.SetExtendedStyle(m_Item.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
m_Item.DeleteAllItems();
m_Item.SetRedraw(FALSE);
if (!m_pSet->GetRecordCount() == 0)
{
m_pSet->MoveFirst();
}

while(!m_pSet->IsEOF())
{

m_Item.InsertItem(i,"");

m_Item.SetItemText(i,0,m_pSet->m_column1);
m_Item.SetItemText(i,1,m_pSet->m_column2);
m_Item.SetItemText(i,2,m_pSet->m_column3);
m_Item.SetItemText(i,3,m_pSet->m_column4);

i+=1;
m_pSet->MoveNext();
}
m_Item.SetRedraw(TRUE);

}

void CMCTTView::OnItemDel() //在view类中删除条目
{
// TODO: Add your control notification handler code here
int listIndex; //当前选中项的索引
//首先得到点击的位置
POSITION pos=m_Item.GetFirstSelectedItemPosition(); //0 based m_item是指代列表控件
if(pos==NULL)
return;
//得索引,通过POSITION转化
listIndex=m_Item.GetNextSelectedItem(pos)+1; //1 based,so 1 added
m_pSet->SetAbsolutePosition(listIndex);

if ( MessageBox( _T( "你确定要删除当前单词信息吗?" ),
_T( "删除确认?" ), MB_OKCANCEL | MB_ICONQUESTION ) == IDOK )
{
m_pSet->Delete();
MessageBox( _T( "该单词信息已经被成功删除!" ),
_T( "删除成功!" ), MB_OK | MB_ICONASTERISK );
OnNext();
}
m_pSet->Requery();
//if(!m_pSet->GetRecordCount() == 0)
ListItem();
}

void CMCTTView::OnNext()
{
m_pSet->MoveNext();

if ( m_pSet->IsEOF() )
m_pSet->MoveFirst();
}

int CMCTTDoc::AddToAcc()//在doc类中添加数据
{
m_mCTTSet.AddNew();
CString str1,str2,str3,str4;
str1.Format("%s",m_Index);
str2.Format("%f",m_UseHs);
str3.Format("%f",m_UseHj);

switch (m_HJStyle)
{
case 0:
str4 = CString("类型1");
break;
case 1:
str4 = CString("类型2");
break;
case 2:
str4 = CString("类型3");
break;
}
m_mCTTSet.m_column1 = str1; //Index
m_mCTTSet.m_column2 = str2; //the use of hansi
m_mCTTSet.m_column3 = str3; //the use of hanji
m_mCTTSet.m_column4 = str4; //the style of hanjie

m_mCTTSet.Update();
m_mCTTSet.Requery();
MessageBeep(MB_OK);

CMainFrame* pframe = (CMainFrame*)AfxGetMainWnd();

CMCTTView* pInterfaceView = (CMCTTView*)pframe->GetActiveView();
pInterfaceView->ListItem();

return 0;
}

③ 在MFC中如何删除已有的数据库

void CBusinesscardView::OnMenuDeleteClick()
{
CDeleteDialog dlg;
if(dlg.DoModal()==IDOK)
{
CString s;
s.Format("确定要删除 “%s” 的相关信息?",dlg.m_name);
if(MessageBox(s,"删除询问",MB_OKCANCEL)==IDOK)
{
BOOL b=FALSE;
m_pSet->MoveFirst();
do
{
if(dlg.m_name!=m_pSet->m_name)
m_pSet->MoveNext();
else
{
m_list.DeleteAllItems();
b=TRUE;
m_pSet->Delete();
m_pSet->Requery();
RefreshList();
m_pSet->MoveFirst();
break;
}
}
while(!m_pSet->IsEOF());

if(b==FALSE)
{
CString str;
str.Format("没有 “%s” 的相关信息",dlg.m_name);
AfxMessageBox(str);
}
}
}

}

你试试看!!

④ 请问MFC中如何清空列表控件中的内容

CListCtrl* pList=GetListCtrl();
pList->DeleteAllItems(); // 全部清空
pList->DeleteColumn(i); // 清空第i行

⑤ MFC如何删除文件或文件夹

给你个删除目录的函数:

voidDeleteDirectory(CStringstrDir)

{

if(strDir.IsEmpty())

{

RemoveDirectory(strDir);

return;

}

//首先删除文件及子文件夹

CFileFindff;

BOOLbFound=ff.FindFile(strDir+_T("
\*"),0
);

while(bFound)

{

bFound=ff.FindNextFile();

if(ff.GetFileName()==_T(".")||ff.GetFileName()==_T(".."))

continue;

//去掉文件(夹)只读等属性

SetFileAttributes(ff.GetFilePath(),FILE_ATTRIBUTE_NORMAL);

if(ff.IsDirectory())

{

//递归删除子文件夹

DeleteDirectory(ff.GetFilePath());

RemoveDirectory(ff.GetFilePath());

}

else

{

DeleteFile(ff.GetFilePath());//删除文件

}

}

ff.Close();

//然后删除该文件夹

RemoveDirectory(strDir);

}

⑥ MFC列表框数据删除与文件数据删除问题

是ListCtrl列表吗? 关联成员控制变量:m_list

  1. 获取学号: m_clist.GetItemText(行号,列号);

  2. 如果是用文件保存的话,那么程序启动是时候,把数据全部读出,读取到链表或其他,然后想删除哪个就删哪个,然后清空,重新保存文件

⑦ MFC 如何删除目录下的所有文件

仅供参考:

boolDeleteDirectory(char*DirName)
{
HANDLEhFirstFile=NULL;
WIN32_FIND_DATAFindData;

charcurrdir[MAX_PATH]={0};
sprintf(currdir,"%s\*.*",DirName);hFirstFile=::FindFirstFile(currdir,&FindData);
if(hFirstFile==INVALID_HANDLE_VALUE)
returnfalse;
BOOLbRes=true;
while(bRes)
{
bRes=::FindNextFile(hFirstFile,&FindData);
if((FindData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))//发现目录
{
if(!strcmp(FindData.cFileName,".")||!strcmp(FindData.cFileName,".."))//.或..
continue;
else
{
chartmppath[MAX_PATH]={0};
sprintf(tmppath,"%s\%s",DirName,FindData.cFileName);

DeleteDirectory(tmppath);
}
}
else//发现文件
{
chartmppath[MAX_PATH]={0};
sprintf(tmppath,"%s\%s",DirName,FindData.cFileName);
::DeleteFile(tmppath);
}
}
::FindClose(hFirstFile);
if(!RemoveDirectory(DirName))
{
returnfalse;
}
returntrue;
}

⑧ MFC中怎么清除GridCtrl里面的所有数据,不是for循环一条一条删除

List control有个函数可以删除所有数据;
m_ListCtrl.DeleteAllItems();
GirdCtrl 也类似 你先定义个变量m
m.DeleteAllItems();

⑨ 在mfc中,如何清空listcontrol控件中添加的列名以及组合框combobox中的全部数据

clistctrl添加列时用的insertcolumn(),ccomboxctrl添加数据时使用addstring()函数。这两个一般是在初始化的时候使用。你找到源文件,直接删除即可

⑩ mfc 如何清空一个txt中的所有内容

直接把当前文件删除,下次写数据的时候重新创建相同名字的文件就好了。