如何用代码获得系统音量大小,可有现成的范例。谢谢

withstudy 2002-06-15 10:17:05
我的QQ是14568499,MAIL:wangyf1978@sina.com
...全文
149 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
withstudy 2002-06-20
  • 打赏
  • 举报
回复
感谢各位参与,小山和RISE都提出了解决办法,虽然我得到了另一种方法,而且上述二位的都没试,但仍然给分,马上结贴。
rise139 2002-06-16
  • 打赏
  • 举报
回复
对了,声明
Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
rise139 2002-06-16
  • 打赏
  • 举报
回复
dim WaveN as long
'读出
form_load
'取出当前系统音量
X& = waveOutGetVolume(0, WaveN)

'取出当前系统左声道音量
WaveNumter = GetBitLow(WaveN)

'取出当前系统右声道音量
WaveNumter = GetBitHigh(WaveN)

Slider1.Max = 255
Slider1.Value = WaveNumter
end

'设置
Private Sub Slider1_Click()
Dim W As Long
'设定当前系统音量
W = Slider1.Value
X& = waveOutSetVolume(0, W * 255 + W)
WaveNumter = W
End Sub

Function GetBitHigh(ByVal dest As Long) As Integer
GetBitHigh = (dest And 65280) \ 255
End Function

Function GetBitLow(ByVal dest As Long) As Integer
GetBitLow = dest And 255
End Function
anshinfo 2002-06-16
  • 打赏
  • 举报
回复
看了许久,没辨出那个是获得系统音量大小的,能否指教?谢谢!
daehappy 2002-06-16
  • 打赏
  • 举报
回复
up!关注!
wgku 2002-06-15
  • 打赏
  • 举报
回复
谢谢楼上的,收了:)

shawls 2002-06-15
  • 打赏
  • 举报
回复
用MCI命令来实现多媒体的播放功能下

'暂停播放
Public Function PauseMusic() As Boolean
Dim RefInt As Long
PauseMusic = False
RefInt = mciSendString("pause NOWMUSIC", vbNull, 0, 0)
If RefInt = 0 Then PauseMusic = True
End Function

'关闭媒体
Public Function CloseMusic() As Boolean
Dim RefInt As Long
CloseMusic = False
RefInt = mciSendString("close NOWMUSIC", vbNull, 0, 0)
If RefInt = 0 Then CloseMusic = True
End Function

'设置声道
Public Function SetAudioSource(sAudioSource As AudioSource) As Boolean
Dim RefInt As Long
Dim strSource As String
Select Case sAudioSource
Case 1: strSource = "left"
Case 2: strSource = "right"
Case 0: strSource = "stereo"
End Select
SetAudioSource = False
RefInt = mciSendString("setaudio NOWMUSIC source to " & strSource, vbNull, 0, 0)
If RefInt = 0 Then SetAudioSource = True
End Function

'全屏播放
Public Function PlayFullScreen() As Boolean
Dim RefInt As Long
PlayFullScreen = False
RefInt = mciSendString("play NOWMUSIC fullscreen", vbNull, 0, 0)
If RefInt = 0 Then PlayFullScreen = True
End Function

'设置声音大小
Public Function SetVolume(Volume As Long) As Boolean
Dim RefInt As Long
SetVolume = False
RefInt = mciSendString("setaudio NOWMUSIC volume to " & Volume, vbNull, 0, 0)
If RefInt = 0 Then SetVolume = True
End Function

'设置播放速度
Public Function SetSpeed(Speed As Long) As Boolean
Dim RefInt As Long
SetSpeed = False
RefInt = mciSendString("set NOWMUSIC speed " & Speed, vbNull, 0, 0)
If RefInt = 0 Then SetSpeed = True
End Function

'静音True为静音,FALSE为取消静音
Public Function SetAudioOnOff(AudioOff As Boolean) As Boolean
Dim RefInt As Long
Dim OnOff As String
SetAudioOff = False
If AudioOff Then OnOff = "off" Else OnOff = "on"
RefInt = mciSendString("setaudio NOWMUSIC " & OnOff, vbNull, 0, 0)
If RefInt = 0 Then SetAudioOff = True
End Function

'是否有画面True为有,FALSE为取消
Public Function SetWindowShow(WindowOff As Boolean) As Boolean
Dim RefInt As Long
Dim OnOff As String
SetWindowShow = False
If WindowOff Then OnOff = "show" Else OnOff = "hide"
RefInt = mciSendString("window NOWMUSIC state " & OnOff, vbNull, 0, 0)
If RefInt = 0 Then SetWindowShow = True
End Function

'获得当前媒体的状态是不是在播放
Public Function IsPlaying() As Boolean
Dim sl As String * 255
mciSendString "status NOWMUSIC mode", sl, Len(sl), 0
If Left(sl, 7) = "playing" Or Left(sl, 2) = "播放" Then
IsPlaying = True
Else
IsPlaying = False
End If
End Function

'获得播放窗口的handle
Public Function GetWindowHandle() As Long
Dim RefStr As String * 160
mciSendString "status NOWMUSIC window handle", RefStr, 80, 0
GetWindowHandle = Val(RefStr)
End Function

'获取DeviceID
Public Function GetDeviceID() As Long
GetDeviceID = mciGetDeviceID("NOWMUSIC")
End Function


以上代码来自: SourceCode Explorer(源代码数据库)
复制时间: 2002-06-15 22:31:23
当前版本: 1.0.707
作者: Shawls
个人主页: Http://Shawls.Yeah.Net
E-Mail: ShawFile@163.Net
QQ: 9181729
shawls 2002-06-15
  • 打赏
  • 举报
回复
用MCI命令来实现多媒体的播放功能中

'打开MCI设备,FILENAME为文件名,传值代表成功与否
Public Function OpenMusic(FileName As String, Optional hwnd As Long) As Boolean
OpenMusic = False
Dim ShortPathName As String * 255
Dim RefShortName As String
Dim RefInt As Long
Dim MciCommand As String
Dim DriverID As String

CloseMusic
'获取短文件名
GetShortPathName FileName, ShortPathName, 255
RefShortName = Left(ShortPathName, InStr(1, ShortPathName, Chr(0)) - 1)
'MCI命令
DriverID = GetDriverID(RefShortName)
If DriverID = "RealPlayer" Then
PlayType = RealPlay
Exit Function
End If
MciCommand = "open " & RefShortName & " type " & DriverID & " alias NOWMUSIC"


If DriverID = "AVIVideo" Or DriverID = "MPEGVideo" Or DriverID = "MPEGVideo2" Then
If hwnd <> 0 Then
MciCommand = MciCommand + " parent " & hwnd & " style child"
hWndMusic = GetWindowHandle
prevWndproc = GetWindowLong(hWndMusic, -4)
SetWindowLong hWndMusic, -4, AddressOf WndProc

Else
MciCommand = MciCommand + " style overlapped "
End If
End If

RefInt = mciSendString(MciCommand, vbNull, 0, 0)
mciSendString "set NOWMUSIC time format milliseconds", vbNullString, 0, 0
If RefInt = 0 Then OpenMusic = True

End Function
Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = &H202 Then
MsgBox "OK"
End If
WndProc = CallWindowProc(prevWndproc, hwnd, Msg, wParam, lParam)
End Function

'根据文件名,确定设备
Public Function GetDriverID(ff As String) As String
Select Case UCase(Right(ff, 3))
Case "MID", "RMI", "IDI"
GetDriverID = "Sequencer"
Case "WAV"
GetDriverID = "Waveaudio"
Case "ASF", "ASX", "IVF", "LSF", "LSX", "P2V", "WAX", "WVX", ".WM", "WMA", "WMX", "WMP"
GetDriverID = "MPEGVideo2"
Case ".RM", "RAM", ".RA"
GetDriverID = "RealPlayer"
Case Else
GetDriverID = "MPEGVideo"
End Select
End Function

'播放文件
Public Function PlayMusic() As Boolean
Dim RefInt As Long
PlayMusic = False
RefInt = mciSendString("play NOWMUSIC", vbNull, 0, 0)
If RefInt = 0 Then PlayMusic = True
End Function

'获取媒体的长度
Public Function GetMusicLength() As Long
Dim RefStr As String * 80
mciSendString "status NOWMUSIC length", RefStr, 80, 0
GetMusicLength = Val(RefStr)
End Function

'获取当前播放进度
Public Function GetMusicPos() As Long
Dim RefStr As String * 80
mciSendString "status NOWMUSIC position", RefStr, 80, 0
GetMusicPos = Val(RefStr)
End Function

'获取媒体的当前进度
Public Function SetMusicPos(Position As Long) As Boolean
Dim RefInt As Long
SetMusicPos = False
RefInt = mciSendString("seek NOWMUSIC to " & Position, vbNull, 0, 0)
If RefInt = 0 Then SetMusicPos = True
End Function


以上代码来自: SourceCode Explorer(源代码数据库)
复制时间: 2002-06-15 22:31:10
当前版本: 1.0.707
作者: Shawls
个人主页: Http://Shawls.Yeah.Net
E-Mail: ShawFile@163.Net
QQ: 9181729
shawls 2002-06-15
  • 打赏
  • 举报
回复
用MCI命令来实现多媒体的播放功能上

'用MCI命令来实现多媒体的播放功能
'下面的内容几乎有播放器软件的各种功能,你只是引用这些函数就能做出一个播放器来
'

Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Declare Function mciGetDeviceID Lib "winmm.dll" Alias "mciGetDeviceIDA" (ByVal lpstrName As String) As Long

Public Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume 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 SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Enum PlayTypeName
File = 1
CDAudio = 2
VCD = 3
RealPlay = 4
End Enum
Dim PlayType As PlayTypeName
Enum AudioSource
AudioStereo = 0 ' "stereo"
AudioLeft = 1 '"left"
AudioRight = 2 '"right"
End Enum
Dim hWndMusic As Long
Dim prevWndproc As Long

'打开MCI设备,urlStr为网址,传值代表成功与否
Public Function OpenURL(urlStr As String, Optional hwnd As Long) As Boolean
OpenMusic = False
Dim MciCommand As String
Dim DriverID As String

CloseMusic
'MCI命令
DriverID = GetDriverID(urlStr)
If DriverID = "RealPlayer" Then
PlayType = RealPlay
Exit Function
End If
MciCommand = "open " & urlStr & " type " & DriverID & " alias NOWMUSIC"


If DriverID = "AVIVideo" Or DriverID = "MPEGVideo" Or DriverID = "MPEGVideo2" Then
If hwnd <> 0 Then
MciCommand = MciCommand + " parent " & hwnd & " style child"
hWndMusic = GetWindowHandle
prevWndproc = GetWindowLong(hWndMusic, -4)
SetWindowLong hWndMusic, -4, AddressOf WndProc

Else
MciCommand = MciCommand + " style overlapped "
End If
End If

RefInt = mciSendString(MciCommand, vbNull, 0, 0)
mciSendString "set NOWMUSIC time format milliseconds", vbNullString, 0, 0
If RefInt = 0 Then OpenMusic = True

End Function


以上代码来自: SourceCode Explorer(源代码数据库)
复制时间: 2002-06-15 22:30:37
当前版本: 1.0.707
作者: Shawls
个人主页: Http://Shawls.Yeah.Net
E-Mail: ShawFile@163.Net
QQ: 9181729
1,cdrecorder.ZIP 一个用API函数编写的CD抓轨程序(5KB)2,mci.ZIP MCI的应用示例,包括播放WAV、MIDI文件和播放CD及将CD中的曲目转录为WAV文件等(5KB)3,wavplay.ZIP 播放WAV文件的演示(23KB)4,vbpiano.ZIP 一个模拟钢琴的源程序,(需要Threed32.ocx)(75KB)5,videocap.ZIP 一个视频捕捉程序,安装了视频捕捉设备的朋友可以下载来看一看(12KB)6,mixer.ZIP 一个非常完全的waveOut程序,包括了一个waveOut类和使用类的范例,这个范例获得Windows下所有的wave输入输出设备的名称以及属性(22KB)7,agent1.ZIP Microsoft Agent范例程序,你的系统中必须已经安装了Agent2.0以上版本(2KB)8,sound_cap.ZIP 利用DirectSound和MS Agent建立的一个语音复读机。读音的捕捉和回放由DirectSound实现,MS Agent实现标准朗读(5KB)9,mmfile_play.ZIP 利用Windows API函数实现多媒体文件得播放,可以播放MPG、AVI、MDI、WAV等文件以及文件信息(128KB)10,midi_drum.ZIP VB鼓机的音序器(26KB)11,flashsamp.ZIP 这是一个介绍如何控制Flash控件显示Flash文件的程序(62KB)12,m032.ZIP 定时计时器(530KB)13,m031_plmaker.ZIP 播放列表生成器(4KB)14,m029_speech.ZIP 程序会朗读(2KB)15,m028_mp3.ZIP 简单的mp3播放器(10KB)16,m027_mp3test.ZIP MP3播放器(3KB)17,m025_zm016.ZIP 一个音量控制小程序(6KB)18,m024_videocap.ZIP 视频捕捉程序(12KB)19,m023_mcd.ZIP CD播放器(23KB)20,m022_mmedia.ZIP 多媒体播放器(3KB)21,m021_Play33.ZIP 电子琴(9KB)22,m020_vbamp.ZIP WINAMP(141KB) 23,m019_testsc.ZIP 声卡测试程序(3KB)24,m018_cdaudio.ZIP CD播放机(4KB)25,m016_aviplay.ZIP 利用Windows API 播放AVI文件(3KB)26,m015.ZIP 一个音量控制小程序(7KB)27,m014.ZIP 播放.mid格式的背景音乐,你可以在此基础上增加其它功能(13KB) 28,m013.ZIP 播放.WAV文件,并显示其波形(6KB)29,m012.ZIP 可同时8个Wave文件混音(338KB) 30,m011.ZIP 能混合很多种声音的好程序(14KB)31,m010.ZIP 播放Wave, Midi和Avi文件(7KB)32,m004.ZIP 多媒体控件的使用,自带EXE(8KB)33,m003.ZIP MULTIMEDIA MCI 多媒体控件的应用,自带EXE(3KB)34,m002.ZIP 可以播放mp3的dll,并附有一个完整的示例程序(可以显示播放时间等,功能强大),自带现成的EXE文件,非常Cool(82KB)35,m001.ZIP 使用API函数播放wav文件(350KB)36,anidemo.ZIP 使用windows api演示动画的例子(288KB) 37,anic.ZIP 动画光标的例子(4KB)38,waveplay.ZIP 播放wave的例子(350KB) 39,jpegvu.ZIP 显示jpeg文件的例子(116KB)40,g

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧