473,405 Members | 2,349 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,405 software developers and data experts.

please help with clipboard viewer

hi
I'm tryin to write a program that keeps track of the contents of the
clipboard to a textbox, but i keep getting "An unhandled exception of
type 'System.NullReferenceException' occurred in
WindowsApplication4.exe" error. here is the sample code

Public Class Form1
Inherits System.Windows.Forms.Form
Public Declare Function SetClipboardViewer Lib "user32" Alias
"SetClipboardViewer" (ByVal hwnd As Long) As Integer
Public Declare Function ChangeClipboardChain Lib "user32" Alias
"ChangeClipboardChain" (ByVal hwnd As Integer, ByVal hWndNext As
Integer) As Integer
Dim hWndClipBoard = SetClipboardViewer(Me.Handle.ToInt32)
Dim strPastedText As String

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
Dim data As IDataObject = Clipboard.GetDataObject()
If m.Msg = WM_DRAWCLIPBOARD Then
MessageBox.Show("Here")
If data.GetDataPresent(GetType(String)) Then
strPastedText =
DirectCast(data.GetData(GetType(String)), String)
TextBox1.Text = strPastedText
End If
End If
MyBase.WndProc(m)
End Sub
End Class
Nov 20 '05 #1
4 2472
Cor
Hi Nick,
I think that when you are changing the folowing lines it wil work like a
clipboard viewer (when there is a textbox of course).
(I did not look for the solution, just changed the errors)
To overcome this kind of problems, the best you can do is to set "Option
Strict On" in the header of your progam,
Option Strict on
Public Class Form1
Inherits System.Windows.Forms.Form
Public Declare Function SetClipboardViewer Lib "user32" Alias
"SetClipboardViewer" (ByVal hwnd As Long) As Integer
Public Declare Function ChangeClipboardChain Lib "user32" Alias
"ChangeClipboardChain" (ByVal hwnd As Integer, ByVal hWndNext As
Integer) As Integer Dim hWndClipBoard as Integer
Remove Dim strPastedText As String
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) Dim strPastedText As String
hWndClipBoard = SetClipboardViewer(Me.Handle.ToInt32)
Const WM_DRAWCLIPBOARD as Integer = &H308 Dim data As IDataObject = Clipboard.GetDataObject()
If m.Msg = WM_DRAWCLIPBOARD Then Remove MessageBox.Show("Here") If data.GetDataPresent(GetType(String)) Then
strPastedText =
DirectCast(data.GetData(GetType(String)), String)
TextBox1.Text = strPastedText
End If
End If
MyBase.WndProc(m)
End Sub
End Class


I hope this helps,
Cor
Nov 20 '05 #2
"Cor" <no*@non.com> wrote in message news:<3f**********************@reader21.wxs.nl>...
Hi Nick,
I think that when you are changing the folowing lines it wil work like a
clipboard viewer (when there is a textbox of course).
(I did not look for the solution, just changed the errors)
To overcome this kind of problems, the best you can do is to set "Option
Strict On" in the header of your progam,
Option Strict on
I hope this helps,
Cor

Hi Cor. now it wont even run, i get "Option Strict On requires all
variable declarations to have an 'As' clause." error, thanks for the
help, if you or anyone else got any other suggestions please let me
know
Nov 20 '05 #3
Cor
Nick,
You have to make all the changes I did make in the text.
The lines with a change have no > before them.
Option strict on shows only the errors..
For me it did work.
Cor
Nov 20 '05 #4
Hi,

I have a Clipboard Viewer example on my site. It uses SetClipboardViewer and
is written in C#.

See http://www.radsoftware.com.au/web/CodeZone/

Ross Donald
Rad Software

"Cor" <no*@non.com> wrote in message
news:3f**********************@reader21.wxs.nl...
| Hi Nick,
| I think that when you are changing the folowing lines it wil work like a
| clipboard viewer (when there is a textbox of course).
| (I did not look for the solution, just changed the errors)
| To overcome this kind of problems, the best you can do is to set "Option
| Strict On" in the header of your progam,
| Option Strict on
| > Public Class Form1
| > Inherits System.Windows.Forms.Form
| > Public Declare Function SetClipboardViewer Lib "user32" Alias
| > "SetClipboardViewer" (ByVal hwnd As Long) As Integer
| > Public Declare Function ChangeClipboardChain Lib "user32" Alias
| > "ChangeClipboardChain" (ByVal hwnd As Integer, ByVal hWndNext As
| > Integer) As Integer
| Dim hWndClipBoard as Integer
| Remove Dim strPastedText As String
| >
| > 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)
| Dim strPastedText As String
| hWndClipBoard = SetClipboardViewer(Me.Handle.ToInt32)
| Const WM_DRAWCLIPBOARD as Integer = &H308
| > Dim data As IDataObject = Clipboard.GetDataObject()
| > If m.Msg = WM_DRAWCLIPBOARD Then
| Remove MessageBox.Show("Here")
| > If data.GetDataPresent(GetType(String)) Then
| > strPastedText =
| > DirectCast(data.GetData(GetType(String)), String)
| > TextBox1.Text = strPastedText
| > End If
| > End If
| > MyBase.WndProc(m)
| > End Sub
| > End Class
|
| I hope this helps,
| Cor
|
|
Nov 20 '05 #5

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

Similar topics

2
by: Gey-Hong Gweon | last post by:
Is there a way to copy a PIL image to windows clipboard (as a dib image or a bitmap, I suppose)? What I would like to accomplish is to do a fast copy and paste of images from my python...
0
by: Dennis | last post by:
Greetings, I am having a wierd problem with .net accessing the clipboard on certain machines. The code copies the RTF formatted data from the clipboard. I first try and retrieve the clipboard...
4
by: Joshua Campbell | last post by:
I am working on an application that needs to parse out data that has been copied into the clipboard. My first questions are how can I detect if the clipboard is empty, and how can I empty the...
3
by: Scott Friedrich | last post by:
Hi group I am using a 3rd party AX control in a VB.NET application. One of the methods of this control is to capture the current map within the control to the windows clipboard as .WMF. I am...
6
by: Ed Bitzer | last post by:
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...
5
by: dmeglio | last post by:
I have an item that I placed on the clipboard as follows: Clipboard.SetDataObject(slide); slide is type SlideType. Now I'm trying to read the data from the clipboard doing: foreach...
7
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.