让你的键盘唱vb代码
私有声明函数midiOutGetNumDevs Lib "winmm "()为整数
私有声明函数MIDIOutOpen Lib“winmm . dll”别名“MIDIOutOpen”(lphMidiOut为Long、ByVal uDeviceID为Long、ByVal dwCallback为Long、ByVal dwInstance为Long、ByVal dwFlags为Long)
私有声明函数midiOutClose Lib " winmm . dll "(ByVal hMidiOut As Long)
私有声明函数midioushortmsg Lib " winmm . dll "(ByVal hMidiOut为Long,ByVal dwMsg为Long)为Long
Private Declare Function midiOutGetErrorText Lib " winmm . dll " Alias " midiOutGetErrorTextA "(ByVal err As Long,ByVal lpText As String,ByVal uSize As Long)Private Const max error length = 128 '最大错误文本长度(包括NULL)Private Const midi mapper =(-1)
私有常量MIDI_MAPPER = (-1)
MIDIOUTCAPS标牌
wMid为整数
“整数形式的WPID”产品ID
“VDriverVersion As Long”设备版本
SzPname作为String * 32 '设备名称
“作为整数的技术”设备类型
wVoices为整数
表示为整数
wChannelMask为整数
dwSupport一样长
end type dim hMidi As long public Function Midi _ OutDevsToList(Obj As Control)As Boolean
将I标注为整数
将midicaps变暗为MIDIOUTCAPS
Dim被添加为布尔值
Obj。清楚的
isAdd = False
如果midioutgetdevcaps (midi mapper,midi caps,len (midi caps)) = 0,则“如果成功获取设备信息。
Obj。AddItem midicaps.szPname '添加设备名称。
' obj . item data(obj . new index)= midi mapper '这是默认的设备ID = -1。
isAdd = True
如果…就会结束
添加其他设备
对于i = 0到midiOutGetNumDevs() - 1
如果midiOutGetDevCaps(i,midicaps,Len(midicaps)) = 0,则
Obj。AddItem midicaps.szPname
Obj。ItemData(Obj。NewIndex) = i
isAdd = True
如果…就会结束
然后
Midi_OutDevsToList = isAdd
结束功能
公共函数MIDI _ out open(ByVal dev _ id As Integer)As Integer
Dim midi_error为整数midi_OutClose
midi_error = MIDIOutOpen(hMidi,dev_id,0,0,0)
如果不是midi_error = 0,则
调用midi _ outer(midi _ error)
如果…就会结束
MIDI _ out open =(HMI di & lt;& gt0)
结束功能
Public Sub midi_OutClose()
如果hMidi & lt& gt那么0
midi_error = midiOutClose(hMidi)
如果不是midi_error = 0,则
调用midi _ outer(midi _ error)
如果…就会结束
hMidi = 0
如果…就会结束
末端接头
Public Sub note_on(ch为整数,ByVal kk为整数,v为整数)
调用midi _ out short(& amp;H90 + ch,kk,v)
End SubPublic Sub note_off(ch为整数,ByVal kk为整数)
调用midi _ out short(& amp;H80 + ch,kk,0)
end sub midi _ out short(b 1为整数,b2为整数,b3为整数)
dim midi _ error As Integer midi _ error = midioushortmsg(HMI di,b3 * & ampH10000 + b2。H100 + b1)
如果不是midi_error = 0,则
调用midi _ outer(midi _ error)
如果…就会结束
末端接头
Sub program_change(ch为整数,cc0nr为整数,ByVal pnr为整数)
呼叫控制_更改(ch,0,cc0nr)
调用midi _ out short(& amp;HC0 + ch,pnr,0)
末端接头
Sub control_change(ch为整数,ccnr为整数,ByVal v为整数)
调用midi _ out short(& amp;HB0 +通道,ccnr,v)
end sub midisetrpn(ch为整数,pmsb为整数,plsb为整数,msb为整数,lsb为整数)
调用midi _ out short(ch & amp;H65,pmsb)
调用midi _ out short(ch & amp;H64,plsb)
调用midi _ out short(ch & amp;H6,msb)
调用midi _ out short(ch & amp;H26,lsb)
末端接头
sub midi _ outer(ByVal midi _ error为整数)
将s作为字符串变暗
dim x As Integer s = Space(MAXERRORLENGTH)
x = midiOutGetErrorText(midi _ error,s,MAXERRORLENGTH)
MsgBox发送订阅
用以下代码创建另一个表单,命名为form 1:Option Explicit Const Max _ Tooltip As Integer = 32。
常量NIF图标= & ampH2的删除图标
常数NIF _消息= & ampH1
常数NIF _提示= & ampH4
Const NIM _ ADD = & ampH0将图标添加到任务栏提示区域
Const NIM _ DELETE = & amp氘
Const WM _ MOUSEMOVE = & ampH200
Const WM _ LBUTTONDOWN = & ampH201
Const WM _ LBUTTONUP = & ampH202
Const WM _ LBUTTONDBLCLK = & ampH203
Const WM _ RBUTTONDOWN = & ampH204
Const WM _ RBUTTONUP = & ampH205
Const WM _ RBUTTONDBLCLK = & ampH206
Const SW_RESTORE = 9
Const SW_HIDE = 0
私有类型NOTIFYICONDATA
cbSize一样长
hwnd一样长
uId一样长
uFlags一样长
ucallbackMessage一样长
hIcon一样长
szTip作为字符串* 32
End TypePrivate声明函数Shell _ NotifyIcon Lib " Shell 32 . dll "别名" Shell _ NotifyIconA " _
(ByVal dwMessage为Long,lpData为NOTIFYICONDATA)为LongPrivate nfIconData为NOTIFYICONDATA
私有声明函数GetAsyncKeyState Lib " user 32 "(ByVal vKey As Long)作为整数私有声明函数Beep Lib " kernel 32 "(ByVal dw freq As Long,ByVal dwDuration As Long)作为整数
Dim lFreq As Long
Dim iLoop As IntegerPrivate子组件Devies_Change()
将dl标注为整数
dl = MIDI_OutOpen(ComDevies。ItemData(ComDevies。ListIndex))
End子私有子设备_Click()
将dl标注为整数
dl = MIDI_OutOpen(ComDevies。ItemData(ComDevies。ListIndex))
end Sub private Sub compounds _ Change()
调用program_change(0,0,ComSounds。列表索引)
end SubPrivate Sub compounds _ Click()
调用program_change(0,0,ComSounds。列表索引)
结束子私有子窗体_Load()
Dim参数作为字符串
Parm =命令
If InStr(Parm," h ")& lt;& gt0然后标记l2_Click
调用Midi _ OutDevsToList(ComDevies)Vol . Value = get setting(" KeySoundII "," Value "," Vol ",100)
刁。ListIndex = GetSetting(" KeySoundII "," Value "," Stage ",0)
ComDevies。ListIndex = GetSetting(" KeySoundII "," Value "," Devies ",0)
通信。ListIndex = GetSetting(" KeySoundII "," Value "," Tools ",0)
ComDevies_Click
ComSounds_Click
end Sub private Sub Form _ MouseMove(Button为整数,Shift为整数,x为Single,Y为Single)
将lMsg调成单个
lMsg = x /屏幕。TwipsPerPixelX
如果lMsg = WM_RBUTTONUP那么调用Shell_NotifyIcon(NIM_DELETE,nfIconData): Me。显示
如果lMsg = WM_LBUTTONUP那么调用Shell_NotifyIcon(NIM_DELETE,nfIconData): Me。显示
end Sub private Sub Form _ Unload(Cancel As Integer)SaveSetting " KeySoundII "," Value "," Devies ",ComDevies。列表索引
保存设置“KeySoundII”、“值”、“工具”、ComSounds。列表索引
保存设置" KeySoundII ","值","卷",卷值
SaveSetting“KeySoundII”,“Value”,“Stage”,刁。ListIndexCall Shell _ NotifyIcon(NIM _ DELETE,nfIconData)
midi_OutClose
结束
结束子私有子标签2_Click()
nfIconData.hwnd = Me.hwnd
nfIconData.uId = Me。图标
nfIconData.uFlags = NIF图标或NIF消息或NIF提示
nficondata . ucallbackmessage = WM _ MOUSEMOVE
nfIconData.hIcon = Me。图标。手柄
nficondata . SZ tip = " KeySound 1.0 " & amp;vbCrLf
nfIconData . cbsize = Len(nfIconData)
调用Shell_NotifyIcon(NIM_ADD,nfIconData)
我。隐藏
末端接头
私有子定时器1_Timer()
整数形式的静态Oldk
将Rn标注为整数
Rn = Int(Rnd * 10)
对于iLoop = 3到127
if GetAsyncKeyState(iLoop)& lt;& gt那么0
将I标注为整数
i = iLoop
如果iLoop & lt50那么i = iLoop + 50
如果iLoop & gt90那么i = iLoop - 30
if(Oldk & lt;& gtI)然后
调用note_off(0,Oldk + (diao。列表索引+ 1) * 5)
Callnote _ on (0,I+(刁。listindex+1) * 5,vol. value+rn)'参数分别为通道号、音调和速度。
调试。打印iLoop
Oldk = i
如果…就会结束
如果…就会结束
然后
末端接头