Results 1 to 9 of 9

Thread: [RESOLVED] Copy Paste/change data issue

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    129

    Resolved [RESOLVED] Copy Paste/change data issue

    so this is a weird one.. I read data from one excel spreadsheeet and convert it into something different in another spread sheet. Here was "I thought" the easiest solution.....change the clipboard data... The problem is that it won't work on my Windows 8/Office 2013(works rarely), but will work on my Windows 7/Office 2010 (admin). However when I use it at work (windows 7/office 2010) it doesn't work (user not admin).. So originally I thought it was a windows 8 issue, but now I see the same issue with Windows 7 at work (non admin). Also an issue with Outlook.. seems as though outlook monitors the clipboard as well.. I have had outlook crash when I run this simple program which basically is just a timer that monitors the clipboard and REPLACES the text so it can be pasted into another format.

    So here is an example.

    I have a timer running to monitor the clipboard. IF the clipboard contains 1 2 3 4 5 it will REPLACE them with "6 7 8 9 10". Its like the Clipboard.settext is not working. It works intermittently not consistantly unless its on my home Windows 7/Office 2010. So I know my coding should be right its just something with the clipboard.

    is there a more effiecent way of intercepting the clipboard/reading/changing/writing????besides Clipboard.gettext/settext

    I read something about clipboard threads/threadstates when researching, but did not come accross a good example...

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,660

    Re: Copy Paste/change data issue

    you can hook the clipboard, so you receive notification of changes:

    Code:
    Public Class Form1
    
        Private Const WM_DRAWCLIPBOARD As Integer = &H308
        Private Declare Function SetClipboardViewer Lib "user32" Alias "SetClipboardViewer" (ByVal hwnd As Integer) As Integer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim result As Integer = SetClipboardViewer(Me.Handle.ToInt32)
            While result <> Me.Handle.ToInt32
                result = SetClipboardViewer(Me.Handle.ToInt32)
            End While
        End Sub
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_DRAWCLIPBOARD Then
                'clipboard changed
            End If
            MyBase.WndProc(m)
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    129

    Re: Copy Paste/change data issue

    so how do you settext, clear, gettext???

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,660

    Re: Copy Paste/change data issue

    Quote Originally Posted by BlayzeX View Post
    so how do you settext, clear, gettext???
    you use my code with gettext + settext.
    the is also a method:

    Code:
    if Clipboard.ContainsText
    or something similar, so you'll be accessing the clipboard + modifying its contents far less often

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    129

    Re: Copy Paste/change data issue

    thank you for you reply... i found the issue with excel. If you leave it selected after pressing copy, office wants to keep it in teh clipboard, but if you press ESC and deselect it, then you can modify it in the clipboard. However I will definitely check out your method of monitoring the clipboard.

  6. #6
    Junior Member
    Join Date
    Aug 2022
    Posts
    17

    Re: Copy Paste/change data issue

    WM_CHANGECBCHAIN needs to be handled by all viewers in the chain.

    Name:  cbv.jpg
Views: 86
Size:  48.6 KB
    Last edited by philo; Jul 31st, 2024 at 12:04 PM.

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,660

    Re: Copy Paste/change data issue

    Quote Originally Posted by philo View Post
    WM_CHANGECBCHAIN needs to be handled by all viewers in the chain.
    You’re a little late to the party. This is an eleven year old resolved thread

  8. #8
    Junior Member
    Join Date
    Aug 2022
    Posts
    17

    Re: [RESOLVED] Copy Paste/change data issue

    Yeah, now it is.



    Code:
        Case WM_CHANGECBCHAIN
            If wParam = nextviewer Then
                nextviewer = lParam
            ElseIf nextviewer <> 0 Then
                SendMessage nextviewer, uMsg, wParam, lParam
            End If

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,660

    Re: [RESOLVED] Copy Paste/change data issue

    Quote Originally Posted by philo View Post
    Yeah, now it is.



    Code:
        Case WM_CHANGECBCHAIN
            If wParam = nextviewer Then
                nextviewer = lParam
            ElseIf nextviewer <> 0 Then
                SendMessage nextviewer, uMsg, wParam, lParam
            End If
    That wouldn’t work in vb.net

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