[Fortran] 纯文本查看 复制代码
Program www_fcode_cn
implicit none
character(len=100) :: c
integer :: j
j = getClipboardText(c)
if(j>0) write(*,'(a)') trim(c)
contains
Integer Function getClipboardText( text ) result( length )
use , intrinsic :: ISO_C_Binding
use user32
use kernel32
Character(len=*) :: text
integer :: hData , j
type(c_ptr) :: cp
character(len=len(text)) , pointer :: p
length = 0
text = ""
if ( 0==OpenClipboard(0) ) return
hData = GetClipboardData(CF_TEXT)
if ( hData /= 0 ) then
call c_f_pointer(transfer(GlobalLock(hData),cp),p)
length = index(p,c_null_char)-1
if(length<0) length = len(text)
text = p(:length)
j = GlobalUnlock(hData)
end if
j = CloseClipboard()
End Function getClipboardText
End Program www_fcode_cn
[Fortran] 纯文本查看 复制代码
subroutine setClipboardText( text )
use , intrinsic :: ISO_C_Binding
use user32
use kernel32
Character(len=*) :: text
integer :: hData , j
type(c_ptr) :: cp
character(len=len(text)) , pointer :: p
if ( 0==OpenClipboard(0) ) return
j = EmptyClipboard()
hData = GlobalAlloc(GMEM_MOVEABLE,len(text)+1)
if ( hData /= 0 ) then
call c_f_pointer(transfer(GlobalLock(hData),cp),p)
p = text
j = GlobalUnlock(hData)
j = SetClipboardData(CF_TEXT,hData)
end if
j = CloseClipboard()
End subroutine