vb中全局快捷键的问题

我用vb做了一个程序,其中插入了一个控件:windowsmediaplayer,名称是WindowsMediaPlayer1。怎么做全局快捷键,使当按下Ctrl+Alt+... 我用vb做了一个程序,其中插入了一个控件:windows media player,名称是WindowsMediaPlayer1。怎么做全局快捷键,使当按下Ctrl+Alt+↑增大音量,当按下Ctrl+Alt+↓减小音量?谢啦~
貌似都没有做到全局快捷键····
展开
 我来答
ASPNET初探
2009-01-15 · 超过25用户采纳过TA的回答
知道答主
回答量:57
采纳率:0%
帮助的人:81.2万
展开全部
需要一个时间控件 Timer1

'api声明
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer '热键

Private Sub Form_Load()
Timer1.Interval=100
Timer1.Enabled = true
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyUp) Then '按下Ctrl+Alt+↑
If WindowsMediaPlayer1.settings.volume < 100 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume + 1
End If
End If

If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyDown) Then '按下Ctrl+Alt+↓
If WindowsMediaPlayer1.settings.volume > 0 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume - 1
End If
End If
End Sub
楼下的老兄怎么Copy我的代码啊!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zhenghanxi
2009-01-15 · TA获得超过422个赞
知道小有建树答主
回答量:268
采纳率:0%
帮助的人:257万
展开全部
'以下保存在模块中
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312
Public Const MOD_CONTROL = &H2
Public Const MOD_ALT = &H1
Public Const VK_UP = &H26
Public Const VK_DOWN = &H28
Public preWinProc As Long
Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam
Case 0
If Form1.WindowsMediaPlayer1.settings.volume < 100 Then Form1.WindowsMediaPlayer1.settings.volume = Form1.WindowsMediaPlayer1.settings.volume + 1
Case 1
If Form1.WindowsMediaPlayer1.settings.volume > 0 Then Form1.WindowsMediaPlayer1.settings.volume = Form1.WindowsMediaPlayer1.settings.volume - 1
End Select
End If
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function

’以下保存在窗体中
Private Sub Form_Load()
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC) '获得窗口过程的地址
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf wndproc '为窗口过程设定一个新的地址
RegisterHotKey Me.hwnd, 0, MOD_CONTROL + MOD_ALT, VK_UP
RegisterHotKey Me.hwnd, 1, MOD_CONTROL + MOD_ALT, VK_DOWN '登记热键
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnregisterHotKey Me.hwnd, 0
UnregisterHotKey Me.hwnd, 1 '释放先前登记的热键
SetWindowLong Me.hwnd, GWL_WNDPROC, preWinProc '还原窗口过程地址
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
happychao123
2009-01-15 · TA获得超过119个赞
知道答主
回答量:483
采纳率:0%
帮助的人:111万
展开全部
'api声明
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer '热键

Private Sub Form_Load()
Timer1.Interval=100
Timer1.Enabled = true
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyUp) Then '按下Ctrl+Alt+↑
If WindowsMediaPlayer1.settings.volume < 100 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume + 1
End If
End If

If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyDown) Then '按下Ctrl+Alt+↓
If WindowsMediaPlayer1.settings.volume > 0 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume - 1
End If
End If
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
715420247
2009-01-15 · TA获得超过495个赞
知道小有建树答主
回答量:630
采纳率:0%
帮助的人:324万
展开全部
NO
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式