
Visual Basic Code Snippets #11
In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Window Actions and File Functions.
Completely Destroy File and Its Information
Compatibility: Win. 98-XP
Add the following code into a module within your project...
Public Sub DestroyFile(sFileName As String)
Dim Block1 As String, Block2 As String, Blocks As Long
Dim hFileHandle As Integer, iLoop As Long, offset As Long
'Create two buffers with a specified 'wipe-out' characters
Const BLOCKSIZE = 4096
Block1 = String(BLOCKSIZE, "X")
Block2 = String(BLOCKSIZE, " ")
'Overwrite the file contents with the wipe-out characters
hFileHandle = FreeFile
Open sFileName For Binary As hFileHandle
Blocks = (LOF(hFileHandle) \ BLOCKSIZE) + 1
For iLoop = 1 To Blocks
offset = Seek(hFileHandle)
Put hFileHandle, , Block1
Put hFileHandle, offset, Block2
Next iLoop
Close hFileHandle
'Now you can delete the file, which contains no sensitive data
Kill sFileName
End Sub
Add the following code to wherever you want the code to execute...
Call DestroyFile("C:\filetodestroy.jpg") 'modify file path of course
Cut, Copy, Paste and Undo
Compatibility: Win. 98-XP
Add the following code into a module within your project...
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_UNDO = &H304
Cut:
Add the following code where you want the code to execute...
Clipboard.SetText Text1.SelText
Text1.SelText = ""
Copy:
Add the following code where you want the code to execute...
Clipboard.SetText Text1.SelText
Paste:
Add the following code where you want the code to execute...
Text1.SelText = Clipboard.GetText(1)
Undo:
Add the following code where you want the code to execute...
Call SendMessage(Text1.hwnd, WM_UNDO, 0&, 0&)