① 在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
獲取學號: m_clist.GetItemText(行號,列號);
如果是用文件保存的話,那麼程序啟動是時候,把數據全部讀出,讀取到鏈表或其他,然後想刪除哪個就刪哪個,然後清空,重新保存文件
⑦ 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中的所有內容
直接把當前文件刪除,下次寫數據的時候重新創建相同名字的文件就好了。