VB 快速切换wifi软件 [提供案例参考吧]

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long '定义API
Private Declare Function timeGetTime Lib "winmm.dll" () As Long '调用时间API
Private Const HWND_TOPMOST = -1 '窗体最上层常数
Private Const SWP_NOMOVE = &H2 '窗体不移动(保持当前位置(x和y设定将被忽略))
Private Const SWP_NOSIZE = &H1 '窗体大小不变(保持当前大小(cx和cy会被忽略))
'窗口拖动
Dim X0!, Y0!

Private Sub E_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '左键
Shell "cmd.exe /c netsh wlan connect name=""BNU""" '连接EDUwifi

'状态提示
LabelE_color.BackStyle = 1
'计时 记录当前计算及运行的时间
Dim savetime As Double
savetime = timeGetTime '记下开始时的时间
While timeGetTime < savetime + 20000 '时间间隔为500ms

If PingIP("172.16.202.201") Then
LabelE_color.BackColor = vbGreen
Else
LabelE_color.BackColor = vbRed
End If
savetime1 = timeGetTime
While timeGetTime < savetime1 + 50
DoEvents
Wend

DoEvents
Wend
LabelE_color.BackColor = RGB(255, 255, 255)
LabelE_color.BackStyle = 0

End If

If Button = 2 Then '右键
Shell App.Path & "\DNSrepairV3.exe"
End If
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X0 = X
Y0 = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
'鼠标指针样式更改
Me.MousePointer = 5
'窗口移动
Me.Left = Me.Left + X - X0
Me.Top = Me.Top + Y - Y0
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'鼠标指针样式还原
Me.MousePointer = 1
End Sub

Private Sub P_Click()
Shell "cmd.exe /c netsh wlan connect name=""Printer Wifi""" '连接Printer wifi
'状态提示
LabelP_color.BackStyle = 1
'计时 记录当前计算及运行的时间
Dim savetime As Double
savetime = timeGetTime '记下开始时的时间
While timeGetTime < savetime + 20000 '时间间隔为500ms

If PingIP("192.168.31.1") Then  '小米路由器wifi网关地址----------------------------------------------------------------------Maybe 需要根据实际情况修改
LabelP_color.BackColor = vbGreen
Else
LabelP_color.BackColor = vbRed
End If
savetime1 = timeGetTime
While timeGetTime < savetime1 + 50
DoEvents
Wend

DoEvents
Wend
LabelP_color.BackColor = RGB(255, 255, 255)
LabelP_color.BackStyle = 0
End Sub
Private Sub C_Click()
End
End Sub
Private Sub Form_Load() '程序一运行就执行
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE '设置最上层窗口
End Sub

Private Sub Timer1_Timer()
'GetCursorPos P
If Me.Top <= 400 And Me.Top >= 0 Then Me.Top = 0
If Me.Top + Me.Height >= Screen.Height - 400 Then Me.Top = Screen.Height - Me.Height
End Sub

Private Sub Timer2_Timer()
On Error Resume Next
Dim P As POINTAPI
Dim f As RECT
GetCursorPos P
GetWindowRect Me.hwnd, f
If Me.WindowState <> 1 Then
If P.X > f.Left And P.X < f.Right And P.Y > f.Top And P.Y < f.Bottom Then
If Me.Top < 0 Then
Me.Top = -10
Me.Show
ElseIf Me.Left < 0 Then
Me.Left = -10
Me.Show
ElseIf Me.Left + Me.Width >= Screen.Width Then
Me.Left = Screen.Width - Me.Width + 10
Me.Show
End If
ElseIf f.Top <= 4 Then
Me.Top = 40 - Me.Height
ElseIf f.Left <= 4 Then
Me.Left = 40 - Me.Width
ElseIf Me.Left + Me.Width >= Screen.Width - 4 Then
Me.Left = Screen.Width - 40
End If
End If
End Sub

截图

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值