vb程序高手帮帮忙解答一下!!谢谢!

2024-11-27 18:47:33
推荐回答(1个)
回答(1):

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long '声明函数
Private Const SND_ASYNC = &H1& '声明常量
Private Const SND_LOOP = &H8& '声明常量
Private Const SND_MEMORY = &H4& '声明常量
Private Const SND_NODEFAULT = &H2& '声明常量
Private Const SND_NOSTOP = &H10& '声明常量
Private Const SND_SYNC = &H0& '声明常量

Dim bArr() As Byte, bArr2() As Byte '定义两个数组
Private Sub cmdSound_Click() '按钮事件过程
Dim h As Integer, m As Integer, n As Integer '定义变量

bArr = LoadResData(118, "CUSTOM") '载入资源库118号资源
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC '播放该资源

bArr = LoadResData(116, "CUSTOM") '载入资源库116号资源
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC '播放该资源
h = Hour(Now) '获取当前系统时间的小时数
n = h \ 10 '获取当前系统时间的小时数的十位数
If n = 0 Then '如果当前小时数是一位数,则
bArr = LoadResData(100 + h, "CUSTOM") '载入资源库(100+当前小时数)号资源
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC '播放该资源
Else '如果当前小时数是两位数,则
: bArr = LoadResData(110 + n - 1, "CUSTOM") '载入资源库(110-当前小时数)号资源

h = h Mod 10 '获取当前小时数的个位数
bArr2 = LoadResData(100 + h, "CUSTOM") '载入资源库(100+当前小时数)号资源
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC '播放上一次载入的资源
If h <> 0 Then sndPlaySound bArr2(0), SND_MEMORY Or SND_SYNC '如果小时数不为0,就播放刚才载入的资源
End If '结束判断

bArr = LoadResData(117, "CUSTOM") '载入资源库117号资源

sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC '播放该资源

m = Minute(Now) '获取当前时间的分钟数
n = m \ 10 '具体过程跟小时数一样
If n = 0 Then
If m <> 0 Then
bArr = LoadResData(100, "CUSTOM")
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC
bArr = LoadResData(100 + m, "CUSTOM")
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC
End If
Else
bArr = LoadResData(110 + n - 1, "CUSTOM")

m = m Mod 10
bArr2 = LoadResData(100 + m, "CUSTOM")
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC
If m <> 0 Then sndPlaySound bArr2(0), SND_MEMORY Or SND_SYNC
End If

If m <> 0 Or n <> 0 Then
bArr = LoadResData(115, "CUSTOM")
sndPlaySound bArr(0), SND_MEMORY Or SND_SYNC
End If

End Sub