[Cool] Clipboard - Copy/Cut Logger ! - BlackSpider - 04-06-2010
*THIS IS NOT ILLEGAL*
WARNING: It was first coded for LeetCoders contest. It's not advertising.
Source:
Code: '\\ Author: Soul Collector
'\\ Language: VB .NET aka. Visual Basic 2008
'\\ Contact: soulcoll3ctor@live.com
'\\ Comments: Please, if you use it. Give credits to Me(Soul Collector), thanks.
Public Class Form1
Dim Stored As String
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Stored = My.Computer.Clipboard.GetText = False Then
If lblNumb.Text = 0 = False Then
lblNumb.Text = lblNumb.Text + 1
txtBoard.Text = txtBoard.Text & vbNewLine & vbNewLine & "Log " & lblNumb.Text & " - " & My.Computer.Clipboard.GetText
Stored = My.Computer.Clipboard.GetText
Else
lblNumb.Text = lblNumb.Text + 1
txtBoard.Text = txtBoard.Text & "Log " & lblNumb.Text & " - " & My.Computer.Clipboard.GetText
Stored = My.Computer.Clipboard.GetText
End If
Else
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
End Sub
End Class
Screenshot:
Video example:
[yt]http://www.youtube.com/watch?v=TjkhiwTX1aY[/yt]
Download Project & Binary:
http://www.multiupload.com/RAG6M587VI
P.S. If you use it in your program, please give proper credits to me(Soul Collector), thanks.
[/font]
RE: [Cool] Clipboard - Copy/Cut Logger ! - Navineous - 04-07-2010
kinda cool, thanks for source
RE: [Cool] Clipboard - Copy/Cut Logger ! - TheBlackMarket - 04-07-2010
It seems to be very useful Thanks for the source code and a tutorial video GREAT! Simple and great project
RE: [Cool] Clipboard - Copy/Cut Logger ! - Teh - 04-08-2010
Hmm what does this basically do?..
Is it like it records what you copied? If so then i <3 u. I always copy double things and then i have to go back to the page and copy it again =.=
Thanks ^^
RE: [Cool] Clipboard - Copy/Cut Logger ! - shubhamm - 04-08-2010
its very useful SOurce COde
Thanks
RE: [Cool] Clipboard - Copy/Cut Logger ! - Swift Swim - 04-08-2010
(04-08-2010, 05:41 AM)Teh Wrote: Hmm what does this basically do?..
Is it like it records what you copied? If so then i <3 u. I always copy double things and then i have to go back to the page and copy it again =.=
Thanks ^^ Similarly I do this!
Pretty useful
I doubt ill use the source, but thanks for the video; Makes it so much easier to understand what it is than just a wall of text that most people post
RE: [Cool] Clipboard - Copy/Cut Logger ! - Xypher - 04-08-2010
Oh wow this is really nice...Thanks for the post dude.
RE: [Cool] Clipboard - Copy/Cut Logger ! - julian - 04-09-2010
There's another way to do it. You are using the technique of polling - checking every x seconds if the clipboard changed. In general the alternative to polling is to use events. .Net doesn't expose any clipboard events, but you can use the Windows Api.
You register your form as a Clipboard viewer. There are a bunch of viewers, and they have to co-operate to maintain the list of viewers that windows uses to know where to send messages. The viewers are in a Chain. If a viewer leaves the chain, then windows tells the first window in the chain which one left. The first window has to tell the next window, and so on down the chain until it reaches the hole.
It's not quite as bad as it sounds. Here I wrap the api and raise an event when the clipboard changes...
Code: Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices
Public Class Form1
' We'll raise this event using the windows api...
Private Event ClipboardChanged()
Private Const WM_CHANGECBCHAIN As Integer = &H30D
Private Const WM_DRAWCLIPBOARD As Integer = &H308
Private hNextWindow As IntPtr
Private Declare Auto Function SetClipboardViewer Lib "user32" (ByVal hWndViewer As IntPtr) As IntPtr
Private Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
Private Declare Auto Function ChangeClipboardChain Lib "user32" (ByVal hWndRemove As IntPtr, ByVal hWndNewNext As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
' Register with windows as a clipboard viewer.
hNextWindow = SetClipboardViewer(Me.Handle)
End Sub
' (This would be better off inside the Dispose method in Form1.designer.vb)
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
' Remove ourselves from the clipboard chain.
ChangeClipboardChain(Me.Handle, hNextWindow)
End Sub
' Once registered as a clipboard viewer windows will send us messages.
' We can intercept windows messages sent to the form in this sub.
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_CHANGECBCHAIN
' We are responsible for telling the next window in the clipboard viewer chain when the chain has changed.
' wParam is the handle of the window that has been removed from the chain.
' lParam is the handle of the next window or IntPtr.Zero if there is no next window.
If m.WParam = hNextWindow Then
' The next window is the one being removed. We now should use lParam as next window
hNextWindow = m.LParam
Else
If m.LParam <> IntPtr.Zero Then
' Send the message to the next window.
SendMessage(m.LParam, m.Msg, m.WParam, m.LParam)
End If
End If
Case WM_DRAWCLIPBOARD
' The clipboard changed!
RaiseEvent ClipboardChanged()
End Select
MyBase.WndProc(m)
End Sub
' Do stuff in here.
Private Sub Form1_ClipboardChanged() Handles Me.ClipboardChanged
If My.Computer.Clipboard.ContainsText Then
Me.TextBox1.Text = My.Computer.Clipboard.GetText
End If
End Sub
End Class
The advantage of using events is that you get instant notification when it changes, and your app doesn't use as many resources.
RE: [Cool] Clipboard - Copy/Cut Logger ! - RaZoR03 - 04-18-2010
Nice tut.Thanks for posting.
|