File Operations (2): file shredder, file operation file shredder

Source: Internet
Author: User

File Operations (2): file shredder, file operation file shredder

Principle of file shredder: Before a file is deleted, write it with random characters

(Note: The reference material uses the BCB compiler, but the BCB compiler does not. Therefore, we need to use MFC here)

I,

First, create a dialog box-based MFC project and add controls in the dialog box

M_StatusBar.Create (WS_CHILD | WS_VISIBLE | SBT_OWNERDRAW, CRect (400,), this, 0); int strPartDim [2] = {,-1 }; // split it into two portions, with 400 pixels on the left m_StatusBar.SetParts (2, strPartDim );

After setting, we can use CStatusBarCtrl: SetText () to display text on the status bar.

Note: In VC6.0, the status bar cannot be directly added to the resource management control, but must be created using a program. Therefore, it can only be displayed after the program is run.

III,

Add the response of the dialog box control. Click Browse to bring up the open file dialog box, click the file in the folder, so that the clicked file name is displayed in the text edit box on the left.

1. associate a member variable m_strPath with the text edit box. Press ctrl + w, select Edit Control ID, add member variable, and enter m_strPath

2. Double-click the Browse button to go to the response function and add the following code to it:

// TODO: Add your control notification handler code here UpdateData (TRUE); CFileDialog fileDlg (TRUE); fileDlg. m_ofn.lpstrTitle = "Open File"; fileDlg. m_ofn.lpstrFilter = "All Files (*. *) \ 0 *. * \ 0 \ 0 "; fileDlg. m_ofn.lpstrDefExt = "*. txt "; if (IDOK = fileDlg. doModal () {CFile file (fileDlg. getFileName (), CFile: modeRead); m_strPath = fileDlg. getPathName (); // assign the file name to m_strPath UpdateData (FALSE); // display immediately}

4. In the main program, double-click to start crushing and add a button for response.

Add the following code:

If (m_strPath = "") {return;} if (MessageBox ("Once deleted, the object cannot be recovered. Are you sure you want to continue the operation? "," Reminder ", MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON2) = IDCANCEL) {m_StatusBar.SetText (_ T (" You have canceled the operation "), 0, 0 ); // set the status bar text message return;} char buff [1024] = {0}; HANDLE hFile = CreateFile (m_strPath, GENERIC_WRITE | GENERIC_READ, file_into_write, NULL, OPEN_EXISTING, NULL, NULL); DWORD dwLen = SetFilePointer (hFile, 0, NULL, FILE_END); CString temp; temp. format ("file size % dbyte", dwLen); m_StatusBar.SetText (temp, 0, 0); for (int I = 0; I <3; I ++) {temp. format ("% d times erased in total", I + 1); m_StatusBar.SetText (temp, 0, 0); SetFilePointer (hFile, 0, NULL, FILE_BEGIN ); if (dwLen <= 1024) {dwLen = WriteFile (hFile, buff, (dwLen <sizeof (buff ))? DwLen: sizeof (buff), & dwLen, NULL) ;}} CloseHandle (hFile); if (! DeleteFile (m_strPath) {m_StatusBar.SetText (_ T ("file deletion failed, but cannot be recovered"), 0, 0 );}

V,

In the response to the Add cancel button, double-click and write OnOK ();

Program running effect:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.