Results 1 to 4 of 4

Thread: is it possible to know when clipboard changes?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    is it possible to know when clipboard changes?

    with .NET or with APIs?
    any way to raise an event when the data in clipboard is changed?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    Doesn't the clipboard chain component do this?

    If not you could coinvert this VB6 code which uses APIs...

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    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:
    1. [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
    2. [/COLOR]    [Color=Blue]Private[/COLOR] [Color=Blue]Const[/COLOR] WM_DRAWCLIPBOARD = &H308
    3.     [Color=Blue]Private[/COLOR] IsSubClassed [Color=Blue]As[/COLOR] [Color=Blue]Boolean[/COLOR] = [Color=Blue]False
    4.  
    5. [/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
    6.         SetClipboardViewer([Color=Blue]Me[/COLOR].Handle)
    7.         IsSubClassed = [Color=Blue]True
    8. [/COLOR]    [Color=Blue]End[/COLOR] [Color=Blue]Sub
    9.  
    10. [/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)
    11.         [Color=Blue]If[/COLOR] IsSubClassed [Color=Blue]Then
    12. [/COLOR]            [Color=Blue]If[/COLOR] m.Msg = WM_DRAWCLIPBOARD [Color=Blue]Then
    13. [/COLOR]                MessageBox.Show("ClipBoard has been modified!")
    14.             [Color=Blue]End[/COLOR] [Color=Blue]If
    15. [/COLOR]        [Color=Blue]End[/COLOR] [Color=Blue]If
    16. [/COLOR]        [Color=Blue]MyBase[/COLOR].WndProc(m)
    17.     [Color=Blue]End[/COLOR] [Color=Blue]Sub[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  4. #4

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width