- 最後登錄
- 2021-11-9
- 在線時間
- 22 小時
- 註冊時間
- 2006-9-23
- 閱讀權限
- 95
- 精華
- 0
- UID
- 272990
- 帖子
- 70
- 積分
- 1000 點
- 潛水值
- 14348 米
| - Attribute VB_Name = "Module1"
- ' Mixer Code provided by GivenRandy
- ' He kewl.
- ' The dos console stuff provided by gridrun [TNC]
- ' He kewl.
- ' I did command line parsing stuff. :)
- Dim hMixer As Long
- Dim VolCtrl As MIXERCONTROL
- Dim hMem As Long
- Dim Mxlc As MIXERLINECONTROLS
- Dim Mxl As MIXERLINE
- Dim Mxcd As MIXERCONTROLDETAILS
- Dim Vol As MIXERCONTROLDETAILS_UNSIGNED
- Const MMSYSERR_NOERROR = 0
- Const MAXPNAMELEN = 32
- Const MIXER_LONG_NAME_CHARS = 64
- Const MIXER_SHORT_NAME_CHARS = 16
- Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
- Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&
- Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
- Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
- Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
- Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
- Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
- Const MIXERCONTROL_CONTROLTYPE_FADER = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
- Const MIXERCONTROL_CONTROLTYPE_VOLUME = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
- Private Type MIXERCONTROLDETAILS
- cbStruct As Long
- dwControlID As Long
- cChannels As Long
- item As Long
- cbDetails As Long
- paDetails As Long
- End Type
- Private Type MIXERCONTROLDETAILS_UNSIGNED
- dwValue As Long
- End Type
- Private Type MIXERCONTROL
- cbStruct As Long
- dwControlID As Long
- dwControlType As Long
- fdwControl As Long
- cMultipleItems As Long
- szShortName As String * MIXER_SHORT_NAME_CHARS
- szName As String * MIXER_LONG_NAME_CHARS
- lMinimum As Long
- lMaximum As Long
- reserved(10) As Long
- End Type
- Private Type MIXERLINECONTROLS
- cbStruct As Long
- dwLineID As Long
- dwControl As Long
- cControls As Long
- cbmxctrl As Long
- pamxctrl As Long
- End Type
- Private Type MIXERLINE
- cbStruct As Long
- dwDestination As Long
- dwSource As Long
- dwLineID As Long
- fdwLine As Long
- dwUser As Long
- dwComponentType As Long
- cChannels As Long
- cConnections As Long
- cControls As Long
- szShortName As String * MIXER_SHORT_NAME_CHARS
- szName As String * MIXER_LONG_NAME_CHARS
- dwType As Long
- dwDeviceID As Long
- wMid As Integer
- wPid As Integer
- vDriverVersion As Long
- szPname As String * MAXPNAMELEN
- End Type
- Private 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
- Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
- Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
- Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
- Private Declare Sub CopyPtrFromStruct Lib "kernel32" Alias "RtlMoveMemory" (ByVal ptr As Long, struct As Any, ByVal cb As Long)
- Private Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (struct As Any, ByVal ptr As Long, ByVal cb As Long)
- Private Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, ByVal uMxId As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal fdwOpen As Long) As Long
- Private Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
- Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Long, pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
- Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Long) As Long
- Sub Main()
- ConAcquire
-
- If Command$ = "" Or InStr(1, Command$, "/?") > 0 Then
- ConPrint "To use just type in " & App.EXEName & " n"
- ConPrint "n is a number between 0 and 100"
- 'MsgBox "hey"
- End
- End If
-
- Dim Newvolume As Long
-
- Newvolume = CLng(Command$)
-
- If (mixerOpen(hMixer, 0, 0, 0, 0) <> MMSYSERR_NOERROR) Then
- ConPrint "Could not open the mixer. Type /? for help."
- ConPrint "Sorry no fix for this...."
- ' MsgBox "hey"
- Exit Sub
- End If
- Dim Max As Long
- Dim Min As Long
-
-
- If (fGetVolumeControl(hMixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, MIXERCONTROL_CONTROLTYPE_VOLUME, VolCtrl)) Then
- Max = VolCtrl.lMinimum
- Min = VolCtrl.lMaximum \ 2
-
- End If
- mciSendString "open cdaudio", 0, 0, hWnd
-
- fSetVolumeControl hMixer, VolCtrl, CLng(Min * Newvolume / 100 * 2)
- mciSendString "close all", 0, 0, hWnd
- ConPrint
- ConPrint "Volume Set to " & Newvolume & "%"
- 'ConRelease
- End
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- End Sub
- Private Sub VScroll1_Change()
- fSetVolumeControl hMixer, VolCtrl, CLng(VScroll1.Value) * 2
- End Sub
- Private Sub VScroll1_Scroll()
- fSetVolumeControl hMixer, VolCtrl, CLng(VScroll1.Value) * 2
- End Sub
- Private Sub fSetVolumeControl(ByVal hMixer As Long, Mxc As MIXERCONTROL, ByVal Volume As Long)
- Mxcd.item = 0
- Mxcd.dwControlID = Mxc.dwControlID
- Mxcd.cbStruct = Len(Mxcd)
- Mxcd.cbDetails = Len(Vol)
- hMem = GlobalAlloc(&H40, Len(Vol))
- Mxcd.paDetails = GlobalLock(hMem)
- Mxcd.cChannels = 1
- Vol.dwValue = Volume
- CopyPtrFromStruct Mxcd.paDetails, Vol, Len(Vol)
- mixerSetControlDetails hMixer, Mxcd, MIXER_SETCONTROLDETAILSF_VALUE
- Call GlobalFree(hMem)
- End Sub
- Private Function fGetVolumeControl(ByVal hMixer As Long, ByVal componentType As Long, ByVal ctrlType As Long, ByRef Mxc As MIXERCONTROL) As Boolean
- Mxl.cbStruct = Len(Mxl)
- Mxl.dwComponentType = componentType
- If (mixerGetLineInfo(hMixer, Mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) = MMSYSERR_NOERROR) Then
- Mxlc.cbStruct = Len(Mxlc)
- Mxlc.dwLineID = Mxl.dwLineID
- Mxlc.dwControl = ctrlType
- Mxlc.cControls = 1
- Mxlc.cbmxctrl = Len(Mxc)
- hMem = GlobalAlloc(&H40, Len(Mxc))
- Mxlc.pamxctrl = GlobalLock(hMem)
- Mxc.cbStruct = Len(Mxc)
- If (mixerGetLineControls(hMixer, Mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) = MMSYSERR_NOERROR) Then
- fGetVolumeControl = True
- Call CopyStructFromPtr(Mxc, Mxlc.pamxctrl, Len(Mxc))
- Else
- fGetVolumeControl = False
- End If
- Call GlobalFree(hMem)
- Exit Function
- End If
- fGetVolumeControl = False
- End Function
複製代碼 ... |
|