WinClip把指定文件放入剪切板、GIF、富文本和链接粘贴等例子.zip
Html剪贴板富文本+Gif示例.ahk
#NoEnv #SingleInstance Force SetBatchLines -1 ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=80706 ; 在 WinClip.SetHTML 上保留换行符 ; Clipboard := StrReplace(Clipboard, "`n", "<br>") ; 富文本带链接、字体加粗、字体颜色的示例【需在Word中粘贴】 F1:: 富文本= ( <a href="https://www.ahk66.com/ ">AutoHotkey精选资源站</a><br> <font size="5" color="FF00FF"><b>5号字体加粗_紫色</b><br> <i>5号字体换行_紫色</i><br></font> <font size="3" color="red">3号字第一行_红色<br></font> 3号字换行_原黑色<br> </font> ) SetClipboardHTML(富文本) SendInput ^v Return ; 将Gif存到剪贴板的示例 F3:: ImageFile := "D:/test.gif" HtmlGif转换 = ( <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD></HEAD> <BODY><!--StartFragment--><IMG src="%ImageFile%"><!--EndFragment--></BODY> </HTML> ) SetClipboardHTML(HtmlGif转换) SendInput ^v Return ; 官方帖子的回复示例【在QQ和Word中都能粘贴】 F4:: SetClipboardHTML("<div><b>Welcome to AutoHotkey</b></div>",, "Welcome to AutoHotkey") SendInput ^v Return SetClipboardHTML(HtmlBody, HtmlHead:="", AltText:="") { ; v0.67 by SKAN on D393/D42B Local F, Html, pMem, Bytes, hMemHTM:=0, hMemTXT:=0, Res1:=1, Res2:=1 ; @ tiny.cc/t80706 Static CF_UNICODETEXT:=13, CFID:=DllCall("RegisterClipboardFormat", "Str","HTML Format") if ! DllCall("OpenClipboard", "Ptr",A_ScriptHwnd) Return 0 else DllCall("EmptyClipboard") if (HtmlBody!="") Html := "Version:0.9`r`nStartHTML:00000000`r`nEndHTML:00000000`r`nStartFragment" . ":00000000`r`nEndFragment:00000000`r`n<!DOCTYPE>`r`n<html>`r`n<head>`r`n" . HtmlHead . "`r`n</head>`r`n<body>`r`n<!--StartFragment -->`r`n" . HtmlBody . "`r`n<!--EndFragment -->`r`n</body>`r`n</html>" , Bytes := StrPut(Html, "utf-8") , hMemHTM := DllCall("GlobalAlloc", "Int",0x42, "Ptr",Bytes+4, "Ptr") , pMem := DllCall("GlobalLock", "Ptr",hMemHTM, "Ptr") , StrPut(Html, pMem, Bytes, "utf-8") , F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","<html>", "Ptr") - pMem , StrPut(Format("{:08}", F), pMem+23, 8, "utf-8") , F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","</html>", "Ptr") - pMem , StrPut(Format("{:08}", F), pMem+41, 8, "utf-8") , F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","<!--StartFra", "Ptr") - pMem , StrPut(Format("{:08}", F), pMem+65, 8, "utf-8") , F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","<!--EndFragm", "Ptr") - pMem , StrPut(Format("{:08}", F), pMem+87, 8, "utf-8") , DllCall("GlobalUnlock", "Ptr",hMemHTM) , Res1 := DllCall("SetClipboardData", "Int",CFID, "Ptr",hMemHTM) if (AltText!="") Bytes := StrPut(AltText, "utf-16") , hMemTXT := DllCall("GlobalAlloc", "Int",0x42, "Ptr",(Bytes*2)+8, "Ptr") , pMem := DllCall("GlobalLock", "Ptr",hMemTXT, "Ptr") , StrPut(AltText, pMem, Bytes, "utf-16") , DllCall("GlobalUnlock", "Ptr",hMemTXT) , Res2 := DllCall("SetClipboardData", "Int",CF_UNICODETEXT, "Ptr",hMemTXT) DllCall("CloseClipboard") , hMemHTM := hMemHTM ? DllCall("GlobalFree", "Ptr",hMemHTM) : 0 Return (Res1 & Res2) }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)