Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
For ValidationError, usually we use MessageBeep function.
But unfortunately MessageBeep is asynchronous (After queuing the sound, the MessageBeep function returns control to the calling function and plays the sound asynchronously.).

Where Beep function is synchronous (Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes.).

If you make a CEdit control validator for numerical chars with a MessageBeep function for ValidationError, and when the user still hitting the wrong key chars, so the sound won't play.
Beep is the preferred function in this situation.

Question: What is the equivalent Beep function Parameters (DWORD dwFreq and DWORD dwDuration) of this code:
C#
MessageBeep(0xFFFFFFFF); // A simple beep. If the sound card is not available, the sound is generated using the speaker.
Posted
Updated 19-Jan-19 3:10am
v4
Comments
Sergey Alexandrovich Kryukov 7-Jan-12 15:26pm    
What's wrong with asynchronous beep?
--SA
Mr. Tomay 7-Jan-12 18:20pm    
when the user still hitting the wrong key chars, so the sound won't play.
Albert Holguin 7-Jan-12 21:23pm    
Why don't you just listen to both and approximate the Beep() parameters by ear? If you get them close enough I'm sure a user wouldn't be able to distinguish them anyway. The whole point of beep is just to alert of an issue anyway so as long as it's clearly audible, that should be the important point.
Mr. Tomay 8-Jan-12 4:22am    
By ear, you're saying: That's difficult (The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF). ).
I am sure there is a way to reveal the secret of Microsoft (May be debugging MessageBeep(0xFFFFFFFF); function), I don't know!

I have debugged an MFC example with an edit control with Number Flag Checked, and make a break point on MessageBeep, so when I Enter some non numerical char keys, a call to the MessageBeep function is never invoked, but I hear a beep!!!

Hi,

From the trail I can't directly figure out if you're just not happy with the frequency of synchronous call and/or you can't get the async to work. If the latter is the case I suggest that you post the non working code.

Anyway what may be of interest for you is to check out a third option: PlaySound[^]

This may just work for you.

Cheers, AT
 
Share this answer
 
Comments
Mr. Tomay 12-Jan-12 14:59pm    
Awesome & very helpful
Thanks ;)
////////////////////Sound.h
#pragma once
class Sound
{
public:
Sound();
~Sound();
void MakeSound();
BOOL Quit = false;
BOOL mkSound = false;
};

////////////Sound.cpp
#include "stdafx.h"
#include "Sound.h"

UINT SoundThread(LPVOID pParam)
{
Sound * mSound = (Sound*)pParam;
while(!mSound->Quit)
{
if (mSound->mkSound)
{
Beep(400, 100);
mSound->mkSound = false;
}
}
ExitThread(0);
}
Sound::Sound()
{
AfxBeginThread(SoundThread, this);
}
void Sound::MakeSound()
{
mkSound = true;
}

Sound::~Sound()
{
Quit = true;
}


//////////////////main app
#include "Sound.h"
int main()
{
Sound mSound;

while(1)
{
mSound.MakeSound();
///do something useful
Sleep(500);
}
return 0;
}
 
Share this answer
 
Comments
Dave Kreskowiak 19-Jan-19 10:09am    
An unexplained, badly formatted code dump is not an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900