home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch13 / frmview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  10.8 KB  |  303 lines

  1. VERSION 4.00
  2. Begin VB.Form frmView 
  3.    Caption         =   "File Information - "
  4.    ClientHeight    =   4755
  5.    ClientLeft      =   1560
  6.    ClientTop       =   1755
  7.    ClientWidth     =   6075
  8.    Height          =   5160
  9.    Left            =   1500
  10.    LinkTopic       =   "Form2"
  11.    ScaleHeight     =   4755
  12.    ScaleWidth      =   6075
  13.    Top             =   1410
  14.    Width           =   6195
  15.    Begin VB.Frame Frame2 
  16.       Caption         =   "Times:"
  17.       Height          =   1035
  18.       Left            =   0
  19.       TabIndex        =   13
  20.       Top             =   1020
  21.       Width           =   4155
  22.       Begin VB.Label lblModified 
  23.          Height          =   195
  24.          Left            =   1200
  25.          TabIndex        =   19
  26.          Top             =   720
  27.          Width           =   2895
  28.       End
  29.       Begin VB.Label lblAccessed 
  30.          Height          =   195
  31.          Left            =   1200
  32.          TabIndex        =   18
  33.          Top             =   480
  34.          Width           =   2895
  35.       End
  36.       Begin VB.Label lblCreated 
  37.          Height          =   195
  38.          Left            =   1200
  39.          TabIndex        =   17
  40.          Top             =   180
  41.          Width           =   2895
  42.       End
  43.       Begin VB.Label Label6 
  44.          Caption         =   "Modified:"
  45.          Height          =   195
  46.          Left            =   120
  47.          TabIndex        =   16
  48.          Top             =   780
  49.          Width           =   735
  50.       End
  51.       Begin VB.Label Label5 
  52.          Caption         =   "Accessed:"
  53.          Height          =   195
  54.          Left            =   120
  55.          TabIndex        =   15
  56.          Top             =   480
  57.          Width           =   855
  58.       End
  59.       Begin VB.Label Label4 
  60.          Caption         =   "Created:"
  61.          Height          =   195
  62.          Left            =   120
  63.          TabIndex        =   14
  64.          Top             =   180
  65.          Width           =   675
  66.       End
  67.    End
  68.    Begin VB.CommandButton cmdClose 
  69.       Cancel          =   -1  'True
  70.       Caption         =   "&Close"
  71.       Height          =   495
  72.       Left            =   4800
  73.       TabIndex        =   10
  74.       Top             =   180
  75.       Width           =   1215
  76.    End
  77.    Begin VB.Frame Frame1 
  78.       Caption         =   "Attributes:"
  79.       Height          =   1035
  80.       Left            =   60
  81.       TabIndex        =   4
  82.       Top             =   2340
  83.       Width           =   2775
  84.       Begin VB.CheckBox chkCompressed 
  85.          Caption         =   "Compressed"
  86.          Height          =   195
  87.          Left            =   1440
  88.          TabIndex        =   9
  89.          Top             =   420
  90.          Width           =   1215
  91.       End
  92.       Begin VB.CheckBox chkArchive 
  93.          Caption         =   "Archive"
  94.          Height          =   195
  95.          Left            =   1440
  96.          TabIndex        =   8
  97.          Top             =   180
  98.          Width           =   1215
  99.       End
  100.       Begin VB.CheckBox chkSystem 
  101.          Caption         =   "System"
  102.          Height          =   195
  103.          Left            =   120
  104.          TabIndex        =   7
  105.          Top             =   660
  106.          Width           =   1035
  107.       End
  108.       Begin VB.CheckBox chkHidden 
  109.          Caption         =   "Hidden"
  110.          Height          =   195
  111.          Left            =   120
  112.          TabIndex        =   6
  113.          Top             =   420
  114.          Width           =   1035
  115.       End
  116.       Begin VB.CheckBox chkReadOnly 
  117.          Caption         =   "Read-Only"
  118.          Height          =   195
  119.          Left            =   120
  120.          TabIndex        =   5
  121.          Top             =   180
  122.          Width           =   1215
  123.       End
  124.    End
  125.    Begin VB.Label lblFileSize 
  126.       Height          =   255
  127.       Left            =   960
  128.       TabIndex        =   12
  129.       Top             =   720
  130.       Width           =   3135
  131.    End
  132.    Begin VB.Label Label3 
  133.       Caption         =   "File Size:"
  134.       Height          =   195
  135.       Left            =   60
  136.       TabIndex        =   11
  137.       Top             =   720
  138.       Width           =   855
  139.    End
  140.    Begin VB.Label lblType 
  141.       Height          =   195
  142.       Left            =   1020
  143.       TabIndex        =   3
  144.       Top             =   480
  145.       Width           =   3015
  146.    End
  147.    Begin VB.Label Label2 
  148.       Caption         =   "File Type:"
  149.       Height          =   195
  150.       Left            =   60
  151.       TabIndex        =   2
  152.       Top             =   480
  153.       Width           =   855
  154.    End
  155.    Begin VB.Label lblFileName 
  156.       Caption         =   "C:\AUTOEXEC.BAT"
  157.       Height          =   195
  158.       Left            =   1020
  159.       TabIndex        =   1
  160.       Top             =   60
  161.       Width           =   3495
  162.    End
  163.    Begin VB.Label Label1 
  164.       Caption         =   "File Name: "
  165.       Height          =   195
  166.       Left            =   60
  167.       TabIndex        =   0
  168.       Top             =   60
  169.       Width           =   855
  170.    End
  171. Attribute VB_Name = "frmView"
  172. Attribute VB_Creatable = False
  173. Attribute VB_Exposed = False
  174. Option Explicit
  175. ' Copyright 
  176.  1997 by Desaware Inc. All Rights Reserved
  177. Dim hFile&, TaskID&
  178. '**********************************
  179. '**  Function Declarations:
  180. #If Win32 Then
  181. Private Declare Function GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" (ByVal Locale As Long, ByVal dwFlags As Long, lpTime As SYSTEMTIME, ByVal lpFormat As Long, ByVal lpTimeStr As String, ByVal cchTime As Long)
  182. Private Declare Function GetDateFormat& Lib "kernel32" Alias "GetDateFormatA" (ByVal Locale As Long, ByVal dwFlags As Long, lpTime As SYSTEMTIME, ByVal lpFormat As Long, ByVal lpTimeStr As String, ByVal cchTime As Long)
  183. Private Declare Function FileTimeToSystemTime& Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME)
  184. Private Declare Function CreateFile& Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long)
  185. Private Declare Function GetFileInformationByHandle& Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION)
  186. Private Declare Function CloseHandle& Lib "kernel32" (ByVal hObject As Long)
  187. Private Declare Function GetBinaryType& Lib "kernel32" (ByVal szFileName As String, fType As Long)
  188. Private Declare Function GetWindowsDirectory& Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal myString As String, ByVal nCount As Long)
  189. #End If 'WIN32
  190. '**********************************
  191. '**  Type Definitions:
  192. #If Win32 Then
  193. Private Type FILETIME
  194.         dwLowDateTime As Long
  195.         dwHighDateTime As Long
  196. End Type
  197. Private Type SYSTEMTIME
  198.         wYear As Integer
  199.         wMonth As Integer
  200.         wDayOfWeek As Integer
  201.         wDay As Integer
  202.         wHour As Integer
  203.         wMinute As Integer
  204.         wSecond As Integer
  205.         wMilliseconds As Integer
  206. End Type
  207. Private Type BY_HANDLE_FILE_INFORMATION
  208.         dwFileAttributes As Long
  209.         ftCreationTime As FILETIME
  210.         ftLastAccessTime As FILETIME
  211.         ftLastWriteTime As FILETIME
  212.         dwVolumeSerialNumber As Long
  213.         nFileSizeHigh As Long
  214.         nFileSizeLow As Long
  215.         nNumberOfLinks As Long
  216.         nFileIndexHigh As Long
  217.         nFileIndexLow As Long
  218. End Type
  219. #End If 'WIN32 Types
  220. '**********************************
  221. '**  Constant Definitions:
  222. #If Win32 Then
  223. Private Const SCS_32BIT_BINARY& = 0
  224. Private Const SCS_DOS_BINARY& = 1
  225. Private Const SCS_OS216_BINARY& = 5
  226. Private Const SCS_PIF_BINARY& = 3
  227. Private Const SCS_POSIX_BINARY& = 4
  228. Private Const SCS_WOW_BINARY& = 2
  229. Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
  230. Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
  231. Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
  232. Private Const FILE_ATTRIBUTE_HIDDEN = &H2
  233. Private Const FILE_ATTRIBUTE_NORMAL = &H80
  234. Private Const FILE_ATTRIBUTE_READONLY = &H1
  235. Private Const FILE_ATTRIBUTE_SYSTEM = &H4
  236. Private Const FILE_ATTRIBUTE_TEMPORARY = &H100
  237. Private Const GENERIC_ALL = &H10000000
  238. Private Const GENERIC_EXECUTE = &H20000000
  239. Private Const GENERIC_READ = &H80000000
  240. Private Const GENERIC_WRITE = &H40000000
  241. Private Const OPEN_EXISTING = 3
  242. #End If 'WIN32
  243. Public Sub Initialize(fileName$)
  244.     Dim dl&, myTime As SYSTEMTIME
  245.     Dim s$, fType&
  246.     Dim myFileInfo As BY_HANDLE_FILE_INFORMATION
  247.     Me.Caption = Me.Caption & fileName
  248.     lblFileName = fileName$
  249.     hFile& = CreateFile&(fileName$, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
  250.     dl& = GetBinaryType&(fileName$, fType&)
  251.     If fType& And SCS_32BIT_BINARY Then
  252.         lblType = "Win32 Application"
  253.     ElseIf fType& And SCS_DOS_BINARY Then
  254.         lblType = "DOS Application"
  255.     ElseIf fType& And SCS_OS216_BINARY Then
  256.         lblType = "OS/2 16-Bit Application"
  257.     ElseIf fType& And SCS_PIF_BINARY Then
  258.         lblType = "DOS PIF Application"
  259.     ElseIf fType& And SCS_WOW_BINARY Then
  260.         lblType = "Win16 Application"
  261.     Else
  262.         lblType = "Document"
  263.     End If
  264.     dl& = GetFileInformationByHandle&(hFile&, myFileInfo)
  265.     With myFileInfo
  266.         If .dwFileAttributes And FILE_ATTRIBUTE_ARCHIVE Then chkArchive = 1
  267.         If .dwFileAttributes And FILE_ATTRIBUTE_COMPRESSED Then chkCompressed = 1
  268.         If .dwFileAttributes And FILE_ATTRIBUTE_HIDDEN Then chkHidden = 1
  269.         If .dwFileAttributes And FILE_ATTRIBUTE_READONLY Then chkReadOnly = 1
  270.         If .dwFileAttributes And FILE_ATTRIBUTE_SYSTEM Then chkSystem = 1
  271.         
  272.         dl& = FileTimeToSystemTime(.ftCreationTime, myTime)
  273.         s$ = String(255, 0)
  274.         dl& = GetTimeFormat&(&H800, 0, myTime, 0, s$, 254)
  275.         lblCreated = Left(s$, dl&)
  276.         s$ = String(255, 0)
  277.         dl& = GetDateFormat&(&H800, 0, myTime, 0, s$, 254)
  278.         lblCreated = Left(s$, dl& - 1) & " " & lblCreated
  279.         
  280.         dl& = FileTimeToSystemTime(.ftLastAccessTime, myTime)
  281.         s$ = String(255, 0)
  282.         dl& = GetTimeFormat&(&H800, 0, myTime, 0, s$, 254)
  283.         lblAccessed = Left$(s$, dl&)
  284.         s$ = String(255, 0)
  285.         dl& = GetDateFormat&(&H800, 0, myTime, 0, s$, 254)
  286.         lblAccessed = Left(s$, dl& - 1) & " " & lblAccessed
  287.         
  288.         dl& = FileTimeToSystemTime(.ftLastWriteTime, myTime)
  289.         s$ = String(255, 0)
  290.         dl& = GetTimeFormat&(&H800, 0, myTime, 0, s$, 254)
  291.         lblModified = Left$(s$, dl&)
  292.         s$ = String(255, 0)
  293.         dl& = GetDateFormat&(&H800, 0, myTime, 0, s$, 254)
  294.         lblModified = Left(s$, dl& - 1) & " " & lblModified
  295.                 
  296.         lblFileSize = CStr(.nFileSizeLow) & " bytes"
  297.     End With
  298.     dl& = CloseHandle&(hFile&)
  299. End Sub
  300. Private Sub cmdClose_Click()
  301.     Unload Me
  302. End Sub
  303.