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.
Re: Soundplay repeat problem
Thanks for the quick response. Works great. I will work on solving the key problem. Thanks again.