[2005] simultaneous button click
Hello everybody,
i'm making a program in vb 2005 and i have a problem...i m trying to make two buttons work(be clicked and selected) programmatically...by clicking a third button...the only problem is that i want the two buttons to work simultaneously...so here is my code
Button2.PerformClick()
Button2.Select()
Button3.PerformClick()
Button3.Select()
this code is inside Button4 for example...
now, this code performs only the methods for Button3 because it's the last one...
how can i make the two buttons work simultaneously???
i know that this approach is kind of wrong...but i would really appreciate your help...
note:the two buttons contain .wav sounds that i have recorded(just to know)...
thank you for your time
sorry for my english...
theodora
Re: [2005] simultaneous button click
You're going to have the problem that two buttons can never be clicked simultaneously in a single threaded app (and not really in a multithreaded app). Each button click posts a message to the process message queue, and one will always be ahead of the other.
I see that you are playing sounds, which I have never dealt with, so they may work differently, but if each button click event just had a sub like this:
Code:
Button2Click()
PlaySound(2)
End sub
Button3Click()
PlaySound(3)
End Sub
Then you would simulate clicking the two buttons by calling:
PlaySound(2)
PlaySound(3)
Obviously, this would NOT act like two simultaneous button clicks, since one would happen just before the other one. However, that's how the actual button clicks happen anyways, so this example is the functional equivalent to having each button click event be called specifically.
What I don't know, having never worked with sound, is whether you can play one sound and start a second sound before the first one has finished playing.
Re: [2005] simultaneous button click
Your english is actually quite good. Doubtless it is better than my inability at whatever is your native tongue.
Actually, what you are trying to do must be possible, because I have played games where there were multiple sound clips overlapping. How it is done I don't know, but I would guess that it may require playing each sound on a different thread, or something like that. In your case, that is probably worth considering, since a guitar string would be a single note fading in volume over time, and without the ability to play two notes at the same time, computer sound would have to be really simplistic. Thus I believe it can be done, but exactly how I don't know. Somebody with more knowledge about playing sounds would be better equipt to answer.
Re: [2005] simultaneous button click
Hi,
Perhaps it isn't that what you need, but this is an example how to click simultaneous:
vb.net Code:
Dim the_clics As Integer
Dim my_clics As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If the_clics Mod 2 = 0 Then
Button1.Text = "Hello"
Else
Button1.Text = "Goodbye"
End If
the_clics += 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If my_clics Mod 2 = 0 Then
Me.BackColor = Color.Green
Else
Me.BackColor = Color.Blue
End If
my_clics += 1
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Button1.PerformClick()
Button2.PerformClick()
End Sub
Hope it's a start,
sparrow1
Re: [2005] simultaneous button click
Generally speaking if you want two things to happen at the "same time" (though not really, just close) you're going to have to use Threads. In that way you can have a thread start doing some work and launch another thread to do something else without having to wait for the first thread to finish it's job.
Now, if all you want to do is play sounds, while I don't know for sure I would wager that the player can play sounds asynchronously. Have you looked at directx?.... Okay a quick search turned up this http://www.vbforums.com/showthread.php?p=2586544.... I think that will help.
Re: [2005] simultaneous button click
Thank you all for your help...yes, the way to play simultaneous sounds in vb 2005 is through directX SDK...!
Also, thank you sparrow1 for the code...it has been very helpful although i started using a different approach now...
Anyway...
Thank you all for your time...;)
theodora
Re: [2005] simultaneous button click
You can also use MCI. It can sound pretty simultaneously to humans.
Re: [2005] simultaneous button click
oups it seems i have a different kind of problem now...
i managed to play simultaneous sounds by using DirectX like this
Dim Play1 As New DirectX.AudioVideoPlayback.Audio("c:\cuckoo.wav")
Dim Play2 As New DirectX.AudioVideoPlayback.Audio("c:\cuckoo2.wav")
Play1.Play()
Play2.Play()
it seems that DirectX.AudioVideoPlayback.Audio accepts only filenames/URLs to load audio files. i added my sounds to the application's resources but i can't find a way to call them since i'm using directX.
Does anyone know if i can call stored audio files by using directX???
i really want the program to run on other computers,too.
Thank you,
theodora