如何在vb中定义一个热键,使得当一个应用程序的窗口最小化后,可以通过热键来唤醒它 ?
1个回答
展开全部
你这个功能其实就是很多影音播放器的老板键功能,给你一段代码参考一下,看看有没有帮助
'---------------------------------------------------------------------------------------
' Author
' Purpose :vb实现老板键的简单功能
'---------------------------------------------------------------------------------------
Sub Form_Load() Sub Form_Load()
Dim ret As Long
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf Wndproc)
idHotKey = 1
'按住ctrl+q实现切换
Modifiers = MOD_CONTROL
uVirtKey = vbKeyQ
ret = ReGISterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
'最小花到托盘
TrayAddIcon frmmain, App.Path & "PBs.ico", "系统托盘"
End Sub
Sub Form_Unload() Sub Form_Unload(Cancel As Integer)
Dim ret As Long
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
Call UnregisterHotKey(Me.hwnd, uVirtKey)
'退出时移出托盘图标
TrayRemoveIcon
End Sub
Sub Form_Resize() Sub Form_Resize()
'窗口最小化
If Me.Windowstate = vbMinimized Then Me.Hide
End Sub
Sub Form_MouseMove() Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'气泡单击时的鼠标事件
Dim Result As Long
Dim cEvent As Single
cEvent = X / Screen.TwipsPERPixelX
Select Case cEvent
Case MouseMove
TrayBalloon frmmain, "一键隐藏程序 v0.1 By 阿汐", NIIF_INFO
Case LeftUp
Case LeftDown
frmmain.Windowstate = 0
frmmain.Show
Case LeftDbClick
Case MiddleUp
Case MiddleDown
Case MiddleDbClick
Case RightUp
Case RightDown
Case RightDbClick
Case BalloonClick
End Select
End Sub
Sub Label1_Click() Sub Label1_Click()
End Sub
Sub Label2_Click() Sub Label2_Click()
End Sub
'---------------------------------------------------------------------------------------
' Author
' Purpose :vb实现老板键的简单功能
'---------------------------------------------------------------------------------------
Sub Form_Load() Sub Form_Load()
Dim ret As Long
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf Wndproc)
idHotKey = 1
'按住ctrl+q实现切换
Modifiers = MOD_CONTROL
uVirtKey = vbKeyQ
ret = ReGISterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
'最小花到托盘
TrayAddIcon frmmain, App.Path & "PBs.ico", "系统托盘"
End Sub
Sub Form_Unload() Sub Form_Unload(Cancel As Integer)
Dim ret As Long
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
Call UnregisterHotKey(Me.hwnd, uVirtKey)
'退出时移出托盘图标
TrayRemoveIcon
End Sub
Sub Form_Resize() Sub Form_Resize()
'窗口最小化
If Me.Windowstate = vbMinimized Then Me.Hide
End Sub
Sub Form_MouseMove() Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'气泡单击时的鼠标事件
Dim Result As Long
Dim cEvent As Single
cEvent = X / Screen.TwipsPERPixelX
Select Case cEvent
Case MouseMove
TrayBalloon frmmain, "一键隐藏程序 v0.1 By 阿汐", NIIF_INFO
Case LeftUp
Case LeftDown
frmmain.Windowstate = 0
frmmain.Show
Case LeftDbClick
Case MiddleUp
Case MiddleDown
Case MiddleDbClick
Case RightUp
Case RightDown
Case RightDbClick
Case BalloonClick
End Select
End Sub
Sub Label1_Click() Sub Label1_Click()
End Sub
Sub Label2_Click() Sub Label2_Click()
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询