home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / filever / filever.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-07  |  16.0 KB  |  479 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "GetFileVersionInfo 32"
  5.    ClientHeight    =   4965
  6.    ClientLeft      =   1140
  7.    ClientTop       =   1485
  8.    ClientWidth     =   5820
  9.    Height          =   5370
  10.    Icon            =   "filever.frx":0000
  11.    KeyPreview      =   -1  'True
  12.    Left            =   1080
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   4965
  17.    ScaleWidth      =   5820
  18.    ShowInTaskbar   =   0   'False
  19.    Top             =   1140
  20.    Width           =   5940
  21.    Begin VB.PictureBox Picture1 
  22.       BackColor       =   &H00FFFFFF&
  23.       Height          =   2415
  24.       Left            =   120
  25.       ScaleHeight     =   2355
  26.       ScaleWidth      =   5475
  27.       TabIndex        =   7
  28.       TabStop         =   0   'False
  29.       Top             =   2100
  30.       Width           =   5535
  31.       Begin VB.Label lblValue 
  32.          Appearance      =   0  'Flat
  33.          BackColor       =   &H80000005&
  34.          ForeColor       =   &H000000C0&
  35.          Height          =   195
  36.          Index           =   0
  37.          Left            =   1680
  38.          TabIndex        =   27
  39.          Top             =   0
  40.          Width           =   3750
  41.       End
  42.       Begin VB.Label Label1 
  43.          Appearance      =   0  'Flat
  44.          BackColor       =   &H80000005&
  45.          Caption         =   "File Name"
  46.          ForeColor       =   &H80000008&
  47.          Height          =   195
  48.          Index           =   9
  49.          Left            =   0
  50.          TabIndex        =   26
  51.          Top             =   0
  52.          Width           =   1515
  53.       End
  54.       Begin VB.Label lblValue 
  55.          Appearance      =   0  'Flat
  56.          BackColor       =   &H80000005&
  57.          ForeColor       =   &H00800000&
  58.          Height          =   195
  59.          Index           =   1
  60.          Left            =   1680
  61.          TabIndex        =   25
  62.          Top             =   240
  63.          Width           =   3750
  64.       End
  65.       Begin VB.Label Label1 
  66.          Appearance      =   0  'Flat
  67.          BackColor       =   &H80000005&
  68.          Caption         =   "File Date/Size"
  69.          ForeColor       =   &H80000008&
  70.          Height          =   195
  71.          Index           =   0
  72.          Left            =   0
  73.          TabIndex        =   24
  74.          Top             =   240
  75.          Width           =   1515
  76.       End
  77.       Begin VB.Label Label1 
  78.          Appearance      =   0  'Flat
  79.          BackColor       =   &H80000005&
  80.          Caption         =   "Company Name"
  81.          ForeColor       =   &H80000008&
  82.          Height          =   195
  83.          Index           =   1
  84.          Left            =   0
  85.          TabIndex        =   23
  86.          Top             =   480
  87.          Width           =   1515
  88.       End
  89.       Begin VB.Label Label1 
  90.          Appearance      =   0  'Flat
  91.          BackColor       =   &H80000005&
  92.          Caption         =   "File Description"
  93.          ForeColor       =   &H80000008&
  94.          Height          =   195
  95.          Index           =   2
  96.          Left            =   0
  97.          TabIndex        =   22
  98.          Top             =   720
  99.          Width           =   1515
  100.       End
  101.       Begin VB.Label Label1 
  102.          Appearance      =   0  'Flat
  103.          BackColor       =   &H80000005&
  104.          Caption         =   "File Version"
  105.          ForeColor       =   &H80000008&
  106.          Height          =   195
  107.          Index           =   3
  108.          Left            =   0
  109.          TabIndex        =   21
  110.          Top             =   960
  111.          Width           =   1515
  112.       End
  113.       Begin VB.Label Label1 
  114.          Appearance      =   0  'Flat
  115.          BackColor       =   &H80000005&
  116.          Caption         =   "Internal Name"
  117.          ForeColor       =   &H80000008&
  118.          Height          =   195
  119.          Index           =   4
  120.          Left            =   0
  121.          TabIndex        =   20
  122.          Top             =   1200
  123.          Width           =   1515
  124.       End
  125.       Begin VB.Label Label1 
  126.          Appearance      =   0  'Flat
  127.          BackColor       =   &H80000005&
  128.          Caption         =   "Legal Copyright"
  129.          ForeColor       =   &H80000008&
  130.          Height          =   195
  131.          Index           =   5
  132.          Left            =   0
  133.          TabIndex        =   19
  134.          Top             =   1440
  135.          Width           =   1515
  136.       End
  137.       Begin VB.Label Label1 
  138.          Appearance      =   0  'Flat
  139.          BackColor       =   &H80000005&
  140.          Caption         =   "Original File Name"
  141.          ForeColor       =   &H80000008&
  142.          Height          =   195
  143.          Index           =   6
  144.          Left            =   0
  145.          TabIndex        =   18
  146.          Top             =   1680
  147.          Width           =   1515
  148.       End
  149.       Begin VB.Label Label1 
  150.          Appearance      =   0  'Flat
  151.          BackColor       =   &H80000005&
  152.          Caption         =   "Product Name"
  153.          ForeColor       =   &H80000008&
  154.          Height          =   195
  155.          Index           =   7
  156.          Left            =   0
  157.          TabIndex        =   17
  158.          Top             =   1920
  159.          Width           =   1515
  160.       End
  161.       Begin VB.Label Label1 
  162.          Appearance      =   0  'Flat
  163.          BackColor       =   &H80000005&
  164.          Caption         =   "Product Version"
  165.          ForeColor       =   &H80000008&
  166.          Height          =   195
  167.          Index           =   8
  168.          Left            =   0
  169.          TabIndex        =   16
  170.          Top             =   2160
  171.          Width           =   1515
  172.       End
  173.       Begin VB.Label lblValue 
  174.          Appearance      =   0  'Flat
  175.          BackColor       =   &H80000005&
  176.          ForeColor       =   &H80000008&
  177.          Height          =   195
  178.          Index           =   2
  179.          Left            =   1680
  180.          TabIndex        =   15
  181.          Top             =   480
  182.          Width           =   3750
  183.       End
  184.       Begin VB.Label lblValue 
  185.          Appearance      =   0  'Flat
  186.          BackColor       =   &H80000005&
  187.          ForeColor       =   &H80000008&
  188.          Height          =   195
  189.          Index           =   3
  190.          Left            =   1680
  191.          TabIndex        =   14
  192.          Top             =   720
  193.          Width           =   3750
  194.       End
  195.       Begin VB.Label lblValue 
  196.          Appearance      =   0  'Flat
  197.          BackColor       =   &H80000005&
  198.          ForeColor       =   &H80000008&
  199.          Height          =   195
  200.          Index           =   4
  201.          Left            =   1680
  202.          TabIndex        =   13
  203.          Top             =   960
  204.          Width           =   3750
  205.       End
  206.       Begin VB.Label lblValue 
  207.          Appearance      =   0  'Flat
  208.          BackColor       =   &H80000005&
  209.          ForeColor       =   &H80000008&
  210.          Height          =   195
  211.          Index           =   5
  212.          Left            =   1680
  213.          TabIndex        =   12
  214.          Top             =   1200
  215.          Width           =   3750
  216.       End
  217.       Begin VB.Label lblValue 
  218.          Appearance      =   0  'Flat
  219.          BackColor       =   &H80000005&
  220.          ForeColor       =   &H80000008&
  221.          Height          =   195
  222.          Index           =   6
  223.          Left            =   1680
  224.          TabIndex        =   11
  225.          Top             =   1440
  226.          Width           =   3750
  227.       End
  228.       Begin VB.Label lblValue 
  229.          Appearance      =   0  'Flat
  230.          BackColor       =   &H80000005&
  231.          ForeColor       =   &H80000008&
  232.          Height          =   195
  233.          Index           =   7
  234.          Left            =   1680
  235.          TabIndex        =   10
  236.          Top             =   1680
  237.          Width           =   3750
  238.       End
  239.       Begin VB.Label lblValue 
  240.          Appearance      =   0  'Flat
  241.          BackColor       =   &H80000005&
  242.          ForeColor       =   &H80000008&
  243.          Height          =   195
  244.          Index           =   8
  245.          Left            =   1680
  246.          TabIndex        =   9
  247.          Top             =   1920
  248.          Width           =   3750
  249.       End
  250.       Begin VB.Label lblValue 
  251.          Appearance      =   0  'Flat
  252.          BackColor       =   &H80000005&
  253.          ForeColor       =   &H80000008&
  254.          Height          =   195
  255.          Index           =   9
  256.          Left            =   1680
  257.          TabIndex        =   8
  258.          Top             =   2160
  259.          Width           =   3750
  260.       End
  261.    End
  262.    Begin VB.FileListBox File1 
  263.       Height          =   1425
  264.       Left            =   120
  265.       TabIndex        =   2
  266.       Top             =   600
  267.       Width           =   2895
  268.    End
  269.    Begin VB.DirListBox Dir1 
  270.       Height          =   1155
  271.       Left            =   3120
  272.       TabIndex        =   6
  273.       Top             =   860
  274.       Width           =   2535
  275.    End
  276.    Begin VB.DriveListBox Drive1 
  277.       Height          =   315
  278.       Left            =   3120
  279.       TabIndex        =   4
  280.       Top             =   240
  281.       Width           =   2535
  282.    End
  283.    Begin VB.TextBox txtFileName 
  284.       Height          =   315
  285.       Left            =   120
  286.       TabIndex        =   1
  287.       Top             =   240
  288.       Width           =   2895
  289.    End
  290.    Begin VB.Label Label3 
  291.       BackStyle       =   0  'Transparent
  292.       Caption         =   "MMC Software              info@mmcsoftware.com or CompuServe: 72500,1406"
  293.       ForeColor       =   &H00000000&
  294.       Height          =   255
  295.       Index           =   1
  296.       Left            =   120
  297.       TabIndex        =   29
  298.       Top             =   4740
  299.       Width           =   5535
  300.    End
  301.    Begin VB.Label Label3 
  302.       BackStyle       =   0  'Transparent
  303.       Caption         =   "Copyright 
  304.  1995, David Warren"
  305.       ForeColor       =   &H00000000&
  306.       Height          =   255
  307.       Index           =   0
  308.       Left            =   120
  309.       TabIndex        =   28
  310.       Top             =   4560
  311.       Width           =   2475
  312.    End
  313.    Begin VB.Label Label2 
  314.       Caption         =   "Di&rectory"
  315.       Height          =   195
  316.       Index           =   2
  317.       Left            =   3120
  318.       TabIndex        =   5
  319.       Top             =   600
  320.       Width           =   1275
  321.    End
  322.    Begin VB.Label Label2 
  323.       Caption         =   "&Drive"
  324.       Height          =   195
  325.       Index           =   1
  326.       Left            =   3120
  327.       TabIndex        =   3
  328.       Top             =   0
  329.       Width           =   1275
  330.    End
  331.    Begin VB.Label Label2 
  332.       Caption         =   "&File Name"
  333.       Height          =   195
  334.       Index           =   0
  335.       Left            =   120
  336.       TabIndex        =   0
  337.       Top             =   0
  338.       Width           =   1275
  339.    End
  340. Attribute VB_Name = "Form1"
  341. Attribute VB_Creatable = False
  342. Attribute VB_Exposed = False
  343. Private Sub GetFileVersionData()
  344.     On Error GoTo GetFileVersionData_Error
  345.     Dim sFileName As String, sInfo As String, sMsg As String
  346.     Dim lResult As Long, iDelim As Integer, n As Integer, lHandle As Long
  347.     If txtFileName.Text <> "" Then
  348.         For n = 2 To 9
  349.             lblValue(n).Caption = ""
  350.         Next n
  351.         sFileName = txtFileName.Text
  352.         lblValue(0).Caption = UCase$(sFileName)
  353.         lblValue(1).Caption = Format$(FileDateTime(sFileName), "MM/DD/YY HH:MM:SS") & Space(10) & Format$(FileLen(sFileName), "###,###,###") & " bytes"
  354.         
  355.         lHandle = 0
  356.         'how big is the Version Info block?
  357.         lSizeof = GetFileVersionInfoSize(sFileName, lHandle)
  358.         If lSizeof > 0 Then
  359.             
  360.             sInfo = String$(lSizeof, 0)
  361.             lResult = GetFileVersionInfo(ByVal sFileName, 0&, ByVal lSizeof, ByVal sInfo)
  362.             If lResult Then
  363.             
  364.                                 
  365.                 'now parse the returned string:
  366.                 
  367.                 ' NOTE: I found the formal method using VerGetValue()
  368.                 ' to be somewhat unreliable, sometimes failing to
  369.                 ' return the correct information.  Instead, simply
  370.                 ' parse the string as follows:
  371.                 iDelim = InStr(sInfo, "CompanyName")
  372.                 If iDelim > 0 Then
  373.                     iDelim = iDelim + 12
  374.                     lblValue(2).Caption = Mid$(sInfo, iDelim)
  375.                 End If
  376.                 
  377.                 iDelim = InStr(sInfo, "FileDescription")
  378.                 If iDelim > 0 Then
  379.                     iDelim = iDelim + 16
  380.                     lblValue(3).Caption = Mid$(sInfo, iDelim)
  381.                 End If
  382.                 
  383.                 iDelim = InStr(sInfo, "FileVersion")
  384.                 If iDelim > 0 Then
  385.                     iDelim = iDelim + 12
  386.                     lblValue(4).Caption = Mid$(sInfo, iDelim)
  387.                 End If
  388.                 
  389.                 iDelim = InStr(sInfo, "InternalName")
  390.                 If iDelim > 0 Then
  391.                     iDelim = iDelim + 16
  392.                     lblValue(5).Caption = Mid$(sInfo, iDelim)
  393.                 End If
  394.                 
  395.                 iDelim = InStr(sInfo, "LegalCopyright")
  396.                 If iDelim > 0 Then
  397.                     iDelim = iDelim + 16
  398.                     lblValue(6).Caption = Mid$(sInfo, iDelim)
  399.                 End If
  400.                 
  401.                 iDelim = InStr(sInfo, "OriginalFilename")
  402.                 If iDelim > 0 Then
  403.                     iDelim = iDelim + 20
  404.                     lblValue(7).Caption = Mid$(sInfo, iDelim)
  405.                 End If
  406.                 iDelim = InStr(sInfo, "ProductName")
  407.                 If iDelim > 0 Then
  408.                     iDelim = iDelim + 12
  409.                     lblValue(8).Caption = Mid$(sInfo, iDelim)
  410.                 End If
  411.                 iDelim = InStr(sInfo, "ProductVersion")
  412.                 If iDelim > 0 Then
  413.                     iDelim = iDelim + 16
  414.                     lblValue(9).Caption = Mid$(sInfo, iDelim)
  415.                 End If
  416.             
  417.             Else
  418.                 GoTo invalid_file_info_error
  419.             End If
  420.         Else
  421.             GoTo invalid_file_info_error
  422.             
  423.         End If
  424.     End If
  425. GetFileVersionData_Exit:
  426.     Exit Sub
  427. GetFileVersionData_Error:
  428.     MsgBox "Error " & Format$(Err) & ": " & Error$ & " in GetFileVersionData"
  429.     Resume GetFileVersionData_Exit
  430. invalid_file_info_error:
  431.     lblValue(3).Caption = "Not a program file, or does not contain version info."
  432.     GoTo GetFileVersionData_Exit
  433. End Sub
  434. Private Sub cmdFileBrowse_Click()
  435. End Sub
  436. Private Sub Dir1_Change()
  437.     File1.Path = Dir1.Path
  438. End Sub
  439. Private Sub Drive1_Change()
  440.     Dir1.Path = Drive1.Drive
  441. End Sub
  442. Private Sub File1_Click()
  443.     txtFileName.Text = File1.Path & "\" & File1.filename
  444.     GetFileVersionData
  445. End Sub
  446. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  447.     On Error GoTo Form_KeyDown_Error
  448.     If KeyCode = vbKeyReturn Then
  449.         If txtFileName <> "" Then
  450.             If InStr(txtFileName.Text, "*") Then
  451.                 File1.Pattern = txtFileName.Text
  452.             Else
  453.                 GetFileVersionData
  454.             End If
  455.             KeyCode = 0
  456.         End If
  457.     End If
  458. Form_KeyDown_Exit:
  459.     Exit Sub
  460. Form_KeyDown_Error:
  461.     MsgBox "Error " & Format$(Err) & ": " & Error$ & " in Form_KeyDown"
  462.     Resume Form_KeyDown_Exit
  463. End Sub
  464. Private Sub txtFileName_GotFocus()
  465.     On Error GoTo txtFileName_GotFocus_Error
  466.     If txtFileName.Text <> "" Then
  467.         txtFileName.SelStart = 0
  468.         txtFileName.SelLength = Len(txtFileName.Text)
  469.     End If
  470. txtFileName_GotFocus_Exit:
  471.     Exit Sub
  472. txtFileName_GotFocus_Error:
  473.     MsgBox "Error " & Format$(Err) & ": " & Error$ & " in txtFileName_GotFocus"
  474.     Resume txtFileName_GotFocus_Exit
  475. End Sub
  476. Private Sub txtFileName_KeyPress(KeyAscii As Integer)
  477.     If KeyAscii = 13 Then KeyAscii = 0
  478. End Sub
  479.