实例说明
在本实例中,我们将制作一个能够取得本地计算机上的拨号网络的项目的应用程序。程序运行结果如图53-1所示。
图53-1 运行结果
技术要点
l 添加到列表框
实现过程
■ 新建项目
打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"GetDialList",然后选择保存路径。单击"确认"。
向窗体上添加一个ListBox控件。将窗体的Text属性改为"获得拨号网络项目",其余属性都保持默认。
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"(ByVal hKey As Integer,ByVal lpSubKey As String,ByRef phkResult As Integer) As Integer
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Integer) As Integer
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA"(ByVal hKey As Integer,ByVal dwIndex As Integer,ByVal lpName As String,ByVal cbName As Integer) As Integer
Const HKEY_CURRENT_USER As Integer = &H80000001
Const ERROR_NO_MORE_ITEMS As Short = 259
Const ERROR_SUCCESS As Short = 0
Private Sub Form1_Load(ByVal eventSender As System.Object,ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim hKey As Integer
Dim i As Integer
Dim astr As VB6.FixedLengthString = New VB6.FixedLengthString(256)
If RegOpenKey(HKEY_CURRENT_USER,"RemoteAccess/Profile",hKey) = ERROR_SUCCESS Then
While RegEnumKey(hKey,i,astr.Value,256) = ERROR_SUCCESS
List1.Items.Add(astr.Value)
i = i + 1
End While
RegCloseKey(hKey)
End If
End Sub
■ 运行程序
单击菜单"调试|启动"或单击 图标运行程序。
小结