473,802 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Swap Request - Master Volume Class for Remote Application Control

I need to figure out how to control any 3rd party application by
simulating mouse click and key presses. I need to take a partial window
title and get the handle then be able to send the necessary input to the
application, I have been trying for weeks to figure this out and can't.

In trade i am posting a master volume class that i modified and added
functions to.
Imports System
Imports System.Runtime. InteropServices

Public Class class_Audio_Mix er

#Region "Constants"
Private Const MMSYSERR_NOERRO R As Integer = 0
Private Const MAXPNAMELEN As Integer = 32
Private Const MIXER_LONG_NAME _CHARS As Integer = 64
Private Const MIXER_SHORT_NAM E_CHARS As Integer = 16
Private Const MIXERCONTROL_CT _CLASS_FADER As Integer = &H50000000
Private Const MIXERCONTROL_CT _UNITS_UNSIGNED As Integer = &H30000
Private Const MIXERCONTROL_CT _UNITS_BOOLEAN As Integer = &H10000
Private Const MIXERCONTROL_CT _CLASS_SWITCH As Integer = &H20000000
Private Const MIXERLINE_COMPO NENTTYPE_DST_FI RST As Integer = &H0&
Private Const MIXER_GETLINEIN FOF_COMPONENTTY PE As Integer = &H3&
Private Const MIXER_GETLINECO NTROLSF_ONEBYTY PE As Integer = &H2
Private Const MIXER_GETCONTRO LDETAILSF_VALUE As Integer = &H0
Private Const MIXER_SETCONTRO LDETAILSF_VALUE As Integer = &H0
Private Const MIXERLINE_COMPO NENTTYPE_DST_SP EAKERS As Integer =
(MIXERLINE_COMP ONENTTYPE_DST_F IRST + 4)
Private Const MIXERCONTROL_CO NTROLTYPE_FADER As Integer =
(MIXERCONTROL_C T_CLASS_FADER Or MIXERCONTROL_CT _UNITS_UNSIGNED )
Private Const MIXERCONTROL_CO NTROLTYPE_VOLUM E As Integer =
(MIXERCONTROL_C ONTROLTYPE_FADE R + 1)
Private Const MIXERCONTROL_CO NTROLTYPE_BASS As Integer =
(MIXERCONTROL_C ONTROLTYPE_FADE R + 2)
Private Const MIXERCONTROL_CO NTROLTYPE_TREBL E As Integer =
(MIXERCONTROL_C ONTROLTYPE_FADE R + 3)
Private Const MIXERCONTROL_CO NTROLTYPE_EQUAL IZER As Integer =
(MIXERCONTROL_C ONTROLTYPE_FADE R + 4)
Private Const MIXERCONTROL_CO NTROLTYPE_BOOLE AN As Integer =
(MIXERCONTROL_C T_CLASS_SWITCH Or MIXERCONTROL_CT _UNITS_BOOLEAN)
Private Const MIXERCONTROL_CO NTROLTYPE_MUTE As Integer =
(MIXERCONTROL_C ONTROLTYPE_BOOL EAN + 2)
#End Region

#Region "Api Declaration"

Private Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As
Integer) As Integer
Private Declare Function mixerGetControl DetailsA Lib "winmm.dll"
(ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDET AILS, ByVal
fdwDetails As Integer) As Integer
Private Declare Function mixerGetDevCaps A Lib "winmm.dll" (ByVal
uMxId As Integer, ByVal pmxcaps As MIXERCAPS, ByVal cbmxcaps As Integer)
As Integer
Private Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj
As Integer, ByVal pumxID As Integer, ByVal fdwId As Integer) As Integer
Private Declare Function mixerGetLineCon trolsA Lib "winmm.dll"
(ByVal hmxobj As Integer, ByRef pmxlc As MIXERLINECONTRO LS, ByVal
fdwControls As Integer) As Integer
Private Declare Function mixerGetLineInf oA Lib "winmm.dll" (ByVal
hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Integer) As
Integer
Private Declare Function mixerGetNumDevs Lib "winmm.dll" () As Integer
Private Declare Function mixerMessage Lib "winmm.dll" (ByVal hmx As
Integer, ByVal uMsg As Integer, ByVal dwParam1 As Integer, ByVal
dwParam2 As Integer) As Integer
Private Declare Function mixerOpen Lib "winmm.dll" (ByRef phmx As
Integer, ByVal uMxId As Integer, ByVal dwCallback As Integer, ByVal
dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
Private Declare Function mixerSetControl Details Lib "winmm.dll"
(ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDET AILS, ByVal
fdwDetails As Integer) As Integer

#End Region

#Region "Structures "

Private Structure MIXERCAPS
Public wMid As Integer
Public wPid As Integer
Public vDriverVersion As Integer
<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=MAXP NAMELEN)>
Public szPname As String
Public fdwSupport As Integer
Public cDestinations As Integer
End Structure 'MIXERCAPS
Private Structure MIXERCONTROL
Public cbStruct As Integer
Public dwControlID As Integer
Public dwControlType As Integer
Public fdwControl As Integer
Public cMultipleItems As Integer
<MarshalAs(Unma nagedType.ByVal TStr,
SizeConst:=MIXE R_SHORT_NAME_CH ARS)> Public szShortName As String
<MarshalAs(Unma nagedType.ByVal TStr,
SizeConst:=MIXE R_LONG_NAME_CHA RS)> Public szName As String
Public lMinimum As Integer
Public lMaximum As Integer
<MarshalAs(Unma nagedType.U4, SizeConst:=10)> Public reserved As
Integer
End Structure 'MIXERCONTROL
Private Structure MIXERCONTROLDET AILS
Public cbStruct As Integer
Public dwControlID As Integer
Public cChannels As Integer
Public item As Integer
Public cbDetails As Integer
Public paDetails As IntPtr
End Structure 'MIXERCONTROLDE TAILS
Private Structure MIXERCONTROLDET AILS_UNSIGNED
Public dwValue As Integer
End Structure 'MIXERCONTROLDE TAILS_UNSIGNED
Private Structure MIXERLINE
Public cbStruct As Integer
Public dwDestination As Integer
Public dwSource As Integer
Public dwLineID As Integer
Public fdwLine As Integer
Public dwUser As Integer
Public dwComponentType As Integer
Public cChannels As Integer
Public cConnections As Integer
Public cControls As Integer
<MarshalAs(Unma nagedType.ByVal TStr,
SizeConst:=MIXE R_SHORT_NAME_CH ARS)> Public szShortName As String
<MarshalAs(Unma nagedType.ByVal TStr,
SizeConst:=MIXE R_LONG_NAME_CHA RS)> Public szName As String
Public dwType As Integer
Public dwDeviceID As Integer
Public wMid As Integer
Public wPid As Integer
Public vDriverVersion As Integer
<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=MAXP NAMELEN)>
Public szPname As String
End Structure 'MIXERLINE
Private Structure MIXERLINECONTRO LS
Public cbStruct As Integer
Public dwLineID As Integer

Public dwControl As Integer
Public cControls As Integer
Public cbmxctrl As Integer
Public pamxctrl As IntPtr
End Structure 'MIXERLINECONTR OLS
#End Region

#Region "Internal Functions"
Private Shared Function GetVolumeContro l(ByVal hmixer As Integer,
ByVal componentType As Integer, _
ByVal ctrlType As Integer, ByRef mxc As MIXERCONTROL, ByRef
vCurrentVol As Integer) As Boolean
' This function attempts to obtain a mixer control.
' Returns True if successful.
Dim mxlc As New MIXERLINECONTRO LS
Dim mxl As New MIXERLINE
Dim pmxcd As New MIXERCONTROLDET AILS
Dim du As New MIXERCONTROLDET AILS_UNSIGNED
mxc = New MIXERCONTROL
Dim rc As Integer
Dim retValue As Boolean
vCurrentVol = -1

mxl.cbStruct = Marshal.SizeOf( mxl)
mxl.dwComponent Type = componentType

rc = mixerGetLineInf oA(hmixer, mxl,
MIXER_GETLINEIN FOF_COMPONENTTY PE)

If MMSYSERR_NOERRO R = rc Then
Dim sizeofMIXERCONT ROL As Integer = 152
Dim ctrl As Integer = Marshal.SizeOf( GetType(MIXERCO NTROL))
mxlc.pamxctrl = Marshal.AllocCo TaskMem(sizeofM IXERCONTROL)
mxlc.cbStruct = Marshal.SizeOf( mxlc)
mxlc.dwLineID = mxl.dwLineID
mxlc.dwControl = ctrlType
mxlc.cControls = 1
mxlc.cbmxctrl = sizeofMIXERCONT ROL

' Allocate a buffer for the control
mxc.cbStruct = sizeofMIXERCONT ROL

' Get the control
rc = mixerGetLineCon trolsA(hmixer, mxlc,
MIXER_GETLINECO NTROLSF_ONEBYTY PE)

If MMSYSERR_NOERRO R = rc Then
retValue = True

' Copy the control into the destination structure
mxc = CType(Marshal.P trToStructure(m xlc.pamxctrl,
GetType(MIXERCO NTROL)), MIXERCONTROL)
Else
retValue = False
End If
Dim sizeofMIXERCONT ROLDETAILS As Integer =
Marshal.SizeOf( GetType(MIXERCO NTROLDETAILS))
Dim sizeofMIXERCONT ROLDETAILS_UNSI GNED As Integer =
Marshal.SizeOf( GetType(MIXERCO NTROLDETAILS_UN SIGNED))
pmxcd.cbStruct = sizeofMIXERCONT ROLDETAILS
pmxcd.dwControl ID = mxc.dwControlID
pmxcd.paDetails =
Marshal.AllocCo TaskMem(sizeofM IXERCONTROLDETA ILS_UNSIGNED)
pmxcd.cChannels = 1
pmxcd.item = 0
pmxcd.cbDetails = sizeofMIXERCONT ROLDETAILS_UNSI GNED

rc = mixerGetControl DetailsA(hmixer , pmxcd,
MIXER_GETCONTRO LDETAILSF_VALUE )

du = CType(Marshal.P trToStructure(p mxcd.paDetails,
GetType(MIXERCO NTROLDETAILS_UN SIGNED)),
kcVoiceControl. class_Audio_Mix er.MIXERCONTROL DETAILS_UNSIGNE D)

vCurrentVol = du.dwValue

Return retValue
End If

retValue = False
Return retValue
End Function 'GetVolumeContr ol

Private Shared Function SetVolumeContro l(ByVal hmixer As Integer,
ByVal mxc As MIXERCONTROL, ByVal volume As Integer) As Boolean
Try
Dim retValue As Boolean
Dim rc As Integer
Dim mxcd As New MIXERCONTROLDET AILS
Dim vol As New MIXERCONTROLDET AILS_UNSIGNED

mxcd.item = 0
mxcd.dwControlI D = mxc.dwControlID
mxcd.cbStruct = Marshal.SizeOf( mxcd)
mxcd.cbDetails = Marshal.SizeOf( vol)

' Allocate a buffer for the control value buffer
mxcd.cChannels = 1
vol.dwValue = volume

' Copy the data into the control value buffer
mxcd.paDetails =
Marshal.AllocCo TaskMem(Marshal .SizeOf(GetType (MIXERCONTROLDE TAILS_UNSIGNED) ))
Marshal.Structu reToPtr(vol, mxcd.paDetails, False)

' Set the control value
rc = mixerSetControl Details(hmixer, mxcd,
MIXER_SETCONTRO LDETAILSF_VALUE )

If MMSYSERR_NOERRO R = rc Then
retValue = True
Else
retValue = False
End If
Return retValue
Catch ex As Exception
kcIntFunc.kcHan dleError(ex,
System.Reflecti on.MethodInfo.G etCurrentMethod )
Return False
End Try
End Function 'SetVolumeContr ol
#End Region

#Region "Exposed Functions"
Public Function GetVolume() As Integer
Dim mixer As Integer
Dim volCtrl As New MIXERCONTROL
Dim currentVol As Integer
mixerOpen(mixer , 0, 0, 0, 0)
GetVolumeContro l(mixer, MIXERLINE_COMPO NENTTYPE_DST_SP EAKERS,
MIXERCONTROL_CO NTROLTYPE_VOLUM E, volCtrl, currentVol)
mixerClose(mixe r)

Dim kcCurrentPercen t As Integer = CInt(((currentV ol * 100) /
volCtrl.lMaximu m))
Return kcCurrentPercen t
End Function

Public Function GetMute() As Boolean
Dim mixer As Integer
Dim volCtrl As New MIXERCONTROL
Dim currentVol As Integer
mixerOpen(mixer , 0, 0, 0, 0)
GetVolumeContro l(mixer, MIXERLINE_COMPO NENTTYPE_DST_SP EAKERS,
MIXERCONTROL_CO NTROLTYPE_MUTE, volCtrl, currentVol)
mixerClose(mixe r)

Return CBool(currentVo l)
End Function

Public Sub SetVolume(ByVal vVolume As Integer)
Try
Dim mixer As Integer
Dim volCtrl As New MIXERCONTROL
Dim currentVol As Integer = GetVolume()
mixerOpen(mixer , 0, 0, 0, 0)
GetVolumeContro l(mixer,
MIXERLINE_COMPO NENTTYPE_DST_SP EAKERS, MIXERCONTROL_CO NTROLTYPE_VOLUM E,
volCtrl, currentVol)

If vVolume > 100 Then
vVolume = 100
Else
If vVolume < 0 Then
vVolume = 0
End If
End If

Dim kcNewVolume As Integer = CInt(((volCtrl. lMaximum *
vVolume) / 100))
SetVolumeContro l(mixer, volCtrl, kcNewVolume)
mixerClose(mixe r)
Catch ex As Exception
kcIntFunc.kcHan dleError(ex,
System.Reflecti on.MethodInfo.G etCurrentMethod )
End Try
End Sub

Public Sub SetMute(ByVal boolMute As Boolean)
Try
Dim mixer As Integer
Dim volCtrl As New MIXERCONTROL
Dim currentVol As Integer = GetVolume()
Dim lngVolSetting As Integer

' Obtain the hmixer struct
mixerOpen(mixer , 0, 0, 0, 0)

GetVolumeContro l(mixer,
MIXERLINE_COMPO NENTTYPE_DST_SP EAKERS, MIXERCONTROL_CO NTROLTYPE_MUTE,
volCtrl, currentVol)

If boolMute = True Then
lngVolSetting = 1
Else
lngVolSetting = 0
End If

SetVolumeContro l(mixer, volCtrl, lngVolSetting)
mixerClose(mixe r)
Catch ex As Exception
kcIntFunc.kcHan dleError(ex,
System.Reflecti on.MethodInfo.G etCurrentMethod )
End Try
End Sub

Public Sub ToggleMute()
If GetMute() = False Then
SetMute(True)
Else
SetMute(False)
End If
End Sub

Public Sub VolumeDown(ByVa l DeltaValue As Integer)
SetVolume(kcVol .GetVolume - DeltaValue)
End Sub

Public Sub VolumeUp(ByVal DeltaValue As Integer)
SetVolume(GetVo lume() + DeltaValue)
End Sub
#End Region

End Class
Nov 21 '05 #1
1 2628

"Christophe r A. Kelly" <ca*****@kellco mnet.us> wrote in message
news:De******** ************@co mcast.com...
I need to figure out how to control any 3rd party application by simulating
mouse click and key presses. I need to take a partial window title and get
the handle then be able to send the necessary input to the application, I
have been trying for weeks to figure this out and can't.


http://www.devnewsgroups.net/link.as...e/default.aspx

David
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
13466
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
1
4356
by: Jeff Roughgarden | last post by:
We are hosting a 140 GB database on SQL Server Version 7 and Windows 2000 Advanced Server on an 8-cpu box connected to a 15K rpm RAID 5 SAN, with 4 GB of RAM (only 2 GB of which seem to be visible to the OS) and a 4 GB swap file. (The PeopleSoft CIS application will not permit us to upgrade to SQL 2K.) We recently upgraded the server from 4 to 8 cpus and the SAN disks from 10K to 15K drives. But we still have heavy SAN disk usage,...
8
1694
by: Kai-Uwe Bux | last post by:
Hi folks, in another thread there is some discussion about cloning smart pointers. So I started thinking about it and stumbled upon a rather simple generic implementation. However, it uses dynamic_cast<>, and I am not really familiar with that cast. So, I am not sure whether the code is correct. Please have a look and let me know how to improve this.
136
5554
by: Merrill & Michele | last post by:
A derangement is a mapping of a set onto itself leaving no element fixed. I realized that that was what I was programming when I was asked to randomly determine who buys presents for whom this year in my wife's family. Obviously, one does not buy for himself. The code is followed by some questions. #include <stdio.h> #include <stdlib.h> #include <time.h>
10
2508
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of the functions and I can't find out how to do it. Here is an example of what I do and I get the following Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the...
0
2177
by: Stefan Basler | last post by:
Hi there, I'm currently working on a VB .NET project in which I need to control the master and / or the line in of the installed sound card. I managed to control the wave volume by using waveOutSetVolume, but not the master. I've found several examples using mixerOpen for VB6, but they don't work correctly with VB.NET. I assume there is a problem with the DECLARE statement because of data type differences. I'd really appreciate any...
8
2369
by: PJ | last post by:
How can I get a reference to the master page class? It is defined as a partial class, but I cannot seem to type a variable to the name of the partial class? The compiler continually shows "The type 'MyMaster' is not defined." I would like to reference the master page from a control, by casting the Master property of the Page property to the type, but obviously I cannot do this if I can't get a reference to the actual type. Thanks,
14
7044
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that sql server resides on is not reachable. The error is different depending on the connection string that I use. If I use the following connection string: "server=192.1.1.1; Initial Catalog=master; uid=The_User; password=The_Password; Connect...
3
6962
by: Mike Carlisle | last post by:
Hi, Can someone give me some help on setting the master volume control in Vista. I've looked everywhere and there seems to be very little help on this. The only information I can find is that I should be using IAudioEndpointVolume::SetMasterVolumeLevelScalar , but no ideal how to go about this in managed code. Anyone know how to do this?
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.