Re: Check Clipboard via Timer



Hi,

You have to use the setclipboardviewer api to register yourself as a
clipboard viewer. The api will return the hwnd to the old viewer save that
value in a form level variable. You will recieve WM_DRAWCLIPBOARD message
when the clipboard changes override wndproc to recieve message. Make sure
you call mybase.wndproc in the override or you app will not work. When
closing program set the clipboard viewer back to the old one.



Api declares

Declare Function SetClipboardViewer Lib "user32" Alias "SetClipboardViewer"
(ByVal hwnd As Integer) As Integer

Declare Function ChangeClipboardChain Lib "user32" Alias
"ChangeClipboardChain" (ByVal hwnd As Integer, ByVal hWndNext As Integer) As
Integer

In form load or where ever want to start monitoring clipboard

hWndClipBoard = SetClipboardViewer(Me.Handle.ToInt32)



Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

ChangeClipboardChain(Me.Handle.ToInt32, hWndClipBoard)

End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_DRAWCLIPBOARD = &H308



If m.Msg = WM_DRAWCLIPBOARD Then

MessageBox.Show("Here")

End If

MyBase.WndProc(m)

End Sub

Ken
------------------
"Ed Bitzer" <edbitzer@xxxxxxxxx> wrote in message
news:%23F3kwXyUFHA.544@xxxxxxxxxxxxxxxxxxxxxxx
Appreciate some help. Want to continuously check clipboard and if text
present unhide and display in a text. The following code can find nothing
in the clipboard even though I paste information there from Notepad.
\\
Public Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
Dim t As New System.Timers.Timer(2000)
AddHandler t.Elapsed, AddressOf TimerFired
t.Enabled = True
End Sub
Public Sub TimerFired(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
Dim d As IDataObject = Clipboard.GetDataObject()
If (Clipboard.GetDataObject.GetDataPresent(DataFormats.Text)) Then
TextBox1.Text =
Clipboard.GetDataObject.GetData(DataFormats.Text).ToString()
End If
End Sub
//
If I debug the TimerFired sub is repeatedly called but there is nothing in
the Clipboard.

Ed




.



Relevant Pages

  • Win API cant retrieve palette from clipboard
    ... I can't seem to ever retrieve a palette handle from the clipboard. ... Private Sub button2_Click(ByVal sender As ... ...
    (microsoft.public.dotnet.languages.vb)
  • Need a palette expert here
    ... can't retrive a Palette from the clipboard. ... Public Sub New ... Private Sub button1_Click(ByVal sender As Object, ...
    (microsoft.public.dotnet.languages.vb)
  • This code shows that Dotnet cant get a palette from the clipboard
    ... can't retrive a Palette from the clipboard. ... Public Sub New ... Private Sub button1_Click(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Copy a set bit of text to the clipboard?
    ... Sub PutOnClipboard ... Dim DataObj As New MSForms.DataObject ... Function GetFromClipboard() As String ... information and example code for working with the clipboard. ...
    (microsoft.public.excel.programming)
  • Re: Download file from URL with password
    ... Sub GetWebPage() ... 'On Error GoTo ErrorHandler ... Set xml = New XMLHTTP ... 'So we put it into the clipboard as text then paste ...
    (microsoft.public.excel.programming)