VB.NET 这门语言被我们大部分人所熟悉。但是今天在这里还是要介绍一下首先接受一下VB.NET,更主要的是让大家深入的了解一下VB.NET路径选择目录对话框实例。
VB.NET是Visual Basic.net的简称。提到VB.NET,就不能不先提一下vb(Visual Basic)。Visual Basic是Windows环境下的一种简单、易学的编程语言,由于其开发程序的快速、高效,深受程序员的喜爱。严格地来说Visual Basic只是半面向对象的语言,其面向对象的能力及程序的执行效率往往不能一些程序员的需要,因此,大的项目很少使用Visual Basic来开发。Visual Basic的***一个版本是Visual Basic 6.0。在Visual Basic 6.0之后,微软公司推出了全新的“.NEt构架”,在其***个版本-Visual Studio.NET 7.0中,集成了Visual Basic 7.0、Visual C++ 7.0及C#,其中的Visual Basic 7.0(vb 7.0),即是vb.net的***个版本。现在.NET是***版本是Visual Studio 2005,对应的vb.net的***版本是集成在其中的Visual Basic 9.0(vb 9.0),也可称为vb.net 2005。 下面介绍一下VB.NET路径选择目录对话框实现(API):
- Private Type BrowseInfo
- hWndOwner As Long
- pIDLRoot As Long
- pszDisplayName As Long
- lpszTitle As Long
- ulFlags As Long
- lpfnCallback As Long
- lParam As Long
- iImage As Long
- End Type
- Const BIF_RETURNONLYFSDIRS = 1
- Const MAX_PATH = 260
- Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
- Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
- Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
- Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
- Private Function getFolder(ByVal title As String) As String
- Dim iNull As Integer, lpIDList As Long, lResult As Long
- Dim sPath As String, udtBI As BrowseInfo
- With udtBI
- '设置弹出的对话框的父窗口句柄
- .hWndOwner = Me.hWnd
- .lpszTitle = lstrcat(title, "") '标题
- .ulFlags = BIF_RETURNONLYFSDIRS
- End With
- lpIDList = SHBrowseForFolder(udtBI)
- If lpIDList Then
- sPath = String$(MAX_PATH, 0)
- SHGetPathFromIDList lpIDList, sPath
- CoTaskMemFree lpIDList
- iNull = InStr(sPath, vbNullChar)
- If iNull Then
- sPath = Left$(sPath, iNull - 1)
- End If
- End If
- getFolder = sPath
- End Function
- Private Sub Command1_Click()
- Text1.Text = getFolder("请选择文件夹")
- End Sub
以上就VB.NET路径解决方案,希望可以给你带来帮助。
【编辑推荐】