Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define fbc -s gui res\VolLocker.rc
- #include "windows.bi"
- #include "win\commctrl.bi"
- #include "win\mmsystem.bi"
- #include "crt.bi"
- #define ShowDebug 0
- type SimpleDevIDs
- szName as zString * MAXPNAMELEN
- end type
- Declare Sub WinMain(hInstance as HINSTANCE, hPrevInstance as HINSTANCE, szCmdLine as PSTR, iCmdShow as Integer)
- enum WindowControls
- wcMain
- wcInptGrpBox ' Line Selector group box
- wcInptSlctLbl ' Line selector label
- wcInptSlct ' Line Selector to control
- wcLockEnable ' Enable/disable universal lock switch
- wcVolumeLbl
- wcVolLevelLbl ' Show volume level
- wcVolumeSlider ' Volume slider
- wcMuteLockEnable 'Enable/disable mute lock switch
- wcMuteLockCtrl ' Controls if mute is forced on/off
- wcVersionLbl 'Version label
- wcLast
- end enum
- Const WINDOW_WIDTH = 400, WINDOW_HEIGHT = 265
- dim shared as hwnd CTL(wcLast) 'Control handles
- Dim Shared as HINSTANCE hInstance
- Dim Shared as HFONT hFont
- Dim Shared as HFONT hSmallFont
- Dim Shared as String szAppName
- Dim Shared as String szCaption
- '**** mmsys stuff ****
- Declare Sub OpenMixer()
- Declare Sub CloseMixer()
- Declare Sub SetVolume(dwVolumeLevel as DWORD)
- Declare Sub SetMuteState(dwMuteState as DWORD)
- Declare Sub EnumInputDevices()
- Declare Sub EnableLock(iEnable as integer)
- Declare Sub EnableMuteLock(iEnable as integer)
- Dim shared as HWAVEIN WaveInHandle 'Handle for wave in device
- Dim shared as HMIXER MixerHandle 'Handle of mixer for wave in device
- Dim shared as MIXERLINE mixerLine 'Mixer line info
- 'State if line has mute and volume control
- Dim shared as Integer HasMuteControl = -1
- Dim shared as Integer HasVolumeControl = -1
- 'Lock states
- Dim Shared as Integer LockEnabled = 1
- Dim Shared as Integer MuteLockEnabled = 0
- Dim shared as uInteger SelectedDevice = 0 ' 0 is default device
- Dim Shared as Integer iVolume
- 'Make a list of all avalible input devices
- Dim shared as uInteger TotalDevs
- TotalDevs = waveInGetNumDevs() 'Get number of input devices
- Dim shared as SimpleDevIDs DevIDs(TotalDevs-1) 'Create array to store device IDs
- EnumInputDevices() 'Store device names in array
- hInstance = GetModuleHandle(NULL)
- szAppName = "Volume Locker"
- szCaption = "Volume Locker Settings"
- 'Launch into WinMain()
- WinMain(hInstance, NULL, Command, SW_NORMAL)
- Function WndProc (hWnd as HWND, iMsg as uInteger, wParam as WPARAM, lParam as LPARAM) as LRESULT
- Select Case iMsg
- Case WM_CREATE
- '**** Center window on desktop ****'
- Scope 'Calculate Client Area Size
- Dim as rect RcWnd = any, RcCli = Any, RcDesk = any
- GetClientRect(hWnd, @RcCli)
- GetClientRect(GetDesktopWindow(), @RcDesk)
- GetWindowRect(hWnd, @RcWnd)
- 'Window Rect is in SCREEN coordinate.... make right/bottom become WID/HEI
- with RcWnd
- .right -= .left: .bottom -= .top
- .right += (.right-RcCli.right) 'Add difference cli/wnd
- .bottom += (.bottom-RcCli.bottom) 'add difference cli/wnd
- var CenterX = (RcDesk.right-.right)\2
- var CenterY = (RcDesk.bottom-.bottom)\2
- SetWindowPos(hwnd,null,CenterX,CenterY,.right,.bottom,SWP_NOZORDER)
- end with
- end Scope
- '**** Create default font ****'
- var hDC = GetDC(hWnd) 'can be used for other stuff that requires a temporary DC
- var nHeight = -MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72) 'calculate size matching DPI
- var nSmallHeight = -MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72) 'calculate size matching DPI
- hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, _
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, _
- DEFAULT_PITCH, "Verdana")
- hSmallFont = CreateFont(nSmallHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, _
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, _
- DEFAULT_PITCH, "Verdana")
- ' Macro for creating window controls
- #define CreateControl(mID , mExStyle , mClass , mCaption , mStyle , mX , mY , mWid , mHei) CTL(mID) = CreateWindowEx(mExStyle,mClass,mCaption,mStyle,mX,mY,mWid,mHei,hwnd,cast(hmenu,mID),hInstance,null)
- const cBase = WS_VISIBLE OR WS_CHILD
- const cDropList = cBase OR CBS_DROPDOWNLIST OR CBS_HASSTRINGS OR CBS_NOINTEGRALHEIGHT OR WS_VSCROLL
- const cGrpBox = cBase OR BS_GROUPBOX
- const cLabelStyle = cBase
- const cTrackBar = cBase OR TBS_TOP' OR TBS_AUTOTICKS OR TBS_ENABLESELRANGE
- const cCheckBox = cBase OR BS_AUTOCHECKBOX OR BS_RIGHTBUTTON
- '**** Device Select Section ****'
- CreateControl(wcInptGrpBox, WS_EX_TRANSPARENT, WC_BUTTON, "Selected Input Device", cGrpBox, 5, 5, WINDOW_WIDTH-10, WINDOW_HEIGHT-10)
- CreateControl(wcInptSlctLbl, WS_EX_TRANSPARENT, WC_STATIC, "Device to lock:", cLabelStyle, 20, 29, 100, 20)
- CreateControl(wcInptSlct, NULL, WC_COMBOBOX, "", cDropList, 130, 26, 245, 100)
- 'Fill drop menu with list of input devices
- For dev as integer = 0 to TotalDevs-1
- SendMessage(ctl(wcInptSlct), CB_ADDSTRING, cast(WPARAM, 0), cast(LPARAM, @DevIDs(dev).szName))
- Next dev
- 'Select default device
- SendMessage(ctl(wcInptSlct), CB_SETCURSEL, cast(WPARAM, SelectedDevice), cast(LPARAM, 0))
- '**** Lock Enable/Disable ****'
- CreateControl(wcLockEnable, WS_EX_TRANSPARENT, WC_BUTTON, "Enable Device Lock", cCheckBox, 19, 75, 160, 20)
- SendMessage(CTL(wcLockEnable), BM_SETCHECK, TRUE, 0)
- '**** Volume Slider Section ****'
- CreateControl(wcVolumeLbl, WS_EX_TRANSPARENT, WC_STATIC, "Volume to lock device to:", cLabelStyle, 19, 110, 170, 20)
- CreateControl(wcVolLevelLbl, WS_EX_TRANSPARENT, WC_STATIC, Str(iVolume), cLabelStyle, 195, 110, 30, 20)
- CreateControl(wcVolumeSlider, NULL, TRACKBAR_CLASS, "", cTrackBar, 10, 130, 380, 30)
- SendMessage(ctl(wcVolumeSlider), TBM_SETRANGE, TRUE, MAKELONG(0, 100)) 'Set slider range
- SendMessage(ctl(wcVolumeSlider), TBM_SETPAGESIZE, 0, 4) 'Set page size
- SendMessage(ctl(wcVolumeSlider), TBM_SETSEL, FALSE, MAKELONG(0, 1)) 'Set selection range
- SendMessage(ctl(wcVolumeSlider), TBM_SETPOS, TRUE, iVolume) 'Set position
- '**** Mute Lock Enable/Disable ****'
- CreateControl(wcMuteLockEnable, WS_EX_TRANSPARENT, WC_BUTTON, "Enable Mute Lock", cCheckBox, 19, 180, 160, 20)
- CreateControl(wcMuteLockCtrl, WS_EX_TRANSPARENT, WC_BUTTON, "Mute Device:", cCheckBox, 39, 200, 140, 20)
- EnableWindow(CTL(wcMuteLockCtrl), FALSE)
- '**** Version string ****'
- CreateControl(wcVersionLbl, WS_EX_TRANSPARENT, WC_STATIC, !"Volume locker V1.0\nGraham Downey (C) 2017", cLabelStyle, 239, 225, 190, 30)
- 'Set font for all controls
- for CNT as integer = wcMain to wcLast-1
- SendMessage(CTL(CNT), WM_SETFONT, cast(WPARAM, hFont), true)
- next CNT
- 'Small font for version label
- SendMessage(CTL(wcVersionLbl), WM_SETFONT, cast(WPARAM, hSmallFont), true)
- ReleaseDC(hWnd, hDC)
- return 0
- Case WM_COMMAND
- Select Case lParam 'hwndCtl
- Case CTL(wcInptSlct)
- Select Case HIWORD(wParam) 'wNotifyCode
- Case CBN_SELCHANGE
- var iCurDevice = SendMessage(CTL(wcInptSlct), CB_GETCURSEL, 0, 0)
- if (iCurDevice <> CB_ERR) then
- print "device changed ";iCurDevice
- SelectedDevice = iCurDevice ' Set new device to lock
- CloseMixer() 'Close the old mixer device
- if LockEnabled then
- OpenMixer() 'Open new selected one
- else
- EnableLock(TRUE): EnableLock(FALSE)
- end if
- SendMessage(CTL(wcVolumeSlider), TBM_SETPOS, TRUE, iVolume)
- end if
- End Select
- Case CTL(wcLockEnable)
- Select Case HIWORD(wParam)
- Case BN_CLICKED
- 'Get checkbox state
- var iLockState = SendMessage(CTL(wcLockEnable), BM_GETCHECK, 0, 0)
- if iLockState = BST_CHECKED then
- EnableLock(TRUE)
- else
- EnableLock(FALSE)
- end if
- End Select
- Case CTL(wcMuteLockEnable)
- Select Case HIWORD(wParam)
- Case BN_CLICKED
- var iLockState = SendMessage(CTL(wcMuteLockEnable), BM_GETCHECK, 0, 0)
- if iLockState = BST_CHECKED then
- EnableMuteLock(TRUE)
- else
- EnableMuteLock(FALSE)
- end if
- End Select
- End Select
- Case WM_DESTROY
- EnableLock(FALSE) ' disable lock and close mixer
- DeleteObject(hFont)
- DeleteObject(hSmallFont)
- PostQuitMessage(0)
- return 0
- End Select
- return DefWindowProc(hWnd, iMsg, wParam, lParam)
- End Function
- Sub WinMain(hInstance as HINSTANCE, hPrevInstance as HINSTANCE, _
- szCmdLine as PSTR, iCmdShow as Integer)
- Dim as HWND hWnd
- Dim as MSG msg
- Dim as WNDCLASSEX wcls
- #if ShowDebug
- AllocConsole() 'Show console
- #endif
- OpenMixer() 'Open mixer
- wcls.cbSize = sizeof(WNDCLASSEX)
- wcls.style = CS_HREDRAW OR CS_VREDRAW
- wcls.lpfnWndProc = @WndProc
- wcls.cbClsExtra = 0
- wcls.cbWndExtra = 0
- wcls.hInstance = hInstance
- wcls.hIcon = LoadIcon(hInstance, "FB_PROGRAM_ICON")
- wcls.hCursor = LoadCursor(NULL, IDC_ARROW)
- wcls.hbrBackground = cast(HBRUSH, COLOR_BTNFACE + 1)
- wcls.lpszMenuName = NULL
- wcls.lpszClassName = strptr(szAppName)
- wcls.hIconSm = LoadIcon(hInstance, "FB_PROGRAM_ICON")
- if (RegisterClassEx(@wcls) = FALSE) then
- Print "Error! Failed to register window class ", Hex(GetLastError())
- sleep: system
- end if
- const WINDOW_STYLE = WS_OVERLAPPEDWINDOW XOR WS_THICKFRAME XOR WS_MAXIMIZEBOX
- hWnd = CreateWindow(szAppName, _ ' window class name
- szCaption, _ ' Window caption
- WINDOW_STYLE, _ ' Window style
- CW_USEDEFAULT, _ ' Initial X position
- CW_USEDEFAULT, _ ' Initial Y Posotion
- WINDOW_WIDTH, _ ' Window width
- WINDOW_HEIGHT, _ ' Window height
- NULL, _ ' Parent window handle
- NULL, _ ' Window menu handle
- hInstance, _ ' Program instance handle
- NULL) ' Creation parameters
- if hWnd = NULL then system
- ShowWindow(hWnd, iCmdShow)
- UpdateWindow(hWnd)
- 'while (GetMessage(@msg, NULL, 0, 0))
- while (msg.message <> WM_QUIT)
- while (PeekMessage(@msg, NULL, 0, 0, PM_REMOVE))
- TranslateMessage(@msg)
- DispatchMessage(@msg)
- wend
- if LockEnabled then
- 'Get volume slider position
- var iNewVolume = SendMessage(ctl(wcVolumeSlider), TBM_GETPOS, 0, 0)
- if iNewVolume <> iVolume then
- iVolume = iNewVolume 'Set master volume to new slider value
- var sVolString = Str(iVolume) 'Convert to string
- SetWindowText(ctl(wcVolLevelLbl), StrPtr(sVolString)) 'Display on label
- end if
- 'SetVolume((iVolume * &HFFFF + 50) \ 100)
- 'Set volume
- if iVolume = 100 then
- SetVolume(&HFFFF)
- else
- SetVolume(655 * (iVolume + 1))
- 'print 655 * (iVolume + 1)
- end if
- if MuteLockEnabled then
- var iLockState = SendMessage(CTL(wcMuteLockCtrl), BM_GETCHECK, 0, 0)
- if iLockState = BST_CHECKED then
- SetMuteState(1)
- else
- SetMuteState(0)
- end if
- end if
- end if
- sleep 1,1
- wend
- system msg.wParam
- 'return msg.wParam
- End Sub
- Sub EnableLock(iEnable as integer)
- 'Enable/Disable all devices
- EnableWindow(CTL(wcVolumeSlider), iEnable)
- EnableWindow(CTL(wcVolLevelLbl), iEnable)
- EnableWindow(CTL(wcVolumeLbl), iEnable)
- EnableWindow(CTL(wcMuteLockEnable), iEnable)
- if iEnable then
- OpenMixer() 'Open mixer
- LockEnabled = 1 'Enable lock
- 'Update volume display
- var sVolString = Str(iVolume)
- SetWindowText(ctl(wcVolLevelLbl), StrPtr(sVolString))
- SendMessage(CTL(wcVolumeSlider), TBM_SETPOS, TRUE, iVolume)
- if MuteLockEnabled then EnableWindow(CTL(wcMuteLockCtrl), TRUE)
- else
- CloseMixer() 'Close mixer
- LockEnabled = 0 'Disable lock
- EnableWindow(CTL(wcMuteLockCtrl), FALSE)
- end if
- End Sub
- Sub EnableMuteLock(iEnable as integer)
- 'Enable/Disable mute control
- EnableWindow(CTL(wcMuteLockCtrl), iEnable)
- if iEnable then
- MuteLockEnabled = 1 'Enable mute lock
- else
- MuteLockEnabled = 0 'Disable lock
- end if
- End Sub
- Sub EnumInputDevices()
- Dim as WAVEINCAPS caps
- if TotalDevs = 0 then
- MessageBox(NULL, "Error! No wave input devices found!", "Volume Locker - Error!", MB_ICONERROR)
- system
- end if
- for dev as uInteger = 0 to TotalDevs-1
- Dim as MMRESULT result = waveInGetDevCaps(dev, @caps, sizeof(caps))
- if (result <> MMSYSERR_NOERROR) then
- print "waveInGetDevCaps failed: returned 0x"+hex(result)
- 'sleep: system
- end if
- 'Store device names in array
- strcpy(DevIDs(dev).szName, caps.szPname) 'Store name
- next dev
- End Sub
- Sub SetVolume(dwVolumeLevel as DWORD)
- Dim as MIXERCONTROL mixerControl
- Dim as MIXERLINECONTROLS mixerLineControls
- Dim as MIXERCONTROLDETAILS mixerControlDetails
- Dim as MIXERCONTROLDETAILS_UNSIGNED value(1)
- Dim as MMRESULT result
- 'Don't try setting volume if we know it has none! lol
- if (HasVolumeControl = 0) then
- return
- end if
- mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
- mixerLineControls.dwLineID = mixerLine.dwLineID
- mixerLineControls.cControls = 1 'Only get info for one control
- 'Check for mute switch
- mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME
- mixerLineControls.pamxctrl = @mixerControl
- mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
- result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
- if (result <> MMSYSERR_NOERROR) then
- var sErrMsg = "Warning! "+mixerLine.szName+" has no volume control!"
- MessageBox(NULL, StrPtr(sErrMsg), "Volume Locker - Error!", MB_ICONWARNING)
- HasVolumeControl = 0: EnableWindow(CTL(wcVolumeSlider), FALSE) 'disable volume slider
- print mixerLine.szName; " has no volume control!"
- else
- mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
- mixerControlDetails.dwControlID = mixerControl.dwControlID
- mixerControlDetails.cChannels = mixerLine.cChannels
- if (mixerControlDetails.cChannels > 2) then mixerControlDetails.cChannels = 2
- if (mixerControl.fdwControl AND MIXERCONTROL_CONTROLF_UNIFORM) then mixerControlDetails.cChannels = 1
- mixerControlDetails.cMultipleItems = 0
- mixerControlDetails.paDetails = @value(0)
- mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)
- 'Store mute state for both channels
- value(0).dwValue = dwVolumeLevel
- value(1).dwValue = dwVolumeLevel
- result = mixerSetControlDetails(cast(HMIXEROBJ, MixerHandle), @mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " setting volume for "; mixerLine.szName
- end if
- end if
- End Sub
- Sub SetMuteState(dwMuteState as DWORD)
- Dim as MIXERCONTROL mixerControl
- Dim as MIXERLINECONTROLS mixerLineControls
- Dim as MIXERCONTROLDETAILS mixerControlDetails
- Dim as MIXERCONTROLDETAILS_UNSIGNED value(1)
- Dim as MMRESULT result
- 'Don't try setting the mute state if we know it has none!
- if (HasMuteControl = 0) then
- return
- end if
- mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
- mixerLineControls.dwLineID = mixerLine.dwLineID
- mixerLineControls.cControls = 1 'Only get info for one control
- 'Check for mute switch
- mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE
- mixerLineControls.pamxctrl = @mixerControl
- mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
- result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE)
- if (result <> MMSYSERR_NOERROR) then
- var sErrMsg = "Warning! "+mixerLine.szName+" has no mute control!"
- MessageBox(NULL, StrPtr(sErrMsg), "Volume Locker - Error!", MB_ICONWARNING)
- HasMuteControl = 0
- print mixerLine.szName; " has no mute control!"
- else
- mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
- mixerControlDetails.dwControlID = mixerControl.dwControlID
- mixerControlDetails.cChannels = mixerLine.cChannels
- if (mixerControlDetails.cChannels > 2) then mixerControlDetails.cChannels = 2
- if (mixerControl.fdwControl AND MIXERCONTROL_CONTROLF_UNIFORM) then mixerControlDetails.cChannels = 1
- mixerControlDetails.cMultipleItems = 0
- mixerControlDetails.paDetails = @value(0)
- mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)
- 'Store mute state for both channels
- value(0).dwValue = dwMuteState
- value(1).dwValue = dwMuteState
- result = mixerSetControlDetails(cast(HMIXEROBJ, MixerHandle), @mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " setting mute for "; mixerLine.szName
- end if
- end if
- End Sub
- Sub OpenMixer()
- Dim as integer result
- 'Open default input device
- dim as WAVEFORMATEX pwfx
- pwfx.wFormatTag = WAVE_FORMAT_PCM
- pwfx.nChannels = 1
- pwfx.nSamplesPerSec = 8000
- pwfx.wBitsPerSample = 8
- pwfx.nBlockAlign = (pwfx.nChannels * pwfx.wBitsPerSample) \ 8
- pwfx.nAvgBytesPerSec = pwfx.nBlockAlign * pwfx.nSamplesPerSec
- pwfx.cbSize = 0
- 'Open wave input device
- result = waveInOpen(cast(LPHWAVEIN, @WaveInHandle), SelectedDevice, @pwfx, NULL, NULL, CALLBACK_NULL)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " opening wave input device!"
- EnableLock(FALSE) 'Disable lock because we couldn't open device to lock it
- 'sleep: system
- end if
- 'Open mixer for selected input
- result = mixerOpen(@MixerHandle, cast(DWORD, WaveInHandle), 0, 0, MIXER_OBJECTF_HWAVEIN)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " opening input mixer!"
- EnableLock(FALSE)
- 'sleep: system
- end if
- 'Get line info for selected mixer
- mixerLine.cbStruct = sizeof(MIXERLINE)
- mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
- result = mixerGetLineInfo(cast(HMIXEROBJ, MixerHandle), @mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " reading line recording control!"
- EnableLock(FALSE)
- 'sleep: system
- end if
- 'Get mixer line controls
- Dim as MIXERCONTROL mxc
- Dim as MIXERLINECONTROLS mxlc
- mxlc.cbStruct = SizeOf(mxlc)
- mxlc.dwLineID = mixerLine.dwLineID
- mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME
- mxlc.cControls = 1
- mxlc.cbmxctrl = SizeOf(mxc)
- mxc.cbStruct = SizeOf(mxc)
- mxlc.pamxctrl = @mxc
- result = mixerGetLineControls(cast(HMIXEROBJ, MixerHandle), @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " getting line controls!"
- EnableLock(FALSE)
- end if
- 'Get line's current volume
- Dim as MIXERCONTROLDETAILS mxcd
- Dim as MIXERCONTROLDETAILS_SIGNED VolStruct
- mxcd.cbStruct = SizeOf(mxcd)
- mxcd.dwControlID = mxc.dwControlID
- mxcd.cbDetails = SizeOf(VolStruct)
- mxcd.paDetails = @VolStruct
- mxcd.cChannels = 1
- result = mixerGetControlDetails(cast(HMIXEROBJ, MixerHandle), @mxcd, MIXER_GETCONTROLDETAILSF_VALUE)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " getting current line volume!"
- iVolume = 0 'can't read volume, set it to 0
- else
- iVolume = VolStruct.lValue 'Otherwise, store volume
- if iVolume < 0 then iVolume = -iVolume
- end if
- iVolume = (iVolume * 100 + 50) \ 65535 'Convert from actual value to percent
- var sVolString = Str(iVolume) 'Convert to string
- SetWindowText(ctl(wcVolLevelLbl), StrPtr(sVolString)) 'Display on label
- End Sub
- Sub CloseMixer()
- Dim result as integer
- result = mixerClose(MixerHandle)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " closing mixer!"
- 'sleep: system
- end if
- result = waveInClose(WaveInHandle)
- if (result <> MMSYSERR_NOERROR) then
- print "Error #"; result; " Closing wave in device!"
- 'sleep: system
- end if
- HasVolumeControl = -1
- HasMuteControl = -1
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement