- void CMakeFDlg::OnBnClickedBtnMake()
- {
- // TODO: 在此添加控件通知處理程序代碼
- CString strName,strBegin,strEnd,strSize,strPath,strType;
- GetDlgItem(IDC_EDIT_NAME)->GetWindowText(strName);
- GetDlgItem(IDC_EDIT_BEGIN)->GetWindowText(strBegin);
- GetDlgItem(IDC_EDIT_END)->GetWindowText(strEnd);
- GetDlgItem(IDC_EDIT_PATH)->GetWindowText(strPath);
- GetDlgItem(IDC_EDIT_SIZE)->GetWindowText(strSize);
- GetDlgItem(IDC_EDIT_TYPE)->GetWindowText(strType);
- int flag;//單位標記,1=kb,0=byte
- flag=((CButton *)GetDlgItem(IDC_RADIO_K))->GetCheck();
- int nBegin = _ttoi(strBegin);
- int nEnd = _ttoi(strEnd);
- int size = _ttoi(strSize);
- int total = nEnd - nBegin + 1;
- int current = nBegin;
- for(int i=1;i<total+1;i++)
- {
- current = nBegin +i -1;
- int fileSize = i*size;
- MakeFile(flag,fileSize,strName,strType, strPath, current);
- }
- }
- void CMakeFDlg::MakeFile(int flag, int &fileSize, CString &strName, CString &strType,CString &strPath,int current)
- {
- static int fileSection = 0;
- if (1==flag)
- {
- fileSection = 1024;
- }
- else
- {
- fileSection = 1;
- }
- BYTE* pBuf = new BYTE[fileSection*fileSize+1];
- srand((UINT)GetCurrentTime());
- for(int i=0;i<fileSection*fileSize;i++)
- {
- int a = rand()%255;
- pBuf[i]=a;
- }
- if ((strPath.GetLength()-1)!='\\')
- {
- strPath+=L"\\";
- }
- CString strCC,strFull;
- if (current==0)
- {
- strCC=L"";
- }
- else
- {
- strCC.Format(L"%d", current);
- }
- strFull=strPath + strName + strCC + _T(".") + strType;
- CFile file;
- file.Open(strFull,CFile::modeCreate|CFile::modeReadWrite);
- file.Write(pBuf,fileSection * fileSize);
- //file.SetLength(1024*1024);
- file.Close();
- delete pBuf;
- }
- void CMakeFDlg::OnBnClickedBtnExit()
- {
- exit(0);
- }
- void CMakeFDlg::OnBrowser()
- {
- // TODO: 在此添加控件通知處理程序代碼
- CString str;
- BROWSEINFO bi; //必須傳入的參數,下面就是這個結構的參數的初始化
- TCHAR name[MAX_PATH];
- ZeroMemory(&bi,sizeof(BROWSEINFO));
- bi.hwndOwner=GetSafeHwnd(); //得到父窗口Handle值
- bi.pszDisplayName=name;
- bi.lpszTitle=L"選擇存放的文件夾 ";
- bi.ulFlags=BIF_USENEWUI;
- LPITEMIDLIST idl=SHBrowseForFolder(&bi);
- if(idl==NULL)
- return;
- SHGetPathFromIDList(idl,str.GetBuffer(MAX_PATH));
- str.ReleaseBuffer();
- m_Path=str;
- if(str.GetAt(str.GetLength()-1)!='\\')
- m_Path+="\\";
- // UpdateData(FALSE);
- GetDlgItem(IDC_EDIT_PATH)->SetWindowText(m_Path);
- }