如何使用vb.net显示/打开文件属性对话框 [英] How do I show/open the file properties dialogue with vb.net

查看:147
本文介绍了如何使用vb.net显示/打开文件属性对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自德国的问候

抱歉我的笨拙英语



我需要打开Windows通常提供的文件属性对话框。使用VB6从头开始构建它 - 以及一些(相当多)几年前会有很多代码 - 只需通过shellexecuteex和shellexuteinfo调用它就可以了。



我在网上搜索了一些snipplet,它们应该在vb.net中完成Job(见下面的代码)但是:它不起作用。它甚至不会产生错误消息。它确实......没什么。 (确切地说,如果我将项目设置切换到X86,它会在最后一行调用shellexecuteex时产生错误消息)但是当我离开x64(我想要)时它只会:没有。



我做错了什么?

代码有什么问题?

或者还有另一种办法吗?



非常感谢任何暗示



Michael



以下是代码:



Greetings from Germany
and sorry for my clumsy english

I Need to open the file-propertie dialogue as normally provided by Windows. It would be quite a lot of code to build it from scratch on my own - and some (quite some) years ago - with VB6 - it was quite simply to call it via shellexecuteex and shellexuteinfo.

I searched the net and found some snipplets which should do the Job in vb.net (see code below) But: it does not work. It doesn't even produce an errormessage. It does just...... nothing. (To be precise if i Switch Project Settings for compolation to X86 it does produce an error message when shellexecuteex is called in the last line) But when i leave to x64 (as i want) it just does: nothing.

What am i doing wrong ?
What is wrong with the code ?
Or is there another way to do the Job ?

Thanks a lot for any hint

Michael

And here is the code:

imports System.Runtime.InteropServices

Module Properties

    Public Structure SHELLEXECUTEINFO
        Public cbSize As IntPtr?
        Public fMask As IntPtr
        Public hwnd As IntPtr
        <MarshalAs(UnmanagedType.LPTStr)> Public lpVerb As String
        <MarshalAs(UnmanagedType.LPTStr)> Public lpFile As String
        <MarshalAs(UnmanagedType.LPTStr)> Public lpParameters As String
        <MarshalAs(UnmanagedType.LPTStr)> Public lpDirectory As String
        Dim nShow As Integer
        Dim hInstApp As IntPtr
        Dim lpIDList As IntPtr
        <MarshalAs(UnmanagedType.LPTStr)> Public lpClass As String
        Public hkeyClass As IntPtr
        Public dwHotKey As IntPtr
        Public hIcon As IntPtr
        Public hProcess As IntPtr
    End Structure

    Private Const SEE_MASK_FLAG_NO_UI = &H400
    Private Const SEE_MASK_INVOKEIDLIST = &HC
    Private Const SEE_MASK_NOCLOSEPROCESS = &H40
    Private Const SW_SHOW As Integer = 5
    'Dekclarationen zum Anzeigen der Dateieigenschaften
    Private Declare Function ShellExecuteEx Lib "shell32.dll" (LPSHELLEXECUTEINFO As SHELLEXECUTEINFO) As Long

    Public Sub ShowProperties(ByVal path As String)
        Dim fi As New IO.FileInfo(path)
        Dim info As New SHELLEXECUTEINFO()
        info.cbSize = CType(Marshal.SizeOf(info), IntPtr)
        info.lpVerb = "properties"
        info.lpFile = fi.Name
        info.lpDirectory = fi.DirectoryName
        info.nShow = CType(SW_SHOW, IntPtr)
        info.fMask = CType(SEE_MASK_INVOKEIDLIST, IntPtr)
        ShellExecuteEx(info)
    End Sub

End Module

推荐答案

下面你会看到我对你的代码做了一些修改。



Below you will see that i have made a few changes to your code.

Imports System.Runtime.InteropServices

Module PropertiesDialog

    Public Structure SHELLEXECUTEINFO
        Public cbSize As IntPtr
        Public fMask As IntPtr
        Public hwnd As IntPtr
        Public lpVerb As String 'Removed MarshalAs
        Public lpFile As String 'Removed MarshalAs
        Public lpParameters As String 'Removed MarshalAs
        Public lpDirectory As String 'Removed MarshalAs
        Dim nShow As Integer
        Dim hInstApp As IntPtr
        Dim lpIDList As IntPtr
        Public lpClass As String 'Removed MarshalAs
        Public hkeyClass As IntPtr
        Public dwHotKey As IntPtr
        Public hIcon As IntPtr
        Public hProcess As IntPtr
    End Structure

    Private Const SEE_MASK_FLAG_NO_UI = &H400
    Private Const SEE_MASK_INVOKEIDLIST = &HC
    Private Const SEE_MASK_NOCLOSEPROCESS = &H40
    Private Const SW_SHOW As Integer = 5
    'Dekclarationen zum Anzeigen der Dateieigenschaften
    Private Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef LPSHELLEXECUTEINFO As SHELLEXECUTEINFO) As Long 'Added ByRef

    Sub ShowProperties(ByVal path As String)
        Dim fi As New IO.FileInfo(path)
        Dim info As New SHELLEXECUTEINFO()
        info.cbSize = CType(Marshal.SizeOf(info), IntPtr)
        info.lpVerb = "properties"
        info.lpFile = fi.Name
        info.lpDirectory = fi.DirectoryName
        info.nShow = CType(SW_SHOW, IntPtr)
        info.fMask = CType(SEE_MASK_INVOKEIDLIST, IntPtr)
        ShellExecuteEx(info)
    End Sub

End Module


这篇关于如何使用vb.net显示/打开文件属性对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆