|
本帖最后由 楚香饭 于 2022-4-12 12:15 编辑
这个以前恰好写过。不过只能读取粘贴板里的纯文本。对于 图像,文件,其他数据类型没有用。
[Fortran] 纯文本查看 复制代码 03 | character ( len = 100 ) :: c |
05 | j = getClipboardText ( c ) |
06 | if ( j > 0 ) write ( * , '(a)' ) trim ( c ) |
10 | Integer Function getClipboardText ( text ) result ( length ) |
11 | use , intrinsic :: ISO_C_Binding |
14 | Character ( len = * ) :: text |
17 | character ( len = len ( text ) ) , pointer :: p |
20 | if ( 0 == OpenClipboard ( 0 ) ) return |
21 | hData = GetClipboardData ( CF_TEXT ) |
22 | if ( hData /= 0 ) then |
23 | call c_f_pointer ( transfer ( GlobalLock ( hData ) , cp ) , p ) |
24 | length = index ( p , c_null_char ) -1 |
25 | if ( length < 0 ) length = len ( text ) |
27 | j = GlobalUnlock ( hData ) |
30 | End Function getClipboardText |
32 | End Program www_fcode_cn |
|
|