托拽Explore中的文件到VB.net的窗口

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 40star 的 blog

要让vb.net相应外部托拽来的文件,需处理wm_dropfiles消息。

private declare sub dragacceptfiles lib "shell32.dll" (byval hwnd as int32, byval faccept as int32)
private declare sub dragfinish lib "shell32.dll" (byval hdrop as int32)
private declare function dragqueryfile lib "shell32.dll" alias "dragqueryfilea" (byval hdrop as int32, byval uint as int32, byval lpstr as

string, byval ch as int32) as int32

private const wm_dropfiles = &h233
private const max_length = 255

protected overrides sub wndproc(byref m as system.windows.forms.message)
    if m.msg = wm_dropfiles then
        dragfiles(m.wparam.toint32)
        exit sub
    end if
    mybase.wndproc(m)
end sub

private sub dragfiles(byval hdrop as int32)
    dim ireturn as int32
    dim sfile as string
    sfile = space(max_length)
    ireturn = dragqueryfile(hdrop, 0, sfile, max_length)
    if ireturn then
        textbox3.text = sfile
        picturebox1.image = image.fromfile(trim(textbox3.text))
        dragfinish(hdrop)
    end if
end sub

我的代码只是适用于.net的picturebox能用的图像文件噢!

本文关键:WM_DROPFILES VB.net
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top