Results 1 to 9 of 9

Thread: [RESOLVED] Monitoring clipboard for changes.

  1. #1

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Resolved [RESOLVED] Monitoring clipboard for changes.

    Hello,

    Is there any way for me to monitor the clipboard for changes?

    Like say the clipboard data is "HELLO" and it changes to "Goodbye" how can I have it check that automatically? The program will be running full time in the system tray.

    Thank you and have a great day!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Monitoring clipboard for changes.

    Either a timer (which isn't really a good solution) or the SetClipboardViewer API


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Monitoring clipboard for changes.

    And here's an example of the SetClipboardViewer API :

    VB Code:
    1. 'Create a new project, add a module to it
    2. 'Add a command button to Form1
    3. 'In the form
    4. Private Sub Form_Load()
    5.     'KPD-Team 1999
    6.     'URL: [url]http://www.allapi.net/[/url]
    7.     'E-Mail: [email][email protected][/email]
    8.     'Subclass this form
    9.     HookForm Me
    10.     'Register this form as a Clipboardviewer
    11.     SetClipboardViewer Me.hwnd
    12. End Sub
    13. Private Sub Form_Unload(Cancel As Integer)
    14.     'Unhook the form
    15.     UnHookForm Me
    16. End Sub
    17. Private Sub Command1_Click()
    18.     'Change the clipboard
    19.     Clipboard.Clear
    20.     Clipboard.SetText "Hello !"
    21. End Sub
    22.  
    23. 'In a module
    24. 'These routines are explained in our subclassing tutorial.
    25. 'http://www.allapi.net/vbtutor/subclass.php
    26. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    27. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    28. Declare Function SetClipboardViewer Lib "user32" (ByVal hwnd As Long) As Long
    29. Public Const WM_DRAWCLIPBOARD = &H308
    30. Public Const GWL_WNDPROC = (-4)
    31. Dim PrevProc As Long
    32. Public Sub HookForm(F As Form)
    33.     PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc)
    34. End Sub
    35. Public Sub UnHookForm(F As Form)
    36.     SetWindowLong F.hwnd, GWL_WNDPROC, PrevProc
    37. End Sub
    38. Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    39.     WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
    40.     If uMsg = WM_DRAWCLIPBOARD Then
    41.         MsgBox "Clipboard changed ..."
    42.     End If
    43. End Function


    Has someone helped you? Then you can Rate their helpful post.

  4. #4

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Monitoring clipboard for changes.

    PERFECT MANAVO11! Thank you so much! YOU GET A NICE PLUMP RATING! lol

    Thanks buddy!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] Monitoring clipboard for changes.

    Hehe, thanks and you're welcome


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    New Member
    Join Date
    May 2017
    Posts
    1

    Re: [RESOLVED] Monitoring clipboard for changes.

    Hi there, I'm trying to use these macro but I'm not getting it working. I think it's maybe because I'm using a 64 bit machine and I should change some function declaration made for 32 bit machines but I don't know how.
    Does someone know if this can be right and how to solve it?

    Thanks for all the help given yet and in advance .
    Diego López.

  7. #7
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [RESOLVED] Monitoring clipboard for changes.

    Maybe the following link is useful for you:

    http://www.nirsoft.net/utils/inside_clipboard.html

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] Monitoring clipboard for changes.

    Sounds like an Office VBA user. Subclassing can be a pain in Office since things like UserForms were designed to make subclassing difficult by hiding window handles and such.

  9. #9
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: [RESOLVED] Monitoring clipboard for changes.

    This example appears to be using similar API to that in manavo11's post, but thought it might be of interest to some -
    https://www.planet-source-code.com/v...57727&lngWId=1

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