but when it tries to retrieve the HTML format from the clueboard ClipboardGet_HTML it returns as if there's no HTML format in the clipboard.
the stranger thing is when I ran only the ClipboardGet_HTML in its own ahk file it works (retrieves the HTML format that is still in the clipboard)
any idea why?
Code: Select all
s::
a := "<b>test 123 test</b>"
SetClipboardHTML(a)
sleep 2000
If ClipboardGet_HTML( DataInClip )
MsgBox, % DataInClip
Else MsgBox, no HTML format?
Return
SetClipboardHTML(HtmlBody, SourceURL="", AltText:="") {
Local F, Html, pMem, Bytes, hMemHTM:=0, hMemTXT:=0, Res1:=1, Res2:=1
Static CF_UNICODETEXT:=13, CFID:=DllCall("RegisterClipboardFormat", Str ,"HTML Format", UInt)
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" . SourceURL . "`r`n<html>`r`n<body>`r`n<!--StartFragment--><meta charset=""utf-8"">"
. HtmlBody . "<!--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")
RegExMatch(Html, "mP)(*UCP)\X*(?=<html>)" , StartHTML)
formattedString := Format("StartHTML:{:08d}", StartHTML)
Html := StrReplace(Html, "StartHTML:00000000", formattedString)
StrPut(Format("{:08}", StartHTML), pMem+23, 8, "utf-8")
EndHTML := StrLen(Html)
formattedString := Format("EndHTML:{:08d}", EndHTML)
Html := StrReplace(Html, "EndHTML:00000000", formattedString)
StrPut(Format("{:08}", EndHTML), pMem+41, 8, "utf-8")
RegExMatch(Html, "mP)(*UCP)\X*<!--StartFragment-->" , StartFragment)
formattedString := Format("StartFragment:{:08d}", StartFragment)
Html := StrReplace(Html, "StartFragment:00000000", formattedString)
StrPut(Format("{:08}", StartFragment), pMem+65, 8, "utf-8")
RegExMatch(Html, "mP)(*UCP)\X*(?=<!--EndFragment-->)" , EndFragment)
formattedString := Format("EndFragment:{:08d}", EndFragment)
Html := StrReplace(Html, "EndFragment:00000000", formattedString)
StrPut(Format("{:08}", EndFragment), pMem+87, 8, "utf-8")
FileDelete, 111.html
FileAppend, %Html%, 111.html,UTF-8
;Msgbox, % Html
DllCall("GlobalUnlock", "Ptr",hMemHTM)
Res1 := DllCall("SetClipboardData", "Int",CFID, "Ptr",hMemHTM)
;Msgbox, % Html
}
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")
if (hMemHTM != 0) {
DllCall("GlobalFree", "Ptr",hMemHTM)
hMemHTM = 0
}
Return (Res1 & Res2)
}
ClipboardGet_HTML( byref DataInClip ) { ; www.autohotkey.com/forum/viewtopic.php?p=392624#392624
If CBID := DllCall( "RegisterClipboardFormat", Str,"HTML Format", UInt )
If DllCall( "IsClipboardFormatAvailable", UInt,CBID ) <> 0
If DllCall( "OpenClipboard", UInt,0 ) <> 0
If hData := DllCall( "GetClipboardData", UInt,CBID, UInt )
DataL := DllCall( "GlobalSize", UInt,hData, UInt )
, pData := DllCall( "GlobalLock", UInt,hData, UInt )
, DataInClip := StrGet( pData, dataL, "UTF-8" )
, DllCall( "GlobalUnlock", UInt,hData )
DllCall( "CloseClipboard" )
Return dataL ? dataL : 0
}
esc::
ExitApp,
return