VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



File properties information. This application displays a file's properties information. It also c

by Stevan Mitrovic (2 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 3rd March 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

File properties information. This application displays a file's "properties" information. It also contains a really cool form resize routine

API Declarations


'================================================
'You will need the following controls in your form, one Common Dialog box (CommonDialog1),
'one Command Button (Command1) - set its caption property to "Get file properties", one
'Check Box (Check1) - set its caption property to "Show Msgbox" and place it next to the
'Command Button, one Text box (Text1) positioned below the Comand Button and chekbox,
'and finally one List box (List1) positioned below the textbox.
'
'To add the CommonDialog control, click on "Project" in the menu and select "Components..."
'from the drop down list. A Components window should be open in front of you, within the
'"control" tab find "Microsoft CommonDialog Control 6.0 (SP3)" in the list, select it and
'click on "OK". You should now see a new icon added to your components tab bar on the left.
'drag this new item onto your form. Now you will have a CommonDialog box at your disposal.
'You can place it anywhere on your form, because its invisible when you run your application.
'
'You will also have to create a class module to your project. Right click in the
'"Project - FileProperties" window in the upper right corner and select "Add" from the
'popup menu. Then select "Class module" within the sub menu. A new window should popup
'called "Add Class Module" accept the default selection by clicking "Open". You should
'now see a "Class Modules" folder added to your project with a "Class1.cls" in it. Copy
'and paste all the code marked "CLASS1 BEGIN" to "CLASS1 END" into it. It will be at the
'bottom of this source code.
'
'Same applies for the form, copy all the code marked "FORM1 BEGIN" to "FORM1 END" and
'paste it into the "Form1" module.
'
'That's it, have fun with it!

Rate File properties information. This application displays a file's properties information. It also c



'This application displays a file's "properties" information
'It also contains a really cool form resize routine written by
'someone else and slightly modified by me to give extra functionality.

'Follow these instruction to get up and runnning:
'================================================
'You will need the following controls in your form, one Common Dialog box (CommonDialog1),
'one Command Button (Command1) - set its caption property to "Get file properties", one
'Check Box (Check1) - set its caption property to "Show Msgbox" and place it next to the
'Command Button, one Text box (Text1) positioned below the Comand Button and chekbox,
'and finally one List box (List1) positioned below the textbox.
'
'To add the CommonDialog control, click on "Project" in the menu and select "Components..."
'from the drop down list. A Components window should be open in front of you, within the
'"control" tab find "Microsoft CommonDialog Control 6.0 (SP3)" in the list, select it and
'click on "OK". You should now see a new icon added to your components tab bar on the left.
'drag this new item onto your form. Now you will have a CommonDialog box at your disposal.
'You can place it anywhere on your form, because its invisible when you run your application.
'
'You will also have to create a class module to your project. Right click in the
'"Project - FileProperties" window in the upper right corner and select "Add" from the
'popup menu. Then select "Class module" within the sub menu. A new window should popup
'called "Add Class Module" accept the default selection by clicking "Open". You should
'now see a "Class Modules" folder added to your project with a "Class1.cls" in it. Copy
'and paste all the code marked "CLASS1 BEGIN" to "CLASS1 END" into it. It will be at the
'bottom of this source code.
'
'Same applies for the form, copy all the code marked "FORM1 BEGIN" to "FORM1 END" and
'paste it into the "Form1" module.
'
'That's it, have fun with it!


'FORM1 BEGIN ----------------------------------------------------------

'WinApi calls
Private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long

'Initializing an instance of the form resize class module.
Private ClassResize As New Class1

Private Sub ShowFileProperties(ByVal strFileName As String)

    Dim oFSO As Object, oF As Object
    Dim sInfo As String, lSizeof As Long
    Dim lResult As Long, iDelim As Integer, n As Integer, lHandle As Long
    
    Dim iCompName As Integer, iFileDesc As Integer, iFileVer As Integer, iIntlName As Integer
    Dim iLegalCopy As Integer, iOrgFileName As Integer, iProdName As Integer, iProdVer As Integer
    Dim iComments As Integer, iVarFileInfo As Integer
    
    List1.Clear
    lHandle = 0
      
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    If (oFSO.FileExists(strFileName)) Then
  
        Set oF = oFSO.GetFile(strFileName)
        List1.AddItem "DateCreated:      " & vbTab & oF.DateCreated
        List1.AddItem "Name:             " & vbTab & oF.Name
        List1.AddItem "DateLastAcc:      " & vbTab & oF.DateLastAccessed
        List1.AddItem "DateLastMod:      " & vbTab & oF.DateLastModified
        List1.AddItem "ParentFolder:     " & vbTab & oF.ParentFolder
        List1.AddItem "Path:             " & vbTab & oF.Path
        List1.AddItem "ShortName:        " & vbTab & oF.ShortName
        List1.AddItem "ShortPath:        " & vbTab & oF.ShortPath
        
        temp = oFSO.GetFileVersion(strFileName)
        If Len(temp) Then
            GetVersion = temp
        Else
            GetVersion = "No version information available."
        End If
        List1.AddItem "GetVersion:       " & vbTab & GetVersion
        
    End If
    
    List1.AddItem ""
    List1.AddItem ""
    
    'Getting the length of string to be retrieved.
    lSizeof = GetFileVersionInfoSize(strFileName, lHandle)

    If lSizeof > 0 Then
    
        'Creating a buffer filled with nothing in it, to be populated using the GetFileVersionInfo winapi call.
        sInfo = String$(lSizeof, 0)
        lResult = GetFileVersionInfo(ByVal strFileName, ByVal lHandle, ByVal lSizeof, ByVal sInfo)

        If lResult Then
        
            Dim iCounter As Integer, szChar As String
            
            'Removing most of the garbage characters from the returned string.
            For iCounter = 1 To Len(sInfo)
                szTest = Mid(sInfo, iCounter, 1)
                sziTest = Asc(Mid(sInfo, iCounter, 1))
                
                'Replacing any garbage characters with a blank space, but leaving the section terminating character "1" behind to key off of.
                If ((Asc(Mid(sInfo, iCounter, 1)) > 44) And (Asc(Mid(sInfo, iCounter, 1)) < 122)) Or (Asc(Mid(sInfo, iCounter, 1)) = 1) Then
                    szChar = szChar & Mid(sInfo, iCounter, 1)
                    iSpcCnt = 0
                Else
                    If ((iSpcCnt > 1) And (iSpcCnt Mod 2 = 0) And (Asc(Mid(sInfo, iCounter, 1)) = 0)) Then
                        szChar = szChar & " "
                        iSpcCnt = 0
                    End If
                    iSpcCnt = iSpcCnt + 1
                End If
            Next iCounter
            
            'Option to show the entire return string in a pop-up message box.
            If Check1.Value = 1 Then MsgBox szChar


            'Parsing out the values for each of the associated search string.
            
        'COMPANY NAME
            iStart = InStr(LCase(szChar), LCase("CompanyName"))
            If (iStart > 0) Then
                iStart = iStart + 13
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "CompanyName: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'FILE DESCRIPTION
            iStart = InStr(LCase(szChar), LCase("FileDescription"))
            If (iStart > 0) Then
                iStart = iStart + 17
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "FileDescription: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'FILE VERSION
            iStart = InStr(LCase(szChar), LCase("FileVersion"))
            If (iStart > 0) Then
                iStart = iStart + 13
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "FileVersion: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'INTERNAL NAME
            iStart = InStr(LCase(szChar), LCase("InternalName"))
            If (iStart > 0) Then
                iStart = iStart + 13
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "InternalName: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'LEGAL COPYRIGHT
            iStart = InStr(LCase(szChar), LCase("LegalCopyright"))
            If (iStart > 0) Then
                iStart = iStart + 15
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "LegalCopyright: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'ORIGINAL FILE NAME
            iStart = InStr(LCase(szChar), LCase("OriginalFileName"))
            If (iStart > 0) Then
                iStart = iStart + 17
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "OriginalFileName: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'PRODUCT NAME
            iStart = InStr(LCase(szChar), LCase("ProductName"))
            If (iStart > 0) Then
                iStart = iStart + 13
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "ProductName: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'PRODUCT VERSION
            iStart = InStr(LCase(szChar), LCase("ProductVersion"))
            If (iStart > 0) Then
                iStart = iStart + 15
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "ProductVersion: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'COMMENTS
            iStart = InStr(LCase(szChar), LCase("Comments"))
            If (iStart > 0) Then
                iStart = iStart + 9
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "Comments: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'STRING FILE INFORMATION
            iStart = InStr(LCase(szChar), LCase("StringFileInfo"))
            If (iStart > 0) Then
                iStart = iStart + 17
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "StringFileInfo: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        'LEGAL TRADEMARKS
            iStart = InStr(LCase(szChar), LCase("LegalTrademarks"))
            If (iStart > 0) Then
                iStart = iStart + 17
                iEnd = InStr(iStart, LCase(szChar), Chr$(1)) - 2
                List1.AddItem "LegalTrademarks: " & vbTab & Mid$(szChar, iStart, iEnd - iStart)
            End If
            
        End If
    End If

End Sub

Private Sub Command1_Click()

    'Providing a search dialog box for the user to select the
    'file that they wish to see the properties of.
    
    CommonDialog1.ShowOpen
    Text1.Text = CommonDialog1.FileName
    ShowFileProperties Text1.Text
    
End Sub

Private Sub Form_Load()

    'This specifies which elements within your form are allowed to
    'move/resize in relation to the form/window being resized by the
    'user.

    With ClassResize
    
        'Providing the dimensions of the form for scaling reference
        'by the form resize class module.
        .hParam = Form1.Height
        .wParam = Form1.Width
        .hScaleParam = Form1.ScaleHeight
        .wScaleParam = Form1.ScaleWidth
        
        'Instructing which form controls are movable/resizable with
        'the form.
        .Map Command1, RS_CenterOnWidth
        .Map Check1, RS_LeftOnly
        .Map Text1, RS_WidthOnly
        .Map Frame1, RS_Height_Width
        .Map List1, RS_Height_Width
        
    End With
    
End Sub

Private Sub Form_Resize()

    'This calls the form resize class module to move all the items
    'specified in Form_Load() in relation to the forms current size
    'in real time.
    
    ClassResize.rSize Form1
    
End Sub

'FORM1 END ----------------------------------------------------------

'CLASS1 BEGIN ----------------------------------------------------------

'Key codes:
'1  ->  top only
'2  ->  left only
'3  ->  top and left
'4  ->  height only
'5  ->  width only
'6  ->  height and width
'7  ->  center on width
'8  ->  center on height
'9  ->  center on width and height
'10 ->  Move top position and center it on width
'11 ->  Move left position and center on height
'-----------------------
Option Explicit

Enum eParams
    RS_TopOnly = 1
    RS_LeftOnly = 2
    RS_Top_Left = 3
    RS_HeightOnly = 4
    RS_WidthOnly = 5
    RS_Height_Width = 6
    RS_CenterOnWidth = 7
    RS_CenterOnHeight = 8
    RS_CenterOnHeightWidth = 9
    RS_Top_CenterOnWidth = 10
    RS_Left_CenterOnHeight = 11
End Enum

Private Type cInfo
    cControl    As Control
    cHeight     As Integer
    cWidth      As Integer
    cTop        As Integer
    cLeft       As Integer
    cInfo       As Integer
    cCntrWidth  As Integer
    cCntrHeight As Integer
End Type

Private cArray() As cInfo
Private Count As Integer

Private FormHeight As Integer
Private FormWidth As Integer
Private FormScaleHeight As Integer
Private FormScaleWidth As Integer

'/***************************************************************************************'   Property:       hParam(ByVal fh As Integer)
'   Description:    None.
'   Parameters:     None.
'   Return Value:   None.
'\***************************************************************************************/
Public Property Let hParam(ByVal fh As Integer)
    FormHeight = fh
End Property

'/***************************************************************************************'   Property:       wParam(ByVal fw As Integer)
'   Description:    None.
'   Parameters:     None.
'   Return Value:   None.
'\***************************************************************************************/
Public Property Let wParam(ByVal fw As Integer)
    FormWidth = fw
End Property

'/***************************************************************************************'   Property:       hScaleParam(ByVal fsh As Integer)
'   Description:    None.
'   Parameters:     None.
'   Return Value:   None.
'\***************************************************************************************/
Public Property Let hScaleParam(ByVal fsh As Integer)
    FormScaleHeight = fsh
End Property

'/***************************************************************************************'   Property:       wScaleParam(ByVal fsw As Integer)
'   Description:    None.
'   Parameters:     None.
'   Return Value:   None.
'\***************************************************************************************/
Public Property Let wScaleParam(ByVal fsw As Integer)
    FormScaleWidth = fsw
End Property

'/***************************************************************************************'   Function:       Map(rCont As Control, SizeInfo As eParams)
'   Description:    None.
'   Parameters:     None.
'   Return Value:   None.
'\***************************************************************************************/
Public Sub Map(rCont As Control, SizeInfo As eParams)
    Count = Count + 1
    ReDim Preserve cArray(Count)
    Set cArray(Count).cControl = rCont
    cArray(Count).cInfo = SizeInfo

    
    Select Case SizeInfo
        Case 1:
            cArray(Count).cTop = FormHeight - rCont.Top
        Case 2:
            cArray(Count).cLeft = FormWidth - rCont.Left
        Case 3:
            cArray(Count).cTop = FormHeight - rCont.Top
            cArray(Count).cLeft = FormWidth - rCont.Left
        Case 4:
            cArray(Count).cHeight = FormHeight - rCont.Height
        Case 5:
            cArray(Count).cWidth = FormWidth - rCont.Width
        Case 6:
            cArray(Count).cHeight = FormHeight - rCont.Height
            cArray(Count).cWidth = FormWidth - rCont.Width
        Case 7:
            cArray(Count).cCntrWidth = FormWidth - (((FormWidth - rCont.Width) / 2) + rCont.Left)
        Case 8:
            cArray(Count).cCntrHeight = FormHeight - (((FormScaleWidth - rCont.Height) / 2) + rCont.Top)
        Case 9:
            cArray(Count).cCntrWidth = FormWidth - (((FormWidth - rCont.Width) / 2) + rCont.Left)
            cArray(Count).cCntrHeight = FormHeight - (((FormScaleWidth - rCont.Height) / 2) + rCont.Top)
        Case 10:
            cArray(Count).cTop = FormHeight - rCont.Top
            cArray(Count).cCntrWidth = FormWidth - (((FormWidth - rCont.Width) / 2) + rCont.Left)
        Case 11:
            cArray(Count).cLeft = FormWidth - rCont.Left
            cArray(Count).cCntrHeight = FormHeight - (((FormScaleWidth - rCont.Height) / 2) + rCont.Top)
        Case Else:
            Exit Sub
    End Select
    
End Sub

'/***************************************************************************************'   Function:       rSize(cForm As Form)
'   Description:    None.
'   Parameters:     None.
'   Return Value:   None.
'\***************************************************************************************/
Public Sub rSize(cForm As Form)
    
    On Error Resume Next
    Dim i As Integer, a As Integer, b As Integer
    For i = 1 To Count
        Select Case cArray(i).cInfo
            Case 1:
                cArray(i).cControl.Top = cForm.Height - cArray(i).cTop
            Case 2:
                cArray(i).cControl.Left = cForm.Width - cArray(i).cLeft
            Case 3:
                cArray(i).cControl.Top = cForm.Height - cArray(i).cTop
                cArray(i).cControl.Left = cForm.Width - cArray(i).cLeft
            Case 4:
                b = cForm.Height - cArray(i).cHeight
                If b < 0 Then b = 0
                cArray(i).cControl.Height = b
            Case 5:
                a = cForm.Width - cArray(i).cWidth
                If a < 0 Then a = 0
                cArray(i).cControl.Width = a
            Case 6:
                a = cForm.Width - cArray(i).cWidth
                b = cForm.Height - cArray(i).cHeight
                If a < 0 Then a = 0
                If b < 0 Then b = 0
                cArray(i).cControl.Height = b
                cArray(i).cControl.Width = a
            Case 7:
                cArray(i).cControl.Left = (cForm.Width - cArray(i).cCntrWidth) / 2
            Case 8:
                cArray(i).cControl.Top = (cForm.Height - cArray(i).cCntrHeight) / 2
            Case 9:
                cArray(i).cControl.Left = (cForm.Width - cArray(i).cCntrWidth) / 2
                cArray(i).cControl.Top = (cForm.Height - cArray(i).cCntrHeight) / 2
            Case 10:
                cArray(i).cControl.Top = cForm.Height - cArray(i).cTop
                cArray(i).cControl.Left = (cForm.Width - cArray(i).cCntrWidth) / 2
            Case 11:
                cArray(i).cControl.Left = cForm.Width - cArray(i).cLeft
                cArray(i).cControl.Top = (cForm.Height - cArray(i).cCntrHeight) / 2
        End Select
    Next
    Exit Sub
End Sub

'CLASS1 END ----------------------------------------------------------



Download this snippet    Add to My Saved Code

File properties information. This application displays a file's properties information. It also c Comments

No comments have been posted about File properties information. This application displays a file's properties information. It also c. Why not be the first to post a comment about File properties information. This application displays a file's properties information. It also c.

Post your comment

Subject:
Message:
0/1000 characters