Windows: Add OpenFileProperties method
This commit is contained in:
parent
22cf38d83c
commit
a5075cc7f4
36
Windows/File.vb
Normal file
36
Windows/File.vb
Normal file
@ -0,0 +1,36 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Windows.NativeMethods
|
||||
|
||||
Public Class File
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As Logger
|
||||
|
||||
Public Sub New(LogConfig As LogConfig)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
End Sub
|
||||
|
||||
Public Function OpenFileProperties(FilePath As String) As Boolean
|
||||
Try
|
||||
Dim oShellExecuteInfo As New ShellExecuteInfo()
|
||||
oShellExecuteInfo.cbSize = Marshal.SizeOf(oShellExecuteInfo)
|
||||
oShellExecuteInfo.lpVerb = "properties"
|
||||
oShellExecuteInfo.lpFile = FilePath
|
||||
oShellExecuteInfo.nShow = SW_SHOW
|
||||
oShellExecuteInfo.fMask = SEE_MASK_INVOKEIDLIST
|
||||
|
||||
If Not ShellExecuteEx(oShellExecuteInfo) Then
|
||||
Dim oWin32Error = Marshal.GetLastWin32Error()
|
||||
Dim oException As New Win32Exception(oWin32Error)
|
||||
Throw oException
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
@ -5,6 +5,9 @@ Public Class NativeMethods
|
||||
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Int32) As Integer
|
||||
Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer
|
||||
|
||||
<DllImport("Shell32", CharSet:=CharSet.Auto, SetLastError:=True)>
|
||||
Public Shared Function ShellExecuteEx(ByRef lpExecInfo As ShellExecuteInfo) As Boolean
|
||||
End Function
|
||||
<DllImport("user32.dll")>
|
||||
Public Shared Function GetDC(ByVal hwnd As IntPtr) As IntPtr
|
||||
End Function
|
||||
@ -97,6 +100,10 @@ Public Class NativeMethods
|
||||
Public Const MEM_MAPPED As Integer = &H40000
|
||||
Public Const MEM_TOP_DOWN As Integer = &H100000
|
||||
Public Const INVALID_HANDLE_VALUE As Integer = -1
|
||||
Public Const SW_SHOW As Short = 5
|
||||
Public Const SEE_MASK_INVOKEIDLIST = &HC
|
||||
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
|
||||
Public Const SEE_MASK_FLAG_NO_UI = &H400
|
||||
|
||||
Public Enum PageProtection As UInteger
|
||||
NoAccess = &H1
|
||||
@ -130,6 +137,24 @@ Public Class NativeMethods
|
||||
End Function
|
||||
End Structure
|
||||
|
||||
Public Structure ShellExecuteInfo
|
||||
Public cbSize As Integer
|
||||
Public fMask As Integer
|
||||
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 Integer
|
||||
Public hIcon As IntPtr
|
||||
Public hProcess As IntPtr
|
||||
End Structure
|
||||
|
||||
<System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
|
||||
Public Structure PointAPI
|
||||
Public X As Integer
|
||||
|
||||
@ -75,6 +75,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Drawing.vb" />
|
||||
<Compile Include="File.vb" />
|
||||
<Compile Include="NativeMethods.vb" />
|
||||
<Compile Include="Utils.vb" />
|
||||
<Compile Include="Window.vb" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user