|
-
Jul 14th, 2011, 03:51 PM
#1
Thread Starter
New Member
Soundplay repeat problem
Hi, I have a form with a command button which plays a 4 second wav file using the PlaySound function (winnm.dll) which is set to play SND_SYNC (play then return to code) Everything works as it should however if I continue to click on the button as the wav file is playing it somehow remembers the clicks and then plays the wav again. Is there some way to prevent this? Please save my sanity and help. I have tried disabling the button and even making it invisable but "AAAAAAAAGH!" it still remembers the clicks during the 4 seconds.
-
Jul 15th, 2011, 08:51 AM
#2
Re: Soundplay repeat problem
The clicks are being added to your project's message queue. The answer is to prevent them from getting to the queue or remove them from the queue after sound plays. Without advanced code, preventing them from the queue can be done like so:
You can disable your button before playing the sound then re-enable it after it is done playing
Edited. Sounded logical but it didn't work. Maybe PeekMessage API? Thinking....
Yep PeekMessage appears to be a good choice, easier than subclassing to intercept the clicks:
Code:
Private Declare Function PeekMessage Lib "user32.dll" Alias "PeekMessageA" (ByRef lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type MSG
hWnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Const PM_REMOVE As Long = &H1
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Sub Command1_Click()
Dim pMsg As MSG
' ... your code
' clear the queue of clicks
Do Until PeekMessage(pMsg, Command1.hWnd, WM_LBUTTONDOWN, WM_LBUTTONUP, PM_REMOVE) = 0&
Loop
End Sub
Change Command1 in above code to reflect your button's name & index as needed. You may want to read more about that API (linked above). Though this fixes the mouse clicks, it does not deal with user hitting space bar or enter while button has focus. A bit of an exercise I'll leave to you for now.
Last edited by LaVolpe; Jul 15th, 2011 at 09:06 AM.
-
Jul 15th, 2011, 03:39 PM
#3
Thread Starter
New Member
Re: Soundplay repeat problem
Thanks for the quick response. Works great. I will work on solving the key problem. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|