copy到clipboard後,一般從clipboard讀回來的都是純文字。如果想讀到HTML code? Here is the solution in autohotkey.
^q::
msgbox %A_IsUnicode%
WinGetTitle, Title, A
Clip0 = %ClipBoardAll%
clipboard=
send ^c ; copy the selected content to clipboard
ClipWait, 0.5
If ClipboardGet_HTML( Data ){
msgbox, % Data
pos := InStr(Data,"<body")
Data:= SubStr( Data, pos)
MsgBox, % Data ; for debug
}
return
ClipboardGet_HTML( byref Data ) { ; 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 )
VarSetCapacity( data, dataL * ( A_IsUnicode ? 2 : 1 ) )
StrGet := "StrGet"
msgbox A_IsUnicode%A_IsUnicode%
A_IsUnicode ? Data := %StrGet%( pData, dataL, "UTF-8" ) : DllCall( "lstrcpyn", Str,Data, UInt,pData, UInt,DataL )
DllCall( "GlobalUnlock", UInt,hData )
;msgbox 9
}
DllCall( "CloseClipboard" )
Return dataL ? dataL : 0
}