本帖最后由 andy8496 于 2023-2-28 10:07 编辑
我依葫芦画瓢写了个设置剪贴板内容的子程序,Win 7能正常运行,但是Win 10就不行了……烦请大神帮给看看,多谢多谢!
[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
|