论文部分内容阅读
【摘要】本语音提示系统使用Visual Basic编程工具,实现了只需按一下自定义功能组合键,播放相对应声音文件的语音提示的功能。它能运行在任何其它应用程序运行的界面上,完全不干扰用户的其它电脑操作。
【关键词】 vb;热键;语音播放
此程序的设计思路是程序界面设计一个维护热键和对应声音文件的对应表,程序注册所有热键,当用户在其他正常电脑业务流程时,需要语言提示时,按事先定义好的热键组合键,达到语音提示的功能。程序例子中定义了功能键Ctrl+Alt+ F1~F11 实现11条语音播放的功能。
程序实现步骤如下:
1. 新建一个叫“配置表.mdb”ACCESS文件,里面建一个表名称叫“对应表”,字段分别为keycode值、按键、文件名、备注,存放自定义功能键和wav声音文件的对应信息,文件放于主程序目录下。所有声音文件放于主程序目录下的wav文件夹下。
frmWh.frm主窗体下:
Private Sub Form_Load()
Dim dy As Recordset
Set dy = hydb.OpenRecordset("select * from 对应表 order by keycode值")
dy.MoveLast
‘取出热键的数量
getRownum = dy.RecordCount
dy.MoveFirst
‘取出对应表中的热键keycode值和对应的声音文件名赋给数组Hy!
Do While Not dy.EOF
For i = 1 To getRownum
Hy(i, 0) = NtoE(dy("keycode值"))
Hy(i, 1) = NtoE(dy("文件名"))
dy.MoveNext
Next
Loop
dy.Close
End Sub
2. 语音播放:按传入的参数播放相应的wav声音文件。
‘声明函数
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
‘自定义调用声音函数Fplaysound,播放wav目录下的声音文件。
Public Sub Fplaysound(id As Byte)
PlaySound App.Path & "\wav\" & Hy(id, 1), ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
3. 热键:使用热键可以在主程序不在当前界面上照样实现程序的功能。程序启动后注册取出的自定义热键。
mod_hotkey.bas模块下:‘热键相关API函数声明:
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, _
ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, _
ByVal id As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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 Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = -4
Public Const MOD_CTRL = &H2
Public Const MOD_ALT = &H1
Public glWinRet As Long
Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wmsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long
If wmsg = WM_HOTKEY Then
'调用语音播放函数,播放需要的语音提示!
Call frmWh.Fplaysound(wp_id)
CallbackMsgs = 1
Exit Function
End If
CallbackMsgs = CallWindowProc(glWinRet, wHwnd, wmsg, wp_id, lp_id)
End Function
frmWh.frm窗體下:
‘窗体load时调用该函数,注册热键hotkey,从对应表取出的存放于热键数组Hy中获取
Sub setHotKey()
For i = 1 To 100
retVal(i) = False
Next i
For i = 1 To getRownum
If Not (Hy(i, 1) = "" Or IsNull(Hy(i, 1))) Then
'注册热键hotkey: 比如取出ctrl+alt+112 即:组合键ctrl+alt+F1
retVal(i) = RegisterHotKey(Me.hwnd, i, MOD_CTRL + MOD_ALT, Hy(i, 0))
If Not retVal(i) Then
MsgBox "Can not registerthe hotkeys CTRL+ALT+" & Hy(i, 0), vbCritical
End If
End If
Next i
glWinRet = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOfCallbackMsgs)
End Sub
‘注意窗体关闭时要释放热键hotkey
Sub RemoveHotKey()
For i = 1 To getRownum
If retVal(i) Then
UnregisterHotKey Me.hwnd, i
End If
Next
End Sub
作者简介:倪盛兴,男,(1977.2-),上海人,本科,职称:中级,研究方向:医院HIS系统的软件应用和信息化发展
【关键词】 vb;热键;语音播放
此程序的设计思路是程序界面设计一个维护热键和对应声音文件的对应表,程序注册所有热键,当用户在其他正常电脑业务流程时,需要语言提示时,按事先定义好的热键组合键,达到语音提示的功能。程序例子中定义了功能键Ctrl+Alt+ F1~F11 实现11条语音播放的功能。
程序实现步骤如下:
1. 新建一个叫“配置表.mdb”ACCESS文件,里面建一个表名称叫“对应表”,字段分别为keycode值、按键、文件名、备注,存放自定义功能键和wav声音文件的对应信息,文件放于主程序目录下。所有声音文件放于主程序目录下的wav文件夹下。
frmWh.frm主窗体下:
Private Sub Form_Load()
Dim dy As Recordset
Set dy = hydb.OpenRecordset("select * from 对应表 order by keycode值")
dy.MoveLast
‘取出热键的数量
getRownum = dy.RecordCount
dy.MoveFirst
‘取出对应表中的热键keycode值和对应的声音文件名赋给数组Hy!
Do While Not dy.EOF
For i = 1 To getRownum
Hy(i, 0) = NtoE(dy("keycode值"))
Hy(i, 1) = NtoE(dy("文件名"))
dy.MoveNext
Next
Loop
dy.Close
End Sub
2. 语音播放:按传入的参数播放相应的wav声音文件。
‘声明函数
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
‘自定义调用声音函数Fplaysound,播放wav目录下的声音文件。
Public Sub Fplaysound(id As Byte)
PlaySound App.Path & "\wav\" & Hy(id, 1), ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
3. 热键:使用热键可以在主程序不在当前界面上照样实现程序的功能。程序启动后注册取出的自定义热键。
mod_hotkey.bas模块下:‘热键相关API函数声明:
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, _
ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, _
ByVal id As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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 Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = -4
Public Const MOD_CTRL = &H2
Public Const MOD_ALT = &H1
Public glWinRet As Long
Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wmsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long
If wmsg = WM_HOTKEY Then
'调用语音播放函数,播放需要的语音提示!
Call frmWh.Fplaysound(wp_id)
CallbackMsgs = 1
Exit Function
End If
CallbackMsgs = CallWindowProc(glWinRet, wHwnd, wmsg, wp_id, lp_id)
End Function
frmWh.frm窗體下:
‘窗体load时调用该函数,注册热键hotkey,从对应表取出的存放于热键数组Hy中获取
Sub setHotKey()
For i = 1 To 100
retVal(i) = False
Next i
For i = 1 To getRownum
If Not (Hy(i, 1) = "" Or IsNull(Hy(i, 1))) Then
'注册热键hotkey: 比如取出ctrl+alt+112 即:组合键ctrl+alt+F1
retVal(i) = RegisterHotKey(Me.hwnd, i, MOD_CTRL + MOD_ALT, Hy(i, 0))
If Not retVal(i) Then
MsgBox "Can not registerthe hotkeys CTRL+ALT+" & Hy(i, 0), vbCritical
End If
End If
Next i
glWinRet = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOfCallbackMsgs)
End Sub
‘注意窗体关闭时要释放热键hotkey
Sub RemoveHotKey()
For i = 1 To getRownum
If retVal(i) Then
UnregisterHotKey Me.hwnd, i
End If
Next
End Sub
作者简介:倪盛兴,男,(1977.2-),上海人,本科,职称:中级,研究方向:医院HIS系统的软件应用和信息化发展