Resolved Clipboard change detection

devimore

Member
Joined
Jul 1, 2010
Messages
9
Programming Experience
5-10
Hey all. :)
I have been learning and writing programs in vb.net some time now.. But i ran in some problems..

I always wanted to make clipboard manager, since i allways have problems with some stuff that i copy'd and then lost becouse i copy'd it to clipboard and then copy'd something else.. But i didnt made it becouse i didnt know the vb sow well.. But now i have learned everything what i need to make it finelly.. every thing but this little thing..
How to get the clipboard changed state?

Becouse i cant put in timer some code like this:

VB.NET:
if clipboard.containstext then
	' then some code to clipboard.gettext.. or something
elseif clipboard.contains image then
	'some thing..
elseif clipboard.containsFileDropList then

end if
'and so on..

Becouse i ended up all the time sending the same thing..

So i made some search but could find much..
But i found this code:
Talking Clipboard - CodeProject

That dose exactly what i need, but it's writen in C#

I tried to translate it, but with no result..

So im asking you, forum, for help..
Could someone sheare some peace of code that watch the clipboard to change, and, when it have changed, run some sub or function...
Or some thing that would lead me the rigth way atleast..

By the way, if i finishe this this application will be free for everyone to download..
DeviMore..

P.S. sorry about my grammar, because english is not my primary language..
 
Last edited:
VB.NET:
Private WM_DRAWCLIPBOARD As Integer = 776

Protected Overrides Sub WndProc(ByRef m As Message)
    MyBase.WndProc(m)
    Select Case m.Msg
        Case WM_DRAWCLIPBOARD
            'the contents of the clipboard have changed
    End Select
End Sub
 
Tnx a big time. :) I love this forum and you guys..

Ok. sow here is my solution for my problem..
Tnx a lot forum :)

Imports System.Runtime.InteropServices

Public Class Form1

Private Const WM_DRAWCLIPBOARD As Integer = &H308
Private Const WM_CHANGECBCHAIN As Integer = &H30D

Private mNextClipBoardViewerHWnd As IntPtr
Private Event OnClipboardChanged()

<DllImport("user32")> _
Private Shared Function SetClipboardViewer(ByVal hWnd As IntPtr) As IntPtr
End Function

<DllImport("user32")> _
Private Shared Function ChangeClipboardChain(ByVal hWnd As IntPtr, ByVal hWndNext As IntPtr) As _
<MarshalAs(UnmanagedType.Bool)> Boolean
End Function

<DllImport("user32")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As IntPtr
End Function

Sub New()
InitializeComponent()
mNextClipBoardViewerHWnd = SetClipboardViewer(Me.Handle)
AddHandler Me.OnClipboardChanged, AddressOf ClipBoardChanged
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_DRAWCLIPBOARD
RaiseEvent OnClipboardChanged()
SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)

Case WM_CHANGECBCHAIN
If m.WParam.Equals(mNextClipBoardViewerHWnd) Then
mNextClipBoardViewerHWnd = m.LParam
Else
SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)
End If
End Select
MyBase.WndProc(m)
End Sub

Private Sub ClipBoardChanged()
Dim data As IDataObject = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(Bitmap)) Then
Me.BackgroundImage = DirectCast(data.GetData(GetType(Bitmap)), Bitmap)
End If
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
ChangeClipboardChain(Me.Handle, mNextClipBoardViewerHWnd)
End Sub

End Class


Soon my app will be free to download at my website: .:: DeviMore ::. - Powered by CO.CC

Thats all...
 
Back
Top