VB实现给控件添加系统声音
2012-04-22 10:32
267 查看
作品展中组员做了一个小游戏,功能都实现了但还有很多方面要维护,其中添加声音就是改进的一方面。通过上网搜集找到了些代码,很简单也很有意思,和大家分享一下。
(1)添加“咚”的声音
在窗体上添加一个command按钮
private sub command1_click()
beep
end sub
(2)其他的系统声音
使用API: MessageBeep
声明: Declare Function MessageBeep Lib "user32" Alias "MessageBeep" (ByVal wType As Long) As Long
把下面的东西复制到一个新的空白的form中,不要任何东西,不要有代码、控件。
Private Const MB_ICONASTERISK = &H40&
Private Const MB_ICONEXCLAMATION = &H30&
Private Const MB_ICONHAND = &H10&
Private Const MB_ICONINFORMATION = MB_ICONASTERISK
Private Const MB_OK = &H0&
Private Declare Function MessageBeep Lib "user32" (ByVal wType As Long) As Long
Dim WithEvents Command1 As CommandButton
Dim WithEvents Command2 As CommandButton
Dim WithEvents Command3 As CommandButton
Dim WithEvents Command4 As CommandButton
Dim WithEvents Command5 As CommandButton
Dim WithEvents Command6 As CommandButton
Private Sub Command1_Click()
MessageBeep 0
End Sub
Private Sub Command2_Click()
MessageBeep MB_ICONASTERISK
End Sub
Private Sub Command3_Click()
MessageBeep MB_ICONEXCLAMATION
End Sub
Private Sub Command4_Click()
MessageBeep MB_ICONHAND
End Sub
Private Sub Command5_Click()
MessageBeep MB_ICONINFORMATION
End Sub
Private Sub Command6_Click()
MessageBeep MB_OK
End Sub
Private Sub Form_Load()
MessageBeep 0
Set Command1 = Me.Controls.Add("VB.CommandButton", "Command1")
Command1.Visible = True
Command1.Caption = "0"
Command1.Left = 120
Command1.Top = 240
Command1.Height = 255
Command1.Width = 1215
Set Command2 = Me.Controls.Add("VB.CommandButton", "Command2")
Command2.Visible = True
Command2.Caption = "MB_ICONASTERISK"
Command2.Left = 120
Command2.Top = 600
Command2.Height = 255
Command2.Width = 1935
Set Command3 = Me.Controls.Add("VB.CommandButton", "Command3")
Command3.Visible = True
Command3.Caption = "MB_ICONEXCLAMATION"
Command3.Left = 120
Command3.Top = 960
Command3.Height = 255
Command3.Width = 1935
Set Command4 = Me.Controls.Add("VB.CommandButton", "Command4")
Command4.Visible = True
Command4.Caption = "MB_ICONHAND"
Command4.Left = 120
Command4.Top = 1320
Command4.Height = 255
Command4.Width = 1935
Set Command5 = Me.Controls.Add("VB.CommandButton", "Command5")
Command5.Visible = True
Command5.Caption = "MB_ICONINFORMATION"
Command5.Left = 120
Command5.Top = 1680
Command5.Height = 255
Command5.Width = 1935
Set Command6 = Me.Controls.Add("VB.CommandButton", "Command6")
Command6.Visible = True
Command6.Caption = "MB_OK"
Command6.Left = 120
Command6.Top = 2040
Command6.Height = 255
Command6.Width = 1935
End Sub
运行时出现六个按钮 点击就会出现声音
(1)添加“咚”的声音
在窗体上添加一个command按钮
private sub command1_click()
beep
end sub
(2)其他的系统声音
使用API: MessageBeep
声明: Declare Function MessageBeep Lib "user32" Alias "MessageBeep" (ByVal wType As Long) As Long
把下面的东西复制到一个新的空白的form中,不要任何东西,不要有代码、控件。
Private Const MB_ICONASTERISK = &H40&
Private Const MB_ICONEXCLAMATION = &H30&
Private Const MB_ICONHAND = &H10&
Private Const MB_ICONINFORMATION = MB_ICONASTERISK
Private Const MB_OK = &H0&
Private Declare Function MessageBeep Lib "user32" (ByVal wType As Long) As Long
Dim WithEvents Command1 As CommandButton
Dim WithEvents Command2 As CommandButton
Dim WithEvents Command3 As CommandButton
Dim WithEvents Command4 As CommandButton
Dim WithEvents Command5 As CommandButton
Dim WithEvents Command6 As CommandButton
Private Sub Command1_Click()
MessageBeep 0
End Sub
Private Sub Command2_Click()
MessageBeep MB_ICONASTERISK
End Sub
Private Sub Command3_Click()
MessageBeep MB_ICONEXCLAMATION
End Sub
Private Sub Command4_Click()
MessageBeep MB_ICONHAND
End Sub
Private Sub Command5_Click()
MessageBeep MB_ICONINFORMATION
End Sub
Private Sub Command6_Click()
MessageBeep MB_OK
End Sub
Private Sub Form_Load()
MessageBeep 0
Set Command1 = Me.Controls.Add("VB.CommandButton", "Command1")
Command1.Visible = True
Command1.Caption = "0"
Command1.Left = 120
Command1.Top = 240
Command1.Height = 255
Command1.Width = 1215
Set Command2 = Me.Controls.Add("VB.CommandButton", "Command2")
Command2.Visible = True
Command2.Caption = "MB_ICONASTERISK"
Command2.Left = 120
Command2.Top = 600
Command2.Height = 255
Command2.Width = 1935
Set Command3 = Me.Controls.Add("VB.CommandButton", "Command3")
Command3.Visible = True
Command3.Caption = "MB_ICONEXCLAMATION"
Command3.Left = 120
Command3.Top = 960
Command3.Height = 255
Command3.Width = 1935
Set Command4 = Me.Controls.Add("VB.CommandButton", "Command4")
Command4.Visible = True
Command4.Caption = "MB_ICONHAND"
Command4.Left = 120
Command4.Top = 1320
Command4.Height = 255
Command4.Width = 1935
Set Command5 = Me.Controls.Add("VB.CommandButton", "Command5")
Command5.Visible = True
Command5.Caption = "MB_ICONINFORMATION"
Command5.Left = 120
Command5.Top = 1680
Command5.Height = 255
Command5.Width = 1935
Set Command6 = Me.Controls.Add("VB.CommandButton", "Command6")
Command6.Visible = True
Command6.Caption = "MB_OK"
Command6.Left = 120
Command6.Top = 2040
Command6.Height = 255
Command6.Width = 1935
End Sub
运行时出现六个按钮 点击就会出现声音
相关文章推荐
- 章鱼哥—VB.NET 如何实现代码自动生成控件 添加绑定事件
- 用VB写的一个组件,实现添加系统用户,并添加到指定组
- vb实现系统托盘控件下载
- 用VB写的一个组件,实现添加系统用户,并添加到指定组
- VB.NET状态栏控件上添加任意控件
- 系统 : 用VB实现窗口图标最小化到系统托盘
- php 数组动态添加实现代码(最土团购系统的价格排序)
- Edit控件实现系统时间动态显示
- VB运行时动态注册添加控件的方法
- angularjs 实现动态添加控件
- vb.net2005动态添加网页控件的事件
- 地磅称量系统之(40) 实现称量管理界面上的添加、修改、删除、保存、取消按钮的代码
- Android 调用相册 拍照 实现系统控件缩放 切割图片
- Android控件Gridview实现多个menu模块,可添加可删除
- ios给按钮添加系统声音,AudioServicesPlaySystemSound 系统声音提示
- ios 中添加frameworok,实现软件声音和振动
- JavaScript在控件上添加倒计时功能的实现代码
- #245 – 向TextBlock控件中添加格式文本的简单实现(Easily Inline Text Formatting Codes with TextBlock Control)
- vue实现学生录入系统之添加删除功能
- 在VB中动态添加可响应消息的控件