with .NET or with APIs?
any way to raise an event when the data in clipboard is changed?
Printable View
with .NET or with APIs?
any way to raise an event when the data in clipboard is changed?
Doesn't the clipboard chain component do this?
If not you could coinvert this VB6 code which uses APIs...
if you want a basic example to start with, i knocked this up for you, it notifies you when the clipboard receives a change, you can add stuff like if it receives copy etc... as you like
VB Code:
[Color=Blue]Private[/COLOR] [Color=Blue]Declare[/COLOR] [Color=Blue]Function[/COLOR] SetClipboardViewer [Color=Blue]Lib[/COLOR] "user32" ([Color=Blue]ByVal[/COLOR] hwnd [Color=Blue]As[/COLOR] IntPtr) [Color=Blue]As[/COLOR] [Color=Blue]Integer [/COLOR] [Color=Blue]Private[/COLOR] [Color=Blue]Const[/COLOR] WM_DRAWCLIPBOARD = &H308 [Color=Blue]Private[/COLOR] IsSubClassed [Color=Blue]As[/COLOR] [Color=Blue]Boolean[/COLOR] = [Color=Blue]False [/COLOR] [Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] Form1_Load([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] System.Object, [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.EventArgs) [Color=Blue]Handles[/COLOR] [Color=Blue]MyBase[/COLOR].Load SetClipboardViewer([Color=Blue]Me[/COLOR].Handle) IsSubClassed = [Color=Blue]True [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]Sub [/COLOR] [Color=Blue]Protected[/COLOR] [Color=Blue]Overrides[/COLOR] [Color=Blue]Sub[/COLOR] WndProc([Color=Blue]ByRef[/COLOR] m [Color=Blue]As[/COLOR] System.Windows.Forms.Message) [Color=Blue]If[/COLOR] IsSubClassed [Color=Blue]Then [/COLOR] [Color=Blue]If[/COLOR] m.Msg = WM_DRAWCLIPBOARD [Color=Blue]Then [/COLOR] MessageBox.Show("ClipBoard has been modified!") [Color=Blue]End[/COLOR] [Color=Blue]If [/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]If [/COLOR] [Color=Blue]MyBase[/COLOR].WndProc(m) [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]
aha, thanks to both of you...
just wondering though, doesnt this slow the program down a lot? cuz each time WndProc is fired it has to check if it was from the clipboard or not... and I guess WndProc is fired a billion times when you run your app:rolleyes: