Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

copy text to or from clipbard

hkausl
Beginner
919 Views
Hello,
I want to copy some text (character area) from my quickwin-application to the clipboard and read from the clopboard. Is there an examle how this can be done. Thanks.

Solved, found an example
0 Kudos
3 Replies
Steven_L_Intel1
Employee
919 Views
Perhaps you could post some code or point others to the example you found?
0 Kudos
joerg_kuthe
Novice
919 Views
Here is some example I worked out a couple of years ago:
[bash]!     Last change:  JK    1 May 97    7:58 pm
SUBROUTINE PrintErr
   USE DFWIN
   PRINT*,'Error code= ',GetLastError()
END SUBROUTINE

PROGRAM ClipBoard
   USE DFWIN
	IMPLICIT NONE
	CHARACTER, DIMENSION (:), ALLOCATABLE ::  CBCopy
	INTEGER (KIND=HANDLE) :: hWndNewOwner, hClipboardData
	INTEGER (KIND=DWORD) :: CBObjectSize
   INTEGER (BOOL) bRet
   INTEGER :: ErrorCode, lpClipboardData, lpCBCopy

   PRINT*,'Program ClipBoard returns current clipboard contents (text).'

   hWndNewOwner = NULL
   IF ( OpenClipboard(hWndNewOwner) ) THEN
      hClipboardData = GetClipboardData(CF_TEXT)
      IF (hClipboardData == NULL) THEN
      	CALL PrintErr
      ELSE
	      PRINT*,'ClipBoard handle = ',hClipboardData
         CBObjectSize = GlobalSize(hClipboardData)
	      PRINT*,'ClipBoard object size = ', CBObjectSize
!      lock clipboard handle and get pointer to the beginning of the block
			lpClipboardData = GlobalLock (hClipboardData)
!      allocate memory to copy clipboard contents to
         ALLOCATE(CBCopy(1:CBObjectSize), STAT=ErrorCode)
         IF (ErrorCode/=0) THEN
	         PRINT*,'ALLOCATE failed, ErrorCode = ',ErrorCode
         ELSE
!         copy clipboard memory contents to CBCopy (use CopyMemory function)
				lpCBCopy = LOC(CBCopy)
				CALL CopyMemory( lpCBCopy, lpClipboardData, CBObjectSize )
            !IF ( .EQ.NULL) THEN
	         !	PRINT*,'CopyMemory failed'
            !ELSE
            	PRINT*,'Clipboard contents: ',CBCopy(1:CBObjectSize)
            !END IF
!			 Unlock clipboard block
            bRet = GlobalUnlock (hClipboardData) 
				IF ( bRet == 0 ) THEN
				   ErrorCode = GetLastError()
           		PRINT*,'GlobalUnlock failed'
            	IF (ErrorCode == ERROR_ENVVAR_NOT_FOUND) THEN
                  PRINT*,'  ErrorCode = ERROR_ENVVAR_NOT_FOUND; do not ask me why this...'
               ELSE
                  PRINT*,'  ErrorCode = ', ErrorCode
             	END IF
            END IF
!         deallocate CBCopy
         	DEALLOCATE(CBCopy, STAT=ErrorCode)
         	IF (ErrorCode/=0) PRINT*,'DEALLOCATE failed, ErrorCode = ',ErrorCode
         END IF
      END IF
      IF (.NOT. CloseClipboard() ) CALL PrintErr
   ELSE
      CALL PrintErr
   END IF

   pause
END PROGRAM
[/bash]

I just tested that and it still works almost error free. I am getting an error 1418 on the call of
[bash]CloseClipboard() [/bash]
(meaning: Thread does not have a clipboard open). Maybe someone has an idea what's wrong.

Kind regards,

Jrg Kuthe
www.qtsoftware.com
0 Kudos
rwg
Novice
919 Views
The documentation of CloseClipboard says:

Return Values

Nonzero indicates success. Zero indicates failure.

So replace
IF (.NOT. CloseClipboard()) CALL PrintErr
with
IF (CloseClipboard()==0) Call PrintErr

The document also says that the return value is of type BOOL but keep in mind that a BOOL is not a LOGICAL. (see http://software.intel.com/en-us/forums/showthread.php?t=41785&o=a&s=lr)

0 Kudos
Reply