1

我正在尝试在 VB.net 中构建一个类似于 Windows 文件资源管理器的应用程序。我想使用在文件资源管理器中右键单击文件时显示的相同窗口,单击菜单中的属性。问题是,这很容易解决,但仅当我的应用程序编译为 32 位应用程序时才有效,当我将其编译为 64 位时,这不起作用。

我想要两种答案:

  1. 最好的办法是从 64 位应用程序显示此文件属性窗口。
  2. 第二个最好的方法是创建一个 32 位应用程序作为包装器,其目的只是为了显示文件属性窗口。我几乎可以解决这个问题,但我不知道如何在单击“确定”或“取消”按钮时进行跟踪。

下面是我使用的代码,在 32 位 VB.net 中运行良好:

  Private Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (ByRef SEI As SHELLEXECUTEINFO) As Integer

  Private Structure SHELLEXECUTEINFO
    Dim cbSize As Integer
    Dim fMask As Integer
    Dim hwnd As Integer
    Dim lpVerb As String
    Dim lpFile As String
    Dim lpParameters As String
    Dim lpDirectory As String
    Dim nShow As Integer
    Dim hInstApp As Integer
    Dim lpIDList As Integer
    Dim lpClass As String
    Dim hkeyClass As Integer
    Dim dwHotKey As Integer
    Dim hIcon As Integer
    Dim hProcess As Integer
  End Structure

  Private Const SEE_MASK_INVOKEIDLIST As Short = &HCS
  Private Const SEE_MASK_NOCLOSEPROCESS As Short = &H40S
  Private Const SEE_MASK_FLAG_NO_UI As Short = &H400S
  Private Const SW_SHOWNORMAL As Integer = 1

Public Function ShowProps(ByVal FileName As String, ByVal OwnerhWnd As Integer) As Boolean
    Dim SEI As SHELLEXECUTEINFO = Nothing
    Dim r As Integer
    With SEI
      .cbSize = Len(SEI)
      .fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
      .hwnd = OwnerhWnd
      .lpVerb = "properties"
      .lpFile = FileName
      .lpParameters = vbNullChar
      .lpDirectory = vbNullChar
      .nShow = 0
      .hInstApp = 0
      .lpIDList = 0
    End With
    r = ShellExecuteEX(SEI)
    If r <= 0 Then
      Return False
    End If

    Return True
  End Function
4

0 回答 0