今天做了一个复制文件的小程序。
如下
// TODO: 在此添加控件通知处理程序代码
CFileDialog *file = new CFileDialog (TRUE) ;
TCHAR *path = new TCHAR[1000] ;
CString str ;
CString str5 ;
::ZeroMemory (path, 1000) ;
GetModuleFileName (NULL, path, 1000) ;
//GetCurrentDirectory (1000, path) ;
file->DoModal () ;
str = file->GetPathName() ;
TCHAR FilePath[256] = {0};
TCHAR Drive[4], Dir[128], FileName[132], Ext[20];
GetModuleFileName(NULL, FilePath, _countof(FilePath));
_tsplitpath_s(FilePath, Drive, _countof(Drive), Dir, _countof(Dir),
FileName, _countof(FileName), Ext, _countof(Ext));
_stprintf_s(FilePath, _countof(FilePath), TEXT("%s%s"),
Drive, Dir);
//::MessageBox (this->m_hWnd, FilePath, NULL, 0) ;
CString *str1 = new CString(FilePath) ;
int n = str.GetLength();
//获取宽字节字符的大小,大小是按字节计算的
int len = WideCharToMultiByte(CP_ACP,0,str,str.GetLength(),NULL,0,NULL,NULL);
//为多字节字符数组申请空间,数组大小为按字节计算的宽字节字节大小 //以字节为单位
//宽字节编码转换成多字节编码
char *buffer = new char[len+1] ;
WideCharToMultiByte(CP_ACP,0,str,str.GetLength(),buffer,len,NULL,NULL);
buffer [len] = '\0'; //多字节字符以'\0'结束
DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, buffer, -1, NULL, 0) ;
TCHAR *pwText = new TCHAR[dwNum+1];
MultiByteToWideChar (CP_ACP, 0, buffer, dwNum, pwText, dwNum+1) ;
//pwText[dwNum] = L" " ;
::ZeroMemory (FileName, 132) ;
::ZeroMemory (Ext, 20 ) ;
::ZeroMemory (Dir, 128 ) ;
::ZeroMemory (Drive, 4 ) ;
_tsplitpath_s(pwText, Drive, _countof(Drive), Dir, _countof(Dir),
FileName, _countof(FileName), Ext, _countof(Ext));
_stprintf_s(pwText, len+1, TEXT("%s%s"),
Drive, Dir);
CString *str2 = new CString(FileName) ;
CString *str3 = new CString(Ext) ;
*str1 = *str1+TEXT("\\墙纸成品\\")+*str2+*str3 ;
//BOOL bl = MoveFile (TEXT("F:\\122.bmp"), TEXT("C:\\122.bmp")) ;
BOOL bl = CopyFile (path, *str1, FALSE) ;
//BOOL bl = MoveFile (path, *str1) ;
if(bl)
{
::MessageBox (this->m_hWnd, TEXT("成功copy"), NULL, 0) ;
}
else
{
::MessageBox (this->m_hWnd, TEXT("失败copy"), NULL, 0) ;
}
delete [] path ;
delete [] pwText ;
delete [] buffer ;
delete str1 ;
delete file ;
复制成功,可是复制后的文件为什么全部都限定在48kb? 而且也都不能打开了 请教原因!!!