golang walk获取剪切板里面的文件路径

Shadow-Liu · 2017-06-21 09:32:28 · 3418 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2017-06-21 09:32:28 的主题,其中的信息可能已经有所发展或是发生改变。

我把一个或者多个文件用鼠标左键选中,拖拽到一个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
}

不知道怎么获取文件路径 网上看来好久都没有解决。求指点


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3418 次点击  
加入收藏 微博
10 回复  |  直到 2017-06-24 16:27:23
Shadow-Liu
Shadow-Liu · #1 · 8年之前

39.png

channel
channel · #2 · 8年之前

walk 这个项目作者还维护吗?

Shadow-Liu
Shadow-Liu · #3 · 8年之前
channelchannel #2 回复

walk 这个项目作者还维护吗?

不知道我也才学golang 大算用他做几工具。

channel
channel · #4 · 8年之前

github 上看了下,还在维护。

CodyGuo
CodyGuo · #5 · 8年之前
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()
}
Shadow-Liu
Shadow-Liu · #6 · 8年之前
CodyGuoCodyGuo #5 回复

``` 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() } ```

谢了 十分感谢

Shadow-Liu
Shadow-Liu · #7 · 8年之前
CodyGuoCodyGuo #5 回复

``` 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() } ```

知道这个Text内容怎么换行不 \n不起作用 \t可以。

Shadow-Liu
Shadow-Liu · #8 · 8年之前
CodyGuoCodyGuo #5 回复

``` 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() } ```

忽然发现\r\n这样可以换行

Shadow-Liu
Shadow-Liu · #9 · 8年之前
CodyGuoCodyGuo #5 回复

``` 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() } ```

B0A8E43F-314C-4472-974A-A6A7E1AA6DA2.png 怎么弄出一个下拉条 内容多了 就看不到了

Shadow-Liu
Shadow-Liu · #10 · 8年之前
CodyGuoCodyGuo #5 回复

``` 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() } ```

HScroll:true, VScroll:true, 知道了。。

添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传