Re: Check Clipboard via Timer
- From: "Ken Tucker [MVP]" <vb2ae@xxxxxxxxxxxxx>
- Date: Sat, 7 May 2005 14:50:45 -0400
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
.
- Follow-Ups:
- Re: Check Clipboard via Timer
- From: Ed Bitzer
- Re: Check Clipboard via Timer
- From: Ed Bitzer
- Re: Check Clipboard via Timer
- From: Ed Bitzer
- Re: Check Clipboard via Timer
- References:
- Check Clipboard via Timer
- From: Ed Bitzer
- Check Clipboard via Timer
- Prev by Date: Re: VB NET Discussion
- Next by Date: Access an ASP.NET subpge from VB.NET app
- Previous by thread: Check Clipboard via Timer
- Next by thread: Re: Check Clipboard via Timer
- Index(es):
Relevant Pages
|