wince对文件的读写很方便,只需要调用相应的API就可以了
\\ 在\Program Files\office\目录下创建 Sph.txt
LONG OnBtnCreateFile(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
HANDLE hFile = CreateFile(TEXT("\\Program Files\\office\\Sph.txt"),
GENERIC_READ | GENERIC_WRITE ,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
if( hFile == INVALID_HANDLE_VALUE)
return FALSE;
else
MessageBox(hDlg,TEXT("创建成功"),TEXT("message"),0);
CloseHandle(hFile);
return TRUE;
}
\\ 查到\Program Files\office\目录下面的所有文件,并且在ListBox控件中显示出文件名
LONG OnBtnFindFile(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
WIN32_FIND_DATA data;
HANDLE hFile = FindFirstFile(TEXT("\\Program Files\\office\\*.*"),&data);
if(hFile == INVALID_HANDLE_VALUE)
return FALSE;
HWND hlist = GetDlgItem(hDlg,IDC_LIST1);
ListBox_ResetContent(hlist);
do
{
ListBox_AddString(hlist,data.cFileName);
} while (FindNextFile(hFile,&data));
FindClose(hFile);
return TRUE;
}
\\ 删除\Program Files\office\目录下选中的文件
LONG OnBtnDeleteFile(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
HWND hList = GetDlgItem(hDlg,IDC_LIST1);
int px;
TCHAR buf[32];
TCHAR tmp[200]=TEXT("\\Program Files\\office\\");
//得到当前选中的行
px = ListBox_GetCurSel(hList);
ListBox_GetText(hList,px,buf);
_tcscat(tmp,buf);
DeleteFile(tmp);
return TRUE;
}
\\ 移动或拷贝 Sph.txt 文件到U盘里
LONG OnBtnCopyFile(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
CopyFile(TEXT("\\Program Files\\office\\Sph.txt"),TEXT("\\硬盘\\Sph.txt"),TRUE);
return TRUE;
}
LONG OnBtnMoveFile(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
MoveFile(TEXT("\\Program Files\\office\\Sph.txt"),TEXT("\\硬盘\\Sph.txt"));
return TRUE;
}