none
用VB.NET在Pocket PC中如何制作檔案總管中的資料夾清單? RRS feed

解答

  • HI,

    1. 引入Namespace

    Imports System.Runtime.InteropServices

    2.在類別中宣告

    Private Const SW_SHOW As Integer = 5

        <DllImport("coredll", CharSet:=CharSet.Auto, SetLastError:=True)> _
        Public Shared Function ShellExecuteEx(ByRef lpExecInfo As SHELLEXECUTEINFO) As Boolean
        End Function

        Public Structure SHELLEXECUTEINFO
            Public cbSize As Integer
            Public fMask As Integer
            Public hwnd As IntPtr
            <MarshalAs(UnmanagedType.LPTStr)> Public lpVerb As String
            <MarshalAs(UnmanagedType.LPTStr)> Public lpFile As String
            <MarshalAs(UnmanagedType.LPTStr)> Public lpParameters As String
            <MarshalAs(UnmanagedType.LPTStr)> Public lpDirectory As String
            Dim nShow As Integer
            Dim hInstApp As IntPtr
            Dim lpIDList As IntPtr
            <MarshalAs(UnmanagedType.LPTStr)> Public lpClass As String
            Public hkeyClass As IntPtr
            Public dwHotKey As Integer
            Public hIcon As IntPtr
            Public hProcess As IntPtr
        End Structure

    3. 開啟My Documents目錄

    Dim info As SHELLEXECUTEINFO
            info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info)
            info.lpVerb = "open"
            info.lpFile = "fexplore"
            info.lpParameters = "My Documents"
            info.nShow = SW_SHOW
            If Not ShellExecuteEx(info) Then
                Dim ex As New System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error())
                MessageBox.Show(ex.Message, "Error")
            End If

    tihs

    2007年1月9日 上午 03:21

所有回覆

  • HI,

    您可以直接呼叫Win32 API提供的ShellExecuteEx函數, 並指定要開啟那一個資料夾即可, 不需要自己製作

    tihs

    2007年1月6日 下午 12:06
  • 多謝!

    我的解決方法如下:

    Private Sub butSelectPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSelectPath.Click

           'tv is treeview
            tv.Visible = True

            If tv.Nodes.Count > 0 Then Exit Sub
            Dim di As DirectoryInfo = New DirectoryInfo("\")
            Dim fi() As DirectoryInfo = di.GetDirectories
            Dim index As Integer = 0
            tv.Nodes.Add("\")

            Try
                For Each tvi As TreeNode In tv.Nodes
                    For Each f As DirectoryInfo In fi
                        If f.Parent.Name.ToString = tvi.Text Then
                            Dim Node As New TreeNode(f.Name.ToString)
                            tvi.Nodes.Add(Node)
                            '添加本階的下階資料夾清單
                            GetNode(Node, f.FullName.ToString)
                        End If
                    Next
                Next
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

        End Sub

        Private Sub GetNode(ByVal Node As TreeNode, ByVal Path As String)
            Dim di As DirectoryInfo = New DirectoryInfo(Path)
            Dim fi() As DirectoryInfo = di.GetDirectories
            Dim index As Integer = 0
            Try
                For Each f As DirectoryInfo In fi
                    If f.Parent.Name.ToString = Node.Text Then
                        Dim Nodes As New TreeNode(f.Name.ToString)
                        Node.Nodes.Add(Nodes)
                        '遞歸調用;加載自已的子項
                        GetNode(Nodes, f.FullName.ToString)
                    End If
                Next
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub

    2007年1月8日 上午 03:39
  • HI,

    只是個小小的建議, 系統已經有的功能, 可以不要自行製作, 以免出現Style不一致的現象,

    tihs

    2007年1月8日 上午 10:28
  • Hi

        可以提供一下使用方法的代碼嗎?

        謝謝!

    2007年1月8日 上午 10:41
  • HI,

    1. 引入Namespace

    Imports System.Runtime.InteropServices

    2.在類別中宣告

    Private Const SW_SHOW As Integer = 5

        <DllImport("coredll", CharSet:=CharSet.Auto, SetLastError:=True)> _
        Public Shared Function ShellExecuteEx(ByRef lpExecInfo As SHELLEXECUTEINFO) As Boolean
        End Function

        Public Structure SHELLEXECUTEINFO
            Public cbSize As Integer
            Public fMask As Integer
            Public hwnd As IntPtr
            <MarshalAs(UnmanagedType.LPTStr)> Public lpVerb As String
            <MarshalAs(UnmanagedType.LPTStr)> Public lpFile As String
            <MarshalAs(UnmanagedType.LPTStr)> Public lpParameters As String
            <MarshalAs(UnmanagedType.LPTStr)> Public lpDirectory As String
            Dim nShow As Integer
            Dim hInstApp As IntPtr
            Dim lpIDList As IntPtr
            <MarshalAs(UnmanagedType.LPTStr)> Public lpClass As String
            Public hkeyClass As IntPtr
            Public dwHotKey As Integer
            Public hIcon As IntPtr
            Public hProcess As IntPtr
        End Structure

    3. 開啟My Documents目錄

    Dim info As SHELLEXECUTEINFO
            info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info)
            info.lpVerb = "open"
            info.lpFile = "fexplore"
            info.lpParameters = "My Documents"
            info.nShow = SW_SHOW
            If Not ShellExecuteEx(info) Then
                Dim ex As New System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error())
                MessageBox.Show(ex.Message, "Error")
            End If

    tihs

    2007年1月9日 上午 03:21
  • 謝謝...
    學到了.
    2007年1月9日 上午 03:35