473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Check Clipboard via Timer

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(DataFormat s.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

Nov 21 '05 #1
6 3936
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" <ed******@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
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(DataFormat s.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


Nov 21 '05 #2
Ken, Will start the leaning curve playing with that API. Am very
surprised that's necessary with net because thought that was the purpose of
the Clipboard namespace. The following code works great activated by a
button click - but does not work if activated by the timer..
\\
If Clipboard.GetDataObject.GetDataPresent(DataFormats .Text) Then
TextBox1.Text =
Clipboard.GetDataObject.GetData(DataFormats.Text). ToString()
End If
//

Ed
Nov 21 '05 #3
Ken
In form load or where ever want to start monitoring clipboard hWndClipBoard = SetClipboardViewer(Me.Handle.ToInt32)


hWndClipBoard is not declared when I attempt to test - what am I missing?

Ed
Nov 21 '05 #4
"Ed Bitzer" <ed******@yahoo.com> schrieb:
In form load or where ever want to start monitoring clipboard

hWndClipBoard = SetClipboardViewer(Me.Handle.ToInt32)


hWndClipBoard is not declared when I attempt to test - what am I missing?


\\\
Dim hWndClipBoard As Int32
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5
Ken,

The API certainly works as advertised and does not require the timer that I
used in a similar VB6 program to pick up a copy - The API picks up the
"change" when something is copied to the clipboard. I am using this in
small utility I use myself to copy bits and pieces of code or other
information, usually gathered from forums, and accumulates is a temporary
file which I can then edit and often import into a askSam database. I think
I wrote my first version in Pascal many moons ago, after than in VB. I'm
retired and trying to keep up with computer technology and writing a bit of
code, now in VB.Net -- keeps me out of the taverns<g>. I do thank you
guys.

Ed

Nov 21 '05 #6
Hi,

This is how I do it. Example is for getting bitmap but should work
for text.

Dim data As IDataObject

data = Clipboard.GetDataObject()

If data.GetDataPresent(GetType(System.Drawing.Bitmap) ) Then

bm = CType(data.GetData(GetType(System.Drawing.Bitmap)) , Image)

End If

Ken

----------------------------

"Ed Bitzer" <ed******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Ken, Will start the leaning curve playing with that API. Am very
surprised that's necessary with net because thought that was the purpose of
the Clipboard namespace. The following code works great activated by a
button click - but does not work if activated by the timer..
\\
If Clipboard.GetDataObject.GetDataPresent(DataFormats .Text) Then
TextBox1.Text =
Clipboard.GetDataObject.GetData(DataFormats.Text). ToString()
End If
//

Ed

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a...
9
by: Tim Frawley | last post by:
I have converted a VB6 application to VB.NET. The old application made extensive use of the Clipboard for copying an Image Name so that it could be pasted into the image capture app when the user...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: dananrg | last post by:
Can you tell I miss Unix? I want to write a Python script that, when launched, will choose a random .sig (from a list of about 30 cool ones I've devised), and store the .sig text in the Windows...
3
by: Dustin Davis | last post by:
Is it possible to trigger an event in VB.NET whenever anything is copied to the clipboard?
4
by: John Salerno | last post by:
My code is below. The main focus would be on the OnStart method. I want to make sure that a positive integer is entered in the input box. At first I tried an if/else clause, then switched to...
1
by: Tom | last post by:
I have an MDI application in VB.NET. The main MDI window has a status bar, and menu bar. Child MDI windows are opened via the menu on the main MDI window. Now, what I want to do is add code to...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
20
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.