By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,576 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,576 IT Pros & Developers. It's quick & easy.

please help with clipboard viewer

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.