欢迎光临
我们一直在努力

如何控制系统音量_visualbasic教程

建站超值云服务器,限时71元/月

->thankstoRickRatayczakofFutureWorksMedia(rickr@execpc.com)
savefileandrenamethemto[name].BAS

AttributeVB_Name=”MIXER”
****************************************************************************
*ThisconstantholdsthevalueoftheHighestCustomvolumesetting.The*
*lowestvaluewillalwaysbezero.*
****************************************************************************
PublicConstHIGHEST_VOLUME_SETTING=12

Puttheseintoamodule
deviceIDforauxdevicemapper
PublicConstAUX_MAPPER=-1&
PublicConstMAXPNAMELEN=32

TypeAUXCAPS
wMidAsInteger
wPidAsInteger
vDriverVersionAsLong
szPnameAsString*MAXPNAMELEN
wTechnologyAsInteger
dwSupportAsLong
EndType

flagsforwTechnologyfieldinAUXCAPSstructure
PublicConstAUXCAPS_CDAUDIO=1audiofrominternalCD-ROMdrive
PublicConstAUXCAPS_AUXIN=2audiofromauxiliaryinputjacks

flagsfordwSupportfieldinAUXCAPSstructure
PublicConstAUXCAPS_VOLUME=&H1supportsvolumecontrol
PublicConstAUXCAPS_LRVOLUME=&H2separateleft-rightvolumecontrol

DeclareFunctionauxGetNumDevsLib”winmm.dll”()AsLong
DeclareFunctionauxGetDevCapsLib”winmm.dll”Alias”auxGetDevCapsA”(ByValuDeviceIDAsLong,lpCapsAsAUXCAPS,ByValuSizeAsLong)AsLong

DeclareFunctionauxSetVolumeLib”winmm.dll”(ByValuDeviceIDAsLong,ByValdwVolumeAsLong)AsLong
DeclareFunctionauxGetVolumeLib”winmm.dll”(ByValuDeviceIDAsLong,ByReflpdwVolumeAsLong)AsLong
DeclareFunctionauxOutMessageLib”winmm.dll”(ByValuDeviceIDAsLong,ByValmsgAsLong,ByValdw1AsLong,ByValdw2AsLong)AsLong

****************************************************************************
*PossibleReturnvaluesfromauxGetVolume,auxSetVolume*
****************************************************************************
PublicConstMMSYSERR_NOERROR=0
PublicConstMMSYSERR_BASE=0
PublicConstMMSYSERR_BADDEVICEID=(MMSYSERR_BASE 2)

****************************************************************************
*UsetheCopyMemoryfunctionfromtheWindowsAPI*
****************************************************************************
PublicDeclareSubCopyMemoryLib”kernel32″Alias”RtlMoveMemory”(hpvDestAsAny,hpvSourceAsAny,ByValcbCopyAsLong)

****************************************************************************
*UsethisstructuretobreaktheLongintotwoIntegers*
****************************************************************************
PublicTypeVolumeSetting
LeftVolAsInteger
RightVolAsInteger
EndType

SublCrossFader()
Vol1=100-Slider1.ValueLeft
Vol2=100-Slider5.ValueRight
E=CrossFader.Value
F=100-E
IfCheck4.Value=1ThenHalfFaderCheck
LVol=(F*Val(Vol1)/100)*2
RVol=(E*Val(Vol2)/100)*2
IfLVol>(50*Val(Vol1)/100)*2Then
LVol=(50*Val(Vol1)/100)*2
EndIf
IfRVol>(50*Val(Vol2)/100)*2Then
RVol=(50*Val(Vol2)/100)*2
EndIf
Else
LVol=(F*Val(Vol1)/100)
RVol=(E*Val(Vol2)/100)
EndIf
Label1.Caption=”Fader:” LTrim$(Str$(LVol)) “x” LTrim$(Str$(RVol))

EndSub

PublicFunctionlSetVolume(ByReflLeftVolAsLong,ByReflRightVolAsLong,lDeviceIDAsLong)AsLong
****************************************************************************
*ThisfunctionsetsthecurrentWindowsvolumesettingstothespecified*
*deviceusingtwoCustomnumbersfrom0toHIGHEST_VOLUME_SETTINGforthe*
*rightandleftvolumesettings.*
**
*ThereturnvalueofthisfunctionistheReturnvalueoftheauxGetVolume*
*WindowsAPIcall.*
****************************************************************************

DimbReturnValueAsBooleanReturnValuefromFunction
DimVolumeAsVolumeSettingTypestructureusedtoconvertalongto/from
twoIntegers.

DimlAPIReturnValAsLongReturnvaluefromAPICall
DimlBothVolumesAsLongTheAPIpassedvalueoftheCombinedVolumes

****************************************************************************
*CalculatetheIntegers*
****************************************************************************
Volume.LeftVol=nSigned(lLeftVol*65535/HIGHEST_VOLUME_SETTING)
Volume.RightVol=nSigned(lRightVol*65535/HIGHEST_VOLUME_SETTING)

****************************************************************************
*CombinetheIntegersintoaLongtobePassedtotheAPI*
****************************************************************************
lDataLen=Len(Volume)
CopyMemorylBothVolumes,Volume.LeftVol,lDataLen

****************************************************************************
*SettheValuetotheAPI*
****************************************************************************
lAPIReturnVal=auxSetVolume(lDeviceID,lBothVolumes)
lSetVolume=lAPIReturnVal

EndFunction

PublicFunctionlGetVolume(ByReflLeftVolAsLong,ByReflRightVolAsLong,lDeviceIDAsLong)AsLong
****************************************************************************
*ThisfunctionreadsthecurrentWindowsvolumesettingsfromthe*
*specifieddevice,andreturnstwonumbersfrom0to*
*HIGHEST_VOLUME_SETTINGfortherightandleftvolumesettings.*
**
*ThereturnvalueofthisfunctionistheReturnvalueoftheauxGetVolume*
*WindowsAPIcall.*
****************************************************************************

DimbReturnValueAsBooleanReturnValuefromFunction
DimVolumeAsVolumeSettingTypestructureusedtoconvertalongto/from
twoIntegers.
DimlAPIReturnValAsLongReturnvaluefromAPICall
DimlBothVolumesAsLongTheAPIReturnoftheCombinedVolumes

****************************************************************************
*GettheValuefromtheAPI*
****************************************************************************
lAPIReturnVal=auxGetVolume(lDeviceID,lBothVolumes)

****************************************************************************
*SplittheLongvaluereturnedfromtheAPIintotoIntegers*
****************************************************************************
lDataLen=Len(Volume)
CopyMemoryVolume.LeftVol,lBothVolumes,lDataLen

****************************************************************************
*CalculatetheReturnValues.*
****************************************************************************
lLeftVol=HIGHEST_VOLUME_SETTING*lUnsigned(Volume.LeftVol)/65535
lRightVol=HIGHEST_VOLUME_SETTING*lUnsigned(Volume.RightVol)/65535

lGetVolume=lAPIReturnVal
EndFunction

PublicFunctionnSigned(ByVallUnsignedIntAsLong)AsInteger
DimnReturnValAsIntegerReturnvaluefromFunction

IflUnsignedInt>65535OrlUnsignedInt<0Then
MsgBox”ErrorinconversionfromUnsignedtonSignedInteger”
nSignedInt=0
ExitFunction
EndIf

IflUnsignedInt>32767Then
nReturnVal=lUnsignedInt-65536
Else
nReturnVal=lUnsignedInt
EndIf

nSigned=nReturnVal

EndFunction

PublicFunctionlUnsigned(ByValnSignedIntAsInteger)AsLong
DimlReturnValAsLongReturnvaluefromFunction

IfnSignedInt<0Then
lReturnVal=nSignedInt 65536
Else
lReturnVal=nSignedInt
EndIf

IflReturnVal>65535OrlReturnVal<0Then
MsgBox”ErrorinconversionfromnSignedtoUnsignedInteger”
lReturnVal=0
EndIf

lUnsigned=lReturnVal
EndFunction->

->

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何控制系统音量_visualbasic教程
分享到: 更多 (0)