当有(*.txt或*.doc)文件时。是指有新文件。创建到该文件夹里面
解决方案 »
- vb 取字符串,在线等
- vb无线通信协议及单片机驱动问题请教
- 请问如何将DataGrid数据导出Excel
- 有需要函数库的!superruntimerlibary包含258个函数。图标菜单。。。。。
- 谁能给我详解一下这个API函数的功能及参数的意义???
- 如何vb直接调用windows自带的计算器?
- ###那个属性可以使combo不出现插入点符号?###
- 做了一个动态库,提供收发邮件的几个API函数,谁愿意帮助测试?过后赠送正式版。
- 小问题:使用image控件时,能不能用mask将图片的背景色给屏蔽掉?
- vb6 用ado操作access怎样实现模糊查询?
- VB问题:在MSFlexGrid中如何使选中的项反相显示
- 女程序员的烦恼谁来解答???如何使用进程条progressbar
http://www.mvps.org/vbnet/index.html?code/shell/shchangenotify.htmor FindChangeNotification:
http://www.mvps.org/vbnet/index.html?code/shell/shchangenotify.htm
Public Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long'常量定义
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400'定义结构体
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 '可以选
lpClass As String '可以选
hkeyClass As Long '可以选
dwHotKey As Long '可以选
hIcon As Long '可以选
hProcess As Long '可以选
End Type'Function 过程
Public Function ShowProperties(FileName As String, OwnerhWnd As Long) As Long
Dim SEI As SHELLEXECUTEINFO
Dim rPro As Long
'对SEI设置
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
.hWnd = OwnerhWnd
.lpVerb = "properties"
.lpFile = FileName
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
'调用API
rPro = ShellExecuteEX(SEI)
'返回一个成功标志
ShowProperties = SEI.hInstApp
End Functionform1中的代码在上面加入CommonDialog控件
代码如下:
Private Sub cmdOpen_Click()
CommonDialog.Filter = "TXT file (*.txt)|*.TXT|Rich Text Format files(*.rtf)|*.RTF|Word file (*.doc)|*.DOC|All file(*.*)|*.*"
CommonDialog.ShowOpen
End Sub
'文件的属性显示
'调用modset的功能函数 ShowProperties()
Private Sub cmdPropertiy_Click()
rPro = ShowProperties(CommonDialog.FileName, Me.hWnd)
End Sub
'Declaratins:
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As LongPublic Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800Type FILETIME
LowDateTime As Long
HighDateTime As Long
End Type
Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260 'MUST be set to 260
cAlternate As String * 14
End TypeDeclare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As LongType SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Public Function Findfile(xstrfilename) As WIN32_FIND_DATA
Dim Win32Data As WIN32_FIND_DATA
Dim plngFirstFileHwnd As Long
Dim plngRtn As LongplngFirstFileHwnd = FindFirstFile(xstrfilename, Win32Data) ' Get information of file using API call
If plngFirstFileHwnd = 0 Then
Findfile.cFileName = "Error" ' If file was not found, return error as name
Else
Findfile = Win32Data ' Else return results
End If
plngRtn = FindClose(plngFirstFileHwnd) ' It is important that you close the handle for FindFirstFile
End Function
form
Public Sub updatestats()
Dim ftime As SYSTEMTIME ' Initialise variables
Dim tfilename As String
tfilename = dialog.FileName
Dim filedata As WIN32_FIND_DATAfiledata = Findfile(tfilename) ' Get informationtxtname = tfilename ' Put name in text boxIf filedata.nFileSizeHigh = 0 Then ' Put size into text box
txtsize = filedata.nFileSizeLow & " Bytes"
Else
txtsize = filedata.nFileSizeHigh & "Bytes"
End IfCall FileTimeToSystemTime(filedata.ftCreationTime, ftime) ' Determine Creation date and time, then format it
lbldate(0) = ftime.wDay & "/" & ftime.wMonth & "/" & ftime.wYear & " " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
Call FileTimeToSystemTime(filedata.ftLastWriteTime, ftime) ' Determine Last Modified date and time
lbldate(1) = ftime.wDay & "/" & ftime.wMonth & "/" & ftime.wYear & " " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
Call FileTimeToSystemTime(filedata.ftLastAccessTime, ftime) ' Determine Last accessed date (note no time is recorded)
lbldate(2) = ftime.wDay & "/" & ftime.wMonth & "/" & ftime.wYearIf (filedata.dwFileAttributes And FILE_ATTRIBUTE_HIDDEN) = FILE_ATTRIBUTE_HIDDEN Then
attributes(1).Value = 1 ' Determine if file has hidden attribute set
Else
attributes(1).Value = 0
End If
If (filedata.dwFileAttributes And FILE_ATTRIBUTE_SYSTEM) = FILE_ATTRIBUTE_SYSTEM Then
attributes(2).Value = 1 ' Determine if file has system attribute set
Else
attributes(2).Value = 0
End If
If (filedata.dwFileAttributes And FILE_ATTRIBUTE_READONLY) = FILE_ATTRIBUTE_READONLY Then
attributes(3).Value = 1 ' Determine if file has readonly attribute set
Else
attributes(3).Value = 0
End If
If (filedata.dwFileAttributes And FILE_ATTRIBUTE_ARCHIVE) = FILE_ATTRIBUTE_ARCHIVE Then
attributes(4).Value = 1 ' Determine if file has archive attribute set
Else
attributes(4).Value = 0
End If
If (filedata.dwFileAttributes And FILE_ATTRIBUTE_TEMPORARY) = FILE_ATTRIBUTE_TEMPORARY Then
attributes(5).Value = 1 ' Determine if file has temporary attribute set
Else
attributes(5).Value = 0
End If
If (filedata.dwFileAttributes And FILE_ATTRIBUTE_NORMAL) = FILE_ATTRIBUTE_NORMAL Then
attributes(6).Value = 1 ' Determine if file has normal attribute set
Else
attributes(6).Value = 0
End If
If (filedata.dwFileAttributes And FILE_ATTRIBUTE_COMPRESSED) = FILE_ATTRIBUTE_COMPRESSED Then
attributes(7).Value = 1 ' Determine if file has compressed attribute set
Else
attributes(7).Value = 0
End If
End SubPrivate Sub attributes_GotFocus(Index As Integer)
ok.SetFocus ' Make it impossible to change check boxes
End Sub
Private Sub Form_Load()
On Error GoTo errhand
dialog.ShowOpen ' Show open common dialog box
updatestats ' Update infomation on form
Me.Show ' Show the form
ok.SetFocus ' Set focus to Done button
Exit Suberrhand:
If Err.Number = cdlCancel Then
Call MsgBox("You Pressed Cancel!", vbExclamation) ' Cancel was pressed in common dialog box
Else
Call MsgBox("An error has occured!", vbExclamation) ' An unexpected eror has occured
End If
End
End SubPrivate Sub ok_Click()
End
End Sub
Dim Attributes(7) As Variant另外在模块中dialog.filename被视为未定义的变量。updatestats()应该写在form的代码中,才好使。