-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhdrop.go
63 lines (53 loc) · 1.78 KB
/
hdrop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package wingo
import (
"github.com/rogeecn/wingo/proc"
"syscall"
"unsafe"
"github.com/rogeecn/wingo/errco"
)
// A handle to an internal drop structure.
//
// 📑 https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hdrop
type HDROP HANDLE
// Prefer using HDROP.ListFilesAndFinish().
//
// 📑 https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-dragfinish
func (hDrop HDROP) DragFinish() {
syscall.Syscall(proc.DragFinish.Addr(), 1,
uintptr(hDrop), 0, 0)
}
// Prefer using HDROP.ListFilesAndFinish().
//
// 📑 https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-dragqueryfilew
func (hDrop HDROP) DragQueryFile(
iFile uint32, lpszFile *uint16, cch uint32) uint32 {
ret, _, err := syscall.Syscall6(proc.DragQueryFile.Addr(), 4,
uintptr(hDrop), uintptr(iFile), uintptr(unsafe.Pointer(lpszFile)),
uintptr(cch), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return uint32(ret)
}
// Returns true if dropped within client area.
//
// 📑 https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-dragquerypoint
func (hDrop HDROP) DragQueryPoint() (POINT, bool) {
var pt POINT
ret, _, _ := syscall.Syscall(proc.DragQueryPoint.Addr(), 2,
uintptr(hDrop), uintptr(unsafe.Pointer(&pt)), 0)
return pt, ret != 0
}
// Retrieves all file names with DragQueryFile() and calls DragFinish().
func (hDrop HDROP) ListFilesAndFinish() []string {
var pathBuf [_MAX_PATH + 1]uint16 // buffer to receive all paths
count := hDrop.DragQueryFile(0xffff_ffff, nil, 0)
paths := make([]string, 0, count) // paths to be returned
for i := uint32(0); i < count; i++ {
hDrop.DragQueryFile(i, &pathBuf[0], uint32(len(pathBuf)))
paths = append(paths, Str.FromNativeSlice(pathBuf[:]))
}
hDrop.DragFinish()
Path.Sort(paths)
return paths
}