update clipboard func

master
兔子 9 months ago
parent 9b003f3e9d
commit ad19f5cd42

@ -215,16 +215,35 @@ func GetClipboardOwner() (HWND, error) {
return HWND(r), nil
}
func GetUpdatedClipboardFormats() ([]DWORD, error) {
var formats []DWORD
for i := 0; ; i++ {
format, err := EnumClipboardFormats(DWORD(i))
if err != nil {
break
}
formats = append(formats, format)
func GetUpdatedClipboardFormats(lpuiFormats unsafe.Pointer, cFormats int, pcFormats unsafe.Pointer) (int, error) {
user32, err := syscall.LoadLibrary("user32.dll")
if err != nil {
return 0, errors.New("Can't Load User32 API")
}
return formats, nil
defer syscall.FreeLibrary(user32)
gucf, err := syscall.GetProcAddress(syscall.Handle(user32), "GetUpdatedClipboardFormats")
if err != nil {
return 0, errors.New("Can't Load GetUpdatedClipboardFormats API")
}
r, _, errno := syscall.Syscall(gucf, 3, uintptr(lpuiFormats), uintptr(cFormats), uintptr(pcFormats))
if r == 0 {
return 0, error(errno)
}
return int(r), nil
}
func GetUpdatedClipboardFormatsAll() ([]DWORD, error) {
var res []DWORD
formats := make([]uint32, 32)
var count uint32
_, err := GetUpdatedClipboardFormats(unsafe.Pointer(&formats[0]), len(formats), unsafe.Pointer(&count))
if err != nil {
return nil, err
}
for i := 0; i < int(count); i++ {
res = append(res, DWORD(formats[i]))
}
return res, err
}
func IsClipboardFormatAvailable(uFormat DWORD) (bool, error) {

@ -16,6 +16,7 @@ func TestClipboardReadText(t *testing.T) {
t.Error(err)
}
tp := CF_UNICODETEXT
fmt.Println("lenghth", len(formats))
for _, f := range formats {
fmt.Println("Clipboard Format:", f)
d, e := GetClipboardFormatName(f)
@ -25,9 +26,12 @@ func TestClipboardReadText(t *testing.T) {
fmt.Println("HTML Format:", tp)
}
if d == "DataObject" {
tp = CF_HDROP
tp = f
fmt.Println("DataObject:", tp)
}
if f > 20000 {
tp = f
}
}
mem, err := GetClipboardData(tp)
@ -56,10 +60,19 @@ func TestClipboardReadText(t *testing.T) {
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:", string(buf))
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)
}

Loading…
Cancel
Save