MakeF(批量生成亂碼文件)

 

  1. void CMakeFDlg::OnBnClickedBtnMake() 
  2.     // TODO: 在此添加控件通知處理程序代碼 
  3.     CString strName,strBegin,strEnd,strSize,strPath,strType; 
  4.      
  5.      
  6.     GetDlgItem(IDC_EDIT_NAME)->GetWindowText(strName); 
  7.     GetDlgItem(IDC_EDIT_BEGIN)->GetWindowText(strBegin); 
  8.     GetDlgItem(IDC_EDIT_END)->GetWindowText(strEnd); 
  9.     GetDlgItem(IDC_EDIT_PATH)->GetWindowText(strPath); 
  10.     GetDlgItem(IDC_EDIT_SIZE)->GetWindowText(strSize); 
  11.     GetDlgItem(IDC_EDIT_TYPE)->GetWindowText(strType); 
  12.      
  13.  
  14.     int flag;//單位標記,1=kb,0=byte 
  15.     flag=((CButton *)GetDlgItem(IDC_RADIO_K))->GetCheck(); 
  16.  
  17.  
  18.     int nBegin = _ttoi(strBegin); 
  19.     int nEnd = _ttoi(strEnd); 
  20.     int size = _ttoi(strSize); 
  21.     int total = nEnd - nBegin + 1; 
  22.     int current = nBegin; 
  23.  
  24.  
  25.  
  26.     for(int i=1;i<total+1;i++) 
  27.     { 
  28.         current = nBegin +i -1; 
  29.         int fileSize = i*size; 
  30.          
  31.         MakeFile(flag,fileSize,strName,strType, strPath, current); 
  32.  
  33.     } 
  34.   
  35.      
  36. void CMakeFDlg::MakeFile(int flag, int &fileSize, CString &strName, CString &strType,CString &strPath,int current) 
  37.     static int fileSection = 0; 
  38.     if (1==flag) 
  39.     { 
  40.         fileSection = 1024; 
  41.     }  
  42.     else 
  43.     { 
  44.         fileSection = 1; 
  45.     } 
  46.  
  47.     BYTE* pBuf = new BYTE[fileSection*fileSize+1]; 
  48.  
  49.     srand((UINT)GetCurrentTime());  
  50.     for(int i=0;i<fileSection*fileSize;i++) 
  51.     {        
  52.         int a = rand()%255; 
  53.         pBuf[i]=a; 
  54.     } 
  55.  
  56.     if ((strPath.GetLength()-1)!='\\'
  57.     { 
  58.         strPath+=L"\\"
  59.     } 
  60.     CString strCC,strFull; 
  61.  
  62.     if (current==0) 
  63.     { 
  64.         strCC=L""
  65.     }  
  66.     else 
  67.     { 
  68.         strCC.Format(L"%d", current); 
  69.     } 
  70.      
  71.     strFull=strPath + strName + strCC + _T(".") + strType; 
  72.     CFile   file;  
  73.     file.Open(strFull,CFile::modeCreate|CFile::modeReadWrite);  
  74.  
  75.     file.Write(pBuf,fileSection * fileSize); 
  76.     //file.SetLength(1024*1024);  
  77.     file.Close();  
  78.     delete pBuf; 
  79. void CMakeFDlg::OnBnClickedBtnExit() 
  80.     exit(0); 
  81.  
  82. void CMakeFDlg::OnBrowser() 
  83.     // TODO: 在此添加控件通知處理程序代碼 
  84.     CString str; 
  85.     BROWSEINFO bi; //必須傳入的參數,下面就是這個結構的參數的初始化 
  86.     TCHAR name[MAX_PATH]; 
  87.     ZeroMemory(&bi,sizeof(BROWSEINFO)); 
  88.     bi.hwndOwner=GetSafeHwnd();  //得到父窗口Handle值 
  89.     bi.pszDisplayName=name; 
  90.     bi.lpszTitle=L"選擇存放的文件夾 "
  91.     bi.ulFlags=BIF_USENEWUI; 
  92.     LPITEMIDLIST idl=SHBrowseForFolder(&bi); 
  93.     if(idl==NULL) 
  94.         return
  95.     SHGetPathFromIDList(idl,str.GetBuffer(MAX_PATH)); 
  96.     str.ReleaseBuffer(); 
  97.     m_Path=str; 
  98.     if(str.GetAt(str.GetLength()-1)!='\\'
  99.         m_Path+="\\"
  100.    // UpdateData(FALSE); 
  101.     GetDlgItem(IDC_EDIT_PATH)->SetWindowText(m_Path); 
  102.  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章