⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 wince 中查找文件的源码
💻 VB
字号:
Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(16, 16)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(368, 277)
        Me.ListBox1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(400, 310)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim pData As IntPtr, cData As Integer
        Dim hRapi As Int32 = CeRapiInit()
        If hRapi > 0 Then
            Return
        End If
        Dim ret As Boolean = CeFindAllFiles("\*", FAF.FAF_NAME Or FAF.FAF_ATTRIBUTES, cData, pData)
        If ret Then
            Dim p As IntPtr = pData
            For i As Integer = 0 To cData - 1
                Dim fd As CE_FIND_DATA
                fd = Marshal.PtrToStructure(p, GetType(CE_FIND_DATA))
                ListBox1.Items.Add(fd)
                p = New IntPtr(p.ToInt32() + Marshal.SizeOf(GetType(CE_FIND_DATA)))
            Next
            CeRapiFreeBuffer(pData)
        Else
            Debug.WriteLine(CeRapiGetError().ToString("X"))
        End If
        CeRapiUnInit()
    End Sub

    <DllImport("rapi.dll")> _
    Private Shared Function CeRapiInit() As Integer
    End Function

    <DllImport("rapi.dll")> _
    Private Shared Function CeRapiUninit() As Integer
    End Function

    <DllImport("rapi.dll", CharSet:=CharSet.Unicode)> _
    Private Shared Function CeFindAllFiles(ByVal Path As String, ByVal Flags As FAF, ByRef cbItems As Int32, ByRef ppItems As IntPtr) As Boolean
    End Function

    <DllImport("rapi.dll")> _
    Private Shared Function CeRapiFreeBuffer(ByVal Buffer As IntPtr) As Int32
    End Function
    <DllImport("rapi.dll")> _
    Private Shared Function CeRapiGetError() As Integer
    End Function

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
    Private Class CE_FIND_DATA
        Dim dwFileAttributes As Integer
        Dim ftCreationTimeLo As Integer
        Dim ftCreationTimeHi As Integer
        Dim ftLastAccessTimeLo As Integer
        Dim ftLastAccessTimeHi As Integer
        Dim ftLastWriteTimeLo As Integer
        Dim ftLastWriteTimeHi As Integer
        Dim nFileSizeLo As Integer
        Dim nFileSizeHi As Integer
        Dim dwOID As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
        Dim cFileName As String
        Overrides Function ToString() As String
            Return cFileName
        End Function
    End Class

    <Flags()> _
    Private Enum FAF
        FAF_ATTRIBUTES = &H1
        FAF_CREATION_TIME = &H2
        FAF_LASTACCESS_TIME = &H4
        FAF_LASTWRITE_TIME = &H8
        FAF_SIZE_HIGH = &H10
        FAF_SIZE_LOW = &H20
        FAF_OID = &H40
        FAF_NAME = &H80
        FAF_ATTRIB_CHILDREN = &H1000
        FAF_ATTRIB_NO_HIDDEN = &H2000
        FAF_FOLDERS_ONLY = &H4000
        FAF_NO_HIDDEN_SYS_ROMMODULES = &H8000
        FAF_GETTARGET = &H10000
    End Enum

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -