Windows Mobile文件和文件夹图标 [英] Windows Mobile File and Folder Icons

查看:67
本文介绍了Windows Mobile文件和文件夹图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我目前正在为Windows Mobile 5.0开发文件浏览器应用程序.
我已经成功地将系统目录放置在treeview控件中,但是我想使用系统图标在每个文件夹和每个文件上放置图标.以及如何在加载文件中创建后台线程.当我尝试在\ Windows \目录中加载文件时,需要20秒才能加载所有文件.我已经尝试为其创建线程,但根本没有任何更改.这是我的代码.

''资源管理器类

Hello to all !

I am currently developing a file explorer application for windows mobile 5.0.
I have successfully put the system directories in my treeview control but I want to put icons on each folder and each file using system icons. And also how to create background thread in loading files. When I try to load files in \Windows\ directory, it takes 20 seconds to load all the files. I have tried creating thread for it but no changes at all. This is my code.

'' Explorer Class

Imports System.Runtime.InteropServices
Imports System.IntPtr

Public Class Explorer
    Private Info As ArrayList
#Region "Enumeration"
    Private Enum Types
        File
        Folder
    End Enum
#End Region
#Region "Structure"
    Private Structure SFile
        Public FullName As String
        Public Name As String
        Public Size As String
        Public Modified As String
        Public Type As Types
    End Structure
#End Region
#Region "Function"
    Private Function FormatSize(ByVal size As Long) As String
        Dim sizes() As String = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
        Dim formattedsize As Long = size
        Dim sizeIndex As Int32
        While formattedsize >= 1024 And sizeIndex < sizes.Length
            formattedsize /= 1024
            sizeIndex += 1
        End While
        Return Math.Round(formattedsize, 2).ToString & " " & sizes(sizeIndex)
    End Function
#End Region
#Region "Sub"
    Public Sub New()
    End Sub
    Public Sub LoadTree(ByVal nTree As TreeNode, ByVal Path As String)
        Dim ePath() As String = System.IO.Directory.GetDirectories("\" & Path.Trim("\"))
        For Each strPath In ePath
            nTree.Nodes.Add(strPath.Substring(strPath.LastIndexOf("\"), strPath.Length - strPath.LastIndexOf("\")).Trim("\"))
            Dim nNtree As TreeNode = nTree.Nodes(nTree.Nodes.Count - 1)
            Dim FullPath As String = nNtree.FullPath.Trim("\")
            FullPath = FullPath.Substring(FullPath.IndexOf("\"), FullPath.Length - FullPath.IndexOf("\"))
            LoadTree(nNtree, FullPath)
        Next
    End Sub
    Public Sub FillListView(ByVal _listView As ListView, ByVal Path As String)
        FillArrayWithFilesAndFolder(Info, Path)

        _listView.Clear()
        '' Set Columns
        _listView.Columns.Add("Name", _listView.Width / 3, HorizontalAlignment.Left)
        _listView.Columns.Add("Modified", 4 * _listView.Width / 15, HorizontalAlignment.Left)
        _listView.Columns.Add("Size", _listView.Width / 5, HorizontalAlignment.Right)
        _listView.Columns.Add("Type", _listView.Width / 5, HorizontalAlignment.Left)

        For Each ArrayItem As Object In Info
            Dim fullname As String = ""
            Dim lvitem As ListViewItem = New ListViewItem(DirectCast(ArrayItem, SFile).Name)
            lvitem.SubItems.Add(DirectCast(ArrayItem, SFile).Modified)
            If DirectCast(ArrayItem, SFile).Size = Nothing Then lvitem.SubItems.Add("") Else lvitem.SubItems.Add(FormatSize(CLng(DirectCast(ArrayItem, SFile).Size)))
            lvitem.SubItems.Add(If(DirectCast(ArrayItem, SFile).Type = Types.File, "File", "Folder"))
            _listView.Items.Add(lvitem)
        Next

    End Sub
    Private Sub FillArrayWithFilesAndFolder(ByRef InfoList As ArrayList, ByVal Path As String)
        InfoList = New ArrayList()
        InfoList.Clear()
        If System.IO.Directory.Exists(Path) Then
            Try
                Dim dr() As String = System.IO.Directory.GetDirectories(Path)
                For Each folder As String In dr
                    Dim FileInfo As SFile = New SFile
                    FileInfo.FullName = folder
                    FileInfo.Type = Types.Folder
                    FileInfo.Modified = System.IO.Directory.GetLastWriteTime(folder).ToString
                    FileInfo.Size = Nothing
                    FileInfo.Name = folder.Substring(folder.LastIndexOf("\"), folder.Length - folder.LastIndexOf("\")).Trim("\")
                    InfoList.Add(FileInfo)
                Next
                Dim fl() As String = System.IO.Directory.GetFiles(Path)
                For Each files As String In fl
                    Dim FileInfo As SFile = New SFile
                    FileInfo.FullName = files
                    FileInfo.Type = Types.File
                    FileInfo.Modified = System.IO.Directory.GetLastWriteTime(files).ToString
                    FileInfo.Name = files.Substring(files.LastIndexOf("\"), files.Length - files.LastIndexOf("\")).Trim("\")
                    Try
                        Using Fsize As System.IO.FileStream = System.IO.File.OpenRead(files)
                            FileInfo.Size = Fsize.Length.ToString
                        End Using
                    Catch ex As Exception
                        FileInfo.Size = "0"
                    End Try
                    InfoList.Add(FileInfo)
                Next
            Catch ex As Exception
            End Try
        End If
    End Sub
#End Region

End Class


''FORM类


'' FORM Class

Public Class frmMain
    Dim Moving As Boolean = False
    Dim nExplorer As Explorer
    Const SplitterWidth As Integer = 8
    Const Distance As Integer = 6
    Const MouseDistance As Integer = 5
    Const EdgeDistance As Integer = 10
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        nExplorer = New Explorer
        lvwPath.Capture = False
        eTree.Nodes.Clear()
        eTree.Nodes.Add("Window Delve")

        Dim nTree As TreeNode = eTree.Nodes(eTree.Nodes.Count - 1)
        nExplorer.LoadTree(nTree, "\")
        nExplorer.FillListView(lvwPath, "\")
        eTree.Nodes(0).Expand()
        picSplitter.Location = New Point(Me.Width / 2, 0)
        RelocateObj()
    End Sub
    Private Sub RelocateObj()
        picSplitter.Size = New Size(SplitterWidth, Me.Height - If(eHideToolBar.Checked, 0, stBar.Height))
        eTree.Size = New Size(picSplitter.Left, Me.Height - If(eHideToolBar.Checked, 0, stBar.Height))
        eTree.Location = New Point(0, 0)
        lvwPath.Location = New Point(picSplitter.Left + Distance, 0)
        lvwPath.Size = New Size(Me.Width - lvwPath.Left, Me.Height - If(eHideToolBar.Checked, 0, stBar.Height))
    End Sub

    Private Sub frmMain_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        Moving = True
        picSplitter.Visible = True
        picSplitter.Left = e.X - MouseDistance
    End Sub
    Private Sub frmMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        If Moving Then
            If picSplitter.Left - EdgeDistance > 0 Or picSplitter.Left + EdgeDistance < Me.Width Then
                picSplitter.Left = e.X - MouseDistance
                If eDrag.Checked Then RelocateObj()
            End If
        End If
    End Sub

    Private Sub frmMain_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
        Moving = False
        picSplitter.Visible = False
        If Not eDrag.Checked Then RelocateObj()
    End Sub
    Private Sub picSplitter_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picSplitter.Resize
        If Not Moving Then RelocateObj()
    End Sub
    Private Sub eTree_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles eTree.AfterSelect
        Cursor.Current = Cursors.WaitCursor
        stBar.Text = eTree.SelectedNode.Text
        Dim fullpath As String = eTree.SelectedNode.FullPath.Replace("Window Delve", "")
        nExplorer.FillListView(lvwPath, fullpath)
        Cursor.Current = Cursors.Default
    End Sub

    Private Sub eDrag_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eDrag.Click
        eDrag.Checked = Not eDrag.Checked
    End Sub

    Private Sub eHideToolBar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eHideToolBar.Click
        eHideToolBar.Checked = Not eHideToolBar.Checked
        stBar.Visible = Not eHideToolBar.Checked
        RelocateObj()
    End Sub

End Class


这是我的程序
http://www.4shared.com/file/kTylfHIg/WindowDelve.html [ ^ ]
谢谢!!! :)


here is my program
http://www.4shared.com/file/kTylfHIg/WindowDelve.html[^]
Thank you!!! :)

推荐答案

使用后台工作线程.有关示例,请参见 BackgroundWorker线程和支持取消 [
Use a Background worker thread. For a sample, see BackgroundWorker Threads and Supporting Cancel[^].


这篇关于Windows Mobile文件和文件夹图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆