Rss & SiteMap

爱心论坛 http://www.zqax.net/bbs/

自强爱心网是由一群热心公益事业的残疾人共同创办的非盈利性公益网站。网站以服务残疾人为宗旨,同时携手广大残疾人及社会各界爱心人士共同打造残疾人的网上家园!
共1 条记录, 每页显示 15 条, 页签: [1]
[浏览完整版]

标题:浏览文件夹中的图片(用VB实现)

1楼
小猴乖乖 发表于:2007/8/23 7:11:36
浏览文件夹中的图片(用VB实现)
     首先要新建一个工程,在Form1中添加dirlistbox控件,drivelistbox控件,filelistbox控件,combobox控件,textbox控件,vscrollbar控件和一个command1控件
然后在代码框中输入以下代码:

Option Explicit

private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
private Const MAX_PATH = 260
private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type
private 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 * MAX_PATH
        cAlternate As String * 14
End Type

Dim Pic As Object
Private Sub Command1_Click()
Dim obj As Object
Dim pcname As String
Dim i As Long, j As Long, counter As Long
Dim wfd As WIN32_FIND_DATA
Dim source As String, piname As String
Dim hfile As Long
Dim nfile As Long
Dim filename() As String
Dim x As Long, length1 As Long, width1 As Long
counter = 0
Set Pic = Form1.Controls.Add("VB.PictureBox", "test")
Pic.Visible = True
If Right(Dir1.Path, 1) <> "\" Then
  source = Dir1.Path & "\" & Text1.Text
Else
  source = Dir1.Path & Text1.Text
End If
hfile = FindFirstFile(source, wfd)
If hfile = -1 Then
 MsgBox "没有找到文件"
End If
counter = counter + 1
Do
nfile = FindNextFile(hfile, wfd)
If nfile <> 0 Then
counter = counter + 1
End If
Loop Until nfile = 0
ReDim filename(counter) As String
hfile = FindFirstFile(source, wfd)
filename(0) = wfd.cFileName
For i = 1 To counter
 nfile = FindNextFile(hfile, wfd)
 filename(i) = wfd.cFileName
Next i
If Right(Dir1.Path, 1) <> "\" Then
source = Dir1.Path & "\"
Else
source = Dir1.Path
End If
Call FindClose(hfile)

For i = 0 To (counter / 4)
For j = 0 To 3
piname = "picture" & j + 1 + i * 4
Set obj = Form1.Controls.Add("VB.Image", piname)
obj.Width = 1500
obj.Height = 1500
obj.Stretch = True
Set obj.Container = Pic
obj.Left = j * obj.Width
obj.Top = i * obj.Height
If (j + 1 + i * 4) > counter Then
GoTo line
End If
obj.Picture = LoadPicture(source & (filename(j + 1 + i * 4)))
obj.Visible = True
Next j
Next i
line:
width1 = j * obj.Width
length1 = i * obj.Height
Pic.Width = 4 * obj.Width
Pic.Height = length1
Pic.Left = Dir1.Left + Dir1.Width
Pic.Top = 0
width1 = 4 * obj.Width
length1 = i * obj.Height
VScroll1.Min = 0
VScroll1.Max = 32767
End Sub
Private Sub Dir1_Change()
File1.filename = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Form_Load()
Combo1.Text = "*.jpg"
Combo1.AddItem "*.bmp"
Combo1.AddItem "*.gif"
VScroll1.LargeChange = 200
VScroll1.SmallChange = 50
Text1.Text = Combo1.Text
End Sub
Private Sub VScroll1_Change()
Pic.Top = 0 - VScroll1.Value
End Sub
该程序在VB6.0+WINME环境下调试通过。

欢迎广大读者和本人讨论。我的电子邮件是:ywchen2000@etang.com

共1 条记录, 每页显示 15 条, 页签: [1]

Copyright 2006 - 2022 © 自强爱心网 All Rights Reserved
工业和信息化部ICP/IP信息备案号:辽ICP备 11006191号-1
Powered By Dvbbs Version 8.3.0
Processed in .04688 s, 2 queries.