?
Solved

AVI/MPEG Volume must be changed

Posted on 1999-12-01
1
Medium Priority
?
193 Views
Last Modified: 2010-05-02
I need to prorammatically change the PC's volume used to play AVIs and MPEGs. I guess what i really need is a way to change the master system volume from VB.
0
Comment
Question by:rblackwell
1 Comment
 
LVL 6

Accepted Solution

by:
setiawan earned 400 total points
ID: 2248402
'***************************************************************
'Windows API/Global Declarations for :VolumeGetSet
'***************************************************************
Dim q As String, ahgt, ghtr As String
Dim id As Long, v As Long, i As Long, lVol As lVolType, Vol As VolType, lv As Double, rv As Double


Private Declare Function auxGetVolume Lib "WINMM.DLL" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long


Private Declare Function mciGetDeviceID Lib "WINMM.DLL" Alias "mciGetDeviceIDA" (ByVal lpstrName As String) As Long


Private Declare Function waveOutGetVolume Lib "WINMM.DLL" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long


Private Declare Function waveOutSetVolume Lib "WINMM.DLL" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long


Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long


Private Type lVolType
    v As Long
    End Type


Private Type VolType
    lv As Integer
    rv As Integer
    End Type

'***************************************************************
' Name: VolumeGetSet
' Description:Simple function written in VB5 for detecting curren
'     t volume setting, showing
that in a progressbar. Has button Up and Down buttons With hi/low limits that
updates the progressbar.
' By: Dennis James
'
'
' Inputs:None
'
' Returns:Gets and Changes Volume
'
'Assumes:Open New Project, add Progressbar1 and two command butto
'     ns named Command1 and
Command2. Copy Appropriate code to sections. In form load copy "Call Findout"


without the "". Insert Declarations in General Section. Create Sub Findout()
    and copy appropriate code there.
    Set Progressbar from "0 - 10" For min-max. Save and Run.
'
'Side Effects:None
'
'Code provided by Planet Source Code(tm) (http://www.Planet-Sourc
'     e-Code.com) 'as is', without warranties as to performance, fitnes
'     s, merchantability,and any other warranty (whether expressed or i
'     mplied).
'This code is copyrighted by Planet Source Code.
'It may be freely redistributed in a compiled binary executable.
'However, it may not be redistributed in source code form without
'     express written consent from Exhedra Solutions, Inc.
'***************************************************************



Sub Findout()


    id = -0
    i = waveOutGetVolume(id, v)
    lVol.v = v
    LSet Vol = lVol
    lv = Vol.lv: rv = Vol.rv
    lv = lv - &HFFF
    rv = rv - &HFFF
    If lv < -32768 Then lv = 65535 + lv
    If rv < -32768 Then rv = 65535 + rv
    Vol.lv = lv
    Vol.rv = rv
    LSet lVol = Vol
    v = lVol.v
    ghtr = Left(lv, 1)


    If ghtr = "-" Then
        Goto erre
    End If



    If lv < 5000 Then
        q = 1
        Goto sayit
    End If



    If lv < 10000 Then
        q = 2
        Goto sayit
    End If



    If lv < 15000 Then
        q = 3
        Goto sayit
    End If



    If lv < 20000 Then
        q = 4
        Goto sayit
    End If



    If lv < 25000 Then
        q = 5
        Goto sayit
    End If



    If lv < 30000 Then
        q = 6
        Goto sayit
    End If

    erre:


    If lv < (-28000) Then
        q = 7
        Goto sayit
    End If



    If lv < (-22000) Then
        q = 8
        Goto sayit
    End If



    If lv < (-15000) Then
        q = 9
        Goto sayit
    End If



    If lv < (-8000) Then
        q = 10
        Goto sayit
    End If

    sayit:
    ProgressBar1.Value = q
End Sub



Private Sub Command1_Click()



    If q = "1" Then
        Exit Sub
    End If

    id = -0
    i = waveOutGetVolume(id, v)
    lVol.v = v
    LSet Vol = lVol
    lv = Vol.lv: rv = Vol.rv
    lv = lv - &HFFF
    rv = rv - &HFFF
    If lv < -32768 Then lv = 65535 + lv
    If rv < -32768 Then rv = 65535 + rv
    Vol.lv = lv
    Vol.rv = rv
    LSet lVol = Vol
    v = lVol.v
    i = waveOutSetVolume(id, v)
    Call Findout
End Sub



Private Sub Command2_Click()



    If q = "10" Then
        Exit Sub
    End If

    Dim dfre
    j = 1
    id = -0
    i = waveOutGetVolume(id, v)
    lVol.v = v
    LSet Vol = lVol
    lv = Vol.lv: rv = Vol.rv
    lv = lv + &HFFF
    rv = rv + &HFFF
    'If lv <= -30000 Then Exit Sub
    If lv > 32767 Then lv = lv - 65536
    If rv > 32767 Then rv = rv - 65536
    Vol.lv = lv
    Vol.rv = rv
    LSet lVol = Vol
    v = lVol.v
    i = waveOutSetVolume(id, v)
    Call Findout
End Sub



Private Sub Form_Load()

    Call Findout
End Sub
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question