Prerequisites |
None. |
|
Using
using this simple routine, the SHELLEXECUTEINFO type structure and the ShellExecuteEx() API, 32 bit Visual Basic applications can display the
file property page for any passed file on Windows 95, 98 or NT4. As long as the path to the file is known, this routine can be invoked. It
works for both registered and unregistered Windows file types, as well as bringing up the DOS property sheet for DOS applications or files
(try pointing the app to autoexec.bat).
Thanks go out to Ian Land for providing the Delphi code, and Roy Meyers for sending it to me for VBnet. |
|
BAS
Module Code |
None. |
|
|
Form
Code |
|
To a project form add two command buttons (Command1 and
Command2) and a text box (Text1). Add the following to the form: |
|
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long 'Optional
lpClass As String 'Optional
hkeyClass As Long 'Optional
dwHotKey As Long 'Optional
hIcon As Long 'Optional
hProcess As Long 'Optional
End Type
Private Const SEE_MASK_INVOKEIDLIST = &HC
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400
Private Declare Function ShellExecuteEx Lib "shell32" _
Alias "ShellExecuteExA" _
(SEI As SHELLEXECUTEINFO) As Long
Private Sub Form_Load()
Command1.Caption = "Show Properties"
'assure string points to a valid file
'on your system
Text1.Text = "c:\windows\notepad.exe"
End Sub
Private Sub Command1_Click()
'show the properties dialog, passing the filename
'and the owner of the dialog
Call ShowProperties(Text1.Text, Me.hwnd)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub ShowProperties(sFilename As String, hWndOwner As Long)
'open a file properties property page for
'specified file if return value
Dim SEI As SHELLEXECUTEINFO
'Fill in the SHELLEXECUTEINFO structure
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or _
SEE_MASK_INVOKEIDLIST Or _
SEE_MASK_FLAG_NO_UI
.hwnd = hWndOwner
.lpVerb = "properties"
.lpFile = sFilename
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
'call the API to display the property sheet
Call ShellExecuteEX(SEI)
End Sub |
|
Comments |
Run the project, enter a file path and name into the
textbox, and hit properties. The Windows properties page for the specified file will appear. This code displays only a single property page,
even if multiple files are selected. At this time I know of no API call that displays the Explorer property page showing the file size sum
from a selection of multiple files, other than passing a folder instead
to retrieve the total folder size. |
|