|
|
|
package win32api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClipboardReadText(t *testing.T) {
|
|
|
|
if err := OpenClipboard(0); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
formats, err := EnumAllClipboardFormats()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
tp := CF_UNICODETEXT
|
|
|
|
fmt.Println("lenghth", len(formats))
|
|
|
|
for _, f := range formats {
|
|
|
|
fmt.Println("Clipboard Format:", f)
|
|
|
|
d, e := GetClipboardFormatName(f)
|
|
|
|
fmt.Println("Clipboard Format Name:", d, e)
|
|
|
|
if d == "HTML Format" {
|
|
|
|
tp = RegisterClipboardFormat("HTML Format")
|
|
|
|
fmt.Println("HTML Format:", tp)
|
|
|
|
}
|
|
|
|
if d == "DataObject" {
|
|
|
|
tp = f
|
|
|
|
fmt.Println("DataObject:", tp)
|
|
|
|
}
|
|
|
|
if f > 20000 {
|
|
|
|
tp = f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mem, err := GetClipboardData(tp)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
p, err := GlobalLock(mem)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
defer GlobalUnlock(mem)
|
|
|
|
//n := 0
|
|
|
|
if tp == 13 {
|
|
|
|
var buf []uint16
|
|
|
|
for ptr := unsafe.Pointer(p); *(*uint16)(ptr) != 0; ptr = unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(*((*uint16)(unsafe.Pointer(p))))) {
|
|
|
|
buf = append(buf, *(*uint16)(ptr))
|
|
|
|
}
|
|
|
|
str := syscall.UTF16ToString(buf)
|
|
|
|
fmt.Println("\n\nClipboard Data:", str)
|
|
|
|
if err := CloseClipboard(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
size, err := GlobalSize(mem)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Size:", size)
|
|
|
|
var buf []byte
|
|
|
|
for i := 0; i < int(size); i++ {
|
|
|
|
buf = append(buf, *(*byte)(unsafe.Pointer(uintptr(p) + uintptr(i))))
|
|
|
|
}
|
|
|
|
fmt.Println("\n\nClipboard Data:", "ok")
|
|
|
|
fmt.Println("Clipboard Test Done")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUpdatedClipboardFormatsAll(t *testing.T) {
|
|
|
|
d, e := GetUpdatedClipboardFormatsAll()
|
|
|
|
if e != nil {
|
|
|
|
t.Error(e)
|
|
|
|
}
|
|
|
|
fmt.Println(d)
|
|
|
|
}
|