Skip to main content

Is there a simple way with NETEXPRESS 5.1 (CALL, Function, or MOVE) to send info from a text based program to the Clipboard - memory?

Of course there is the possibility to use right button, Edit, mark, enter, but I am looking for a simpler procedure, where all accepted data is copied to the clipboard.  It is then up to the user to paste or not this info.in an other program.

thanks for any help


#clipboard

Is there a simple way with NETEXPRESS 5.1 (CALL, Function, or MOVE) to send info from a text based program to the Clipboard - memory?

Of course there is the possibility to use right button, Edit, mark, enter, but I am looking for a simpler procedure, where all accepted data is copied to the clipboard.  It is then up to the user to paste or not this info.in an other program.

thanks for any help


#clipboard

The following is an example of how this can be done using the Windows Clipboard API functions.

       id division.
       program-id.   testclip.
       special-names.
          call-convention 74 is winapi.
       working-storage section.
       78 GMEM-MOVEABLE                value 2.
       78 CF-TEXT                      value 1.
       01 hWndNewOwner pic x(4) comp-5 value zeroes.
       01 retCode      pic x(4) comp-5 value zeroes.
       01 any-key      pic x.
       01 myHandle     pointer.
       01 myPointer    pointer.
       linkage section.
       01 datatocopy   pic x(30).
       procedure division.

           call winapi "GlobalAlloc"
             using by value GMEM-MOVEABLE
                    by value length of datatocopy
              returning myHandle
           end-call
           call winapi "GlobalLock"
              using by value myHandle
              returning myPointer
           end-call
           set address of datatocopy to myPointer
           move z"This is a test" to datatocopy  *> null terminate text
           call winapi "GetActiveWindow"
              returning hWndNewOwner
           end-call

           call winapi "OpenClipboard"
              using by value hWndNewOwner
              returning retCode
           end-call
           if retCode = 0
              display "error"
           else
              call winapi "EmptyClipboard"
              call winapi "SetClipboardData"
                 using by value CF-TEXT
                       by reference datatocopy
              end-call
              call winapi "CloseClipboard"
           end-if
           call winapi "GlobalUnlock"
              using by value myHandle
              returning retCode
           end-call
           call winapi "GlobalFree" using by value myHandle
           stop run.


Is there a simple way with NETEXPRESS 5.1 (CALL, Function, or MOVE) to send info from a text based program to the Clipboard - memory?

Of course there is the possibility to use right button, Edit, mark, enter, but I am looking for a simpler procedure, where all accepted data is copied to the clipboard.  It is then up to the user to paste or not this info.in an other program.

thanks for any help


#clipboard

Thank you. It works perfectly.  

But I thought just by replacing SetClipboardData by GetClipboardData I can inverse the process, but I suppose something else must also be changed?


Is there a simple way with NETEXPRESS 5.1 (CALL, Function, or MOVE) to send info from a text based program to the Clipboard - memory?

Of course there is the possibility to use right button, Edit, mark, enter, but I am looking for a simpler procedure, where all accepted data is copied to the clipboard.  It is then up to the user to paste or not this info.in an other program.

thanks for any help


#clipboard

Here is a revised program that will read the clipboard after it sets it. You should immediately copy the returned data to a working-storage variable and then close the clipboard. Use only the copy of the data and not the returned data itself as this belongs to the clipboard and not the program. Also be aware that the clipboard can contain data other than text. The program below checks for that:

       id division.
       program-id.   testclip.
       special-names.
          call-convention 74 is winapi.
       working-storage section.
       78 GMEM-MOVEABLE                value 2.
       78 CF-TEXT                      value 1.
       01 hWndNewOwner pic x(4) comp-5 value zeroes.
       01 retCode      pic x(4) comp-5 value zeroes.
       01 any-key      pic x.
       01 myHandle     pointer.
       01 myPointer    pointer.
       01 sub1         pic 9(5) value zeroes.
       01 mywsdata     pic x(30) value spaces.
       linkage section.
       01 datatocopy   pic x(30).
       01 datatoget    pic x(30).
       procedure division.

           call winapi "GlobalAlloc"
             using by value GMEM-MOVEABLE
                    by value length of datatocopy
              returning myHandle
           end-call
           call winapi "GlobalLock"
              using by value myHandle
              returning myPointer
           end-call
           set address of datatocopy to myPointer
           move z"This is a test" to datatocopy  *> null terminate text
           call winapi "GetActiveWindow"
              returning hWndNewOwner
           end-call

           call winapi "OpenClipboard"
              using by value hWndNewOwner
              returning retCode
           end-call
           if retCode = 0
              display "error"
           else
              call winapi "EmptyClipboard"
              call winapi "SetClipboardData"
                 using by value CF-TEXT
                       by reference datatocopy
              end-call
              call winapi "CloseClipboard"
           end-if
           call winapi "GlobalUnlock"
              using by value myHandle
              returning retCode
           end-call
           call winapi "GlobalFree" using by value myHandle
           call winapi "OpenClipboard"
              using by value hWndNewOwner
              returning retCode
           end-call
           if retCode = 0
              display "error"
           else
              call winapi "GetClipboardData"
                 using by value CF-TEXT
                 returning myHandle
              end-call
              if myHandle = null
                 display "Clipboard data not text!"
              else
                 set address of datatoget to myHandle
                 perform varying sub1 from 1 by 1
                    until sub1 > length mywsdata
                    if datatoget(sub1:1) = x"00"
                       exit perform
                    end-if
                 end-perform
                 move datatoget(1:sub1 - 1) to mywsdata
                 display mywsdata
              end-if
              call winapi "CloseClipboard"
           end-if

           stop run.