我把一个或者多个文件用鼠标左键选中,拖拽到一个walk的textEdit中,现在不知道怎么实现。
打算获取鼠标事件,然后获取剪切板里面的文件内容,看到walk只有获取剪切板文本内容,没有获取文件的。
```
// Text returns the current text data of the clipboard.
func (c *ClipboardService) Text() (text string, err error) {
err = c.withOpenClipboard(func() error {
hMem := win.HGLOBAL(win.GetClipboardData(win.CF_UNICODETEXT))
if hMem == 0 {
return lastError("GetClipboardData")
}
p := win.GlobalLock(hMem)
if p == nil {
return lastError("GlobalLock()")
}
defer win.GlobalUnlock(hMem)
text = win.UTF16PtrToString((*uint16)(p))
return nil
})
return
}
```
以上是walk的
```
func (c *ClipboardService) File() (fileName string, err error) {
err = c.withOpenClipboard(func() error {
hMem := win.HGLOBAL(win.GetClipboardData(win.CF_HDROP))// CF_HDROP文件类型
if hMem == 0 {
return lastError("GetClipboardData")
}
p := win.GlobalLock(hMem)
if p == nil {
return lastError("GlobalLock()")
}
defer win.GlobalUnlock(hMem)
fmt.Println(p)
//在这边不知道怎么写了
// fileName = win.UTF16PtrToString((*uint16)(p))
return nil
})
return
}
```
不知道怎么获取文件路径 网上看来好久都没有解决。求指点
```
package main
import (
"log"
"strings"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
type MyMainWindow struct {
*walk.MainWindow
textEdit *walk.TextEdit
}
func main() {
mw := new(MyMainWindow)
if err := (MainWindow{
AssignTo: &mw.MainWindow,
Title: "Walk DropFiles Example",
MinSize: Size{320, 300},
Layout: VBox{MarginsZero: true},
Children: []Widget{
TextEdit{
ReadOnly: true,
Text: "No drop files...",
},
TextEdit{
AssignTo: &mw.textEdit,
ReadOnly: true,
Text: "Drop files here, from windows explorer...",
},
},
}.Create()); err != nil {
log.Fatal(err)
}
mw.textEdit.DropFiles().Attach(func(files []string) {
mw.textEdit.SetText(strings.Join(files, "\r\n"))
})
mw.Run()
}
```
#5
更多评论
![39.png](http://studygolang.qiniudn.com/170621/d78e87639487ab048c839c9f1ebd7d3e.png)
#1