Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 434
Default Silent Msgbox?

hi, Joe !

Yes, I am playing the sound synchronously. That is my intent.
Since Iassociate Windows XP Startup.wav with the "Default Beep" sound
the sndPlaySound call should take about 4.85 sec.
(And it does, as demonstrated by the macro doit3() below.)

My question is: why don't I see and hear the volume muted for the duration of the sndPlaySound call, nearly 5 sec?


1) I'm affraid not quite following your development considering that the goal is to get a "silent MsgBox"
if this is correct, calling the "keybd_event" api (pre & post a MsgBox) seems is doing the thrick (?)
(disregarding if msgbox is launched "alone" or vbInformation(ed) or with some other icon)

in this case, I guess that (possible) questions a

a) how to be sure that volume is (un)muted prior to call the api ?
b) how to be sure that "default beep" is (not) assigned to a "not so short" sound file ?

so (I guess), we have to use something like Ivan' approach mentioned in the previous thread link (?)

2) I'm sure that doing a deeper R&D we can find the answers to your questions (and maybe others "in the way")
however, using recursive calls to sleep makes mi think that you expect a bahaviour like sendkeys method
while a vb/a code comunicates with other devices (?), so...

adding some MsgBox(es) after each sleep call let's you see (in taskbar) the mute icon toggling
(un)comment these new lines to compare the differences, and my tests over doit3() are as follows:

Sub doit3()

Dim sc As Currency, ec As Currency, freq As Currency

' seems to fail to toggle volume off, then on.
' produces sound if speaker unmuted initially
MsgBox "mute or unmute speaker volume", vbInformation
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
'MsgBox "was the volume mute toggled ?"

QueryPerformanceCounter sc
sndPlaySound "Default Beep", 0
QueryPerformanceCounter ec
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
'MsgBox "was the volume mute toggled ?"

' suprise!
' leaves speaker muted if unmuted initially,
' or unmuted if muted initially.
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
'MsgBox "was the volume mute toggled ?"

QueryPerformanceFrequency freq
MsgBox "sndPlaySound duration: " & _
Format((ec - sc) / freq * 1000, "0 ""msec"""), _
vbInformation
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
'MsgBox "was the volume mute toggled ?"

End Sub

hth,
hector.

__ snip(ped) OP __
Let me be clear....

Try each macro below. Each macro gives you the opportunity to mute orunmute the speaker initially.
Normally, I unmute it initially. And remember to associate Windows XP Startup.wav
or the equivalent on your computer with the "Default Beep" sound.

Why the difference in behavior between doit1() and doit2()?

That is, why does "Mute VK_VOLUME_MUTE,0,1,0" seem to fail to toggle the volume off, then on around the sndPlaySound call
whereas it does just that around the Msgbox call?

Moreover, in doit3(), why does the second pair of Mute calls, around the last Msgbox call
leave the mute state set to the opposite of the initial mute state?

Caveat: I have executed doit3() dozens of times, and it had consistently misbehaved per my last question.
But in the last 10 executions just now, doit3() behaved "as expected" 2 or 3 times.
That is, it seemingly failed to toggle mute around the sndPlaySound, a misbehavior that we expect based on doit2()
but it did correctly toggle mute around the second Msgbox call
which is only a surprise because of the misbehavior that I have observed dozens of times.

So the last problem exhibited by doit3() might not be as consistent I first thought.
If you cannot duplicate the misbehaviors, I suggest that you try 2 or 3 more times.

Design notes:

1. Yes, the second pair of Mute calls in doit3() are superfluous, since I use Msgbox vbInformation
which does not play "Default Beep" sound.
I left them there only because they demonstrate an anomalous behavior namely my last question above.

2. I put some delay (Sleep 1000) after each Mute call for two reasons.
First, just in case the Mute operation is asynchronous. (I don't think it is.)
Second, to permit us to see a change of state reflected in the speaker icon on the desktop toolbar, if you display it.
A 1-sec delay is enough time to accomplish both goals, especially the second one.

Public Declare Sub Sleep Lib "kernel32" (ByVal msec As Long)
Public Declare Function QueryPerformanceFrequency Lib _
"kernel32" (ByRef freq As Currency) As Boolean
Public Declare Function QueryPerformanceCounter Lib _
"kernel32" (ByRef cnt As Currency) As Boolean

Public Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Public Const VK_VOLUME_MUTE = &HAD

Public Declare Sub Mute Lib "user32" Alias "keybd_event" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

Sub doit1()
' toggles mute off, then on as expected.
' no sound if speaker unmuted initially
MsgBox "mute or unmute speaker volume", vbInformation
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
MsgBox "press Enter"
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
End Sub

Sub doit2()
' seems to fail to toggle mute off, then on.
' produces sound if speaker unmuted initially
MsgBox "mute or unmute speaker volume", vbInformation
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
sndPlaySound "Default Beep", 0
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
End Sub

Sub doit3()
Dim sc As Currency, ec As Currency, freq As Currency
' seems to fail to toggle volume off, then on.
' produces sound if speaker unmuted initially
MsgBox "mute or unmute speaker volume", vbInformation
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
QueryPerformanceCounter sc
sndPlaySound "Default Beep", 0
QueryPerformanceCounter ec
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
' suprise!
' leaves speaker muted if unmuted initially,
' or unmuted if muted initially.
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
QueryPerformanceFrequency freq
MsgBox "sndPlaySound duration: " & _
Format((ec - sc) / freq * 1000, "0 msec"), _
vbInformation
Mute VK_VOLUME_MUTE, 0, 1, 0
Sleep 1000
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With A Spreadsheet for a silent auction Ken P Excel Worksheet Functions 1 April 12th 10 09:09 AM
MsgBox help James C. Excel Programming 2 March 18th 08 09:23 PM
form to enter Silent Auction data? suezquesteen Excel Discussion (Misc queries) 0 August 5th 05 04:41 PM
running Word/Excel in silent mode with Office XP PIAs Peter Torr \(MS\) Excel Programming 0 November 13th 03 11:08 PM
Silent running Stewart[_2_] Excel Programming 1 August 30th 03 05:47 AM


All times are GMT +1. The time now is 06:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"