此范例是利用 API 来开启「联机/中断网络磁盘驱动器对话框」,我们必须使用 mpr.dll API 函式库的 WNetConnectionDialog 及 WNetDisconnectDialog 函式来完成,以下的 TAPIMpr 类别为操作 mpr.dll 函式库类别。

 

   1:      ''' <summary>
   2:      ''' 网络芳邻相关函式库(mpr.dll)。
   3:      ''' </summary>
   4:      Public NotInheritable Class TAPIMpr
   5:   
   6:         Public Enum EResourceType As Integer
   7:              ''' <summary>
   8:              ''' 何任资源。
   9:              ''' </summary>
  10:              RESOURCETYPE_ANY = &H0
  11:              ''' <summary>
  12:              ''' 网络磁盘驱动器。
  13:              ''' </summary>
  14:              RESOURCETYPE_DISK = &H1
  15:              ''' <summary>
  16:              ''' 网络打印机。
  17:              ''' </summary>
  18:              RESOURCETYPE_PRINT = &H2
  19:              ''' <summary>
  20:              ''' 未知。
  21:              ''' </summary>
  22:              RESOURCETYPE_UNKNOWN = &HFFFFFFFF
  23:          End Enum
  24:   
  25:          ''' <summary>
  26:          ''' 联机网络磁盘驱动器对话框。
  27:          ''' </summary>
  28:          <DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
  29:          Public Shared Function WNetConnectionDialog(ByVal hwnd As IntPtr, ByVal Type As EResourceType) As Integer
  30:          End Function
  31:   
  32:          ''' <summary>
  33:          ''' 中断网络磁盘驱动器对话框。
  34:          ''' </summary>
  35:          <DllImport("mpr.dll", CharSet:=CharSet.Auto)> _
  36:          Public Shared Function WNetDisconnectDialog(ByVal hwnd As IntPtr, ByVal Type As EResourceType) As Integer
  37:          End Function
  38:   
  39:      End Class

 

呼叫 API 的 WNetConnectionDialog 及 WNetDisconnectDialog 函式的方式如下。

   1:      ''' <summary>
   2:      ''' 联机网络磁盘驱动器对话框。
   3:      ''' </summary>
   4:      ''' <param name="Handle">窗口 Handle。</param>
   5:      ''' <returns>联机成功传回 True,反之传回 False。</returns>
   6:      Public Overloads Shared Function NetConnectionDialog(ByVal Handle As IntPtr) As Boolean
   7:          Dim iResult As Integer
   8:   
   9:          iResult = TAPIMpr.WNetConnectionDialog(Handle, TAPIMpr.EResourceType.RESOURCETYPE_DISK)
  10:          Return iResult = 0
  11:      End Function
  12:   
  13:      ''' <summary>
  14:      ''' 中断网络磁盘驱动器对话框。
  15:      ''' </summary>
  16:      ''' <param name="Handle">窗口 Handle。</param>
  17:      ''' <returns>成功传回 True,反之传回 False。</returns>
  18:      Public Overloads Shared Function NetDisconnectDialog(ByVal Handle As IntPtr) As Boolean
  19:          Dim iResult As Integer
  20:   
  21:          iResult = TAPIMpr.WNetDisconnectDialog(Handle, TAPIMpr.EResourceType.RESOURCETYPE_DISK)
  22:          Return iResult = 0
  23:      End Function

posted on 2008-04-22 11:45  jeff377  阅读(346)  评论(0编辑  收藏  举报