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 / samples5 / ch13 / frmview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  10.8 KB  |  302 lines

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