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

clipboard

jmloriot
Beginner
674 Views

Hello,

First a great thank you to INTEL for developing IVF and to Steve for maintaining this very helpful forum.

Now my question :

How can a IVF program write into the clipboard so that I can just paste to get a text into a window application (word or outlook) ?
Thanks

0 Kudos
5 Replies
anthonyrichards
New Contributor III
674 Views
First, you need to use GlobalAlloc to allocate the number of bytes required to store your text.
For example:

hTextBytes = GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, numberofbytes) ! Returns a handle to the memory object
hText = GlobalLock(hTextBytes) ! Returns a pointer to the first byte of the memory block and locks it for use

Then you put your text into the memory buffer pointed to by hText (use pointer-> target for example where target is a character variable)

Then you need to use the Clipboard functions.

iret=OpenClipboard(hWindow) !claim ownership of the clipboard for your window, handle hWindow
iret = SetClipboardData(CF_TEXT, hTextBytes) !Copy the contents onto clipboard
iret=CloseClipboard() ! Release the clipboard
iret = GlobalUnlock(hTextBytes) ! unlock the allocated memory
iret = GlobalFree(hTextBytes) ! Free the momory

CF_TEXT is a standard clipboard format for text where each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. Use this format for ANSI text.

You could put all this into a routine CopyToClipboard that supplies a pointer/address of an allocated character string containing the text that you want to copy to the clipboard. You could then determine the the number of bytes in the input text string, determine its starting location using LOC(string) , then use CopyMemory to copy the input text string from its memory location to the allocated memory block and then to the clipboard. You might even be able to copy directly from the input string to the clipboard.



0 Kudos
jmloriot
Beginner
674 Views
Hi Anthonyrichards,
Thanks for your quick answer.
Which file do I have to "USE" to include the clipboard functions ?
0 Kudos
jmloriot
Beginner
674 Views
Hi Anthonyrichards,
I found it.... and it works fine.
Thank you very much
Jean-Marc Loriot
0 Kudos
rase
New Contributor I
674 Views
For all of us: what library did you include with "use" to get the clipboard functions?
0 Kudos
anthonyrichards
New Contributor III
674 Views
USE USER32

USER32.LIB is a standard windows library that is usually included in the default library search list for the linker.
GlobalAlloc is in KERNEL32.LIB.

However, if you just use

USE IFWIN

that includes USEs for all the standard IVF and windows modules.
0 Kudos
Reply