Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MessageBox() without a beep

Posted on 2000-02-25
12
Medium Priority
?
1,072 Views
Last Modified: 2013-12-03
Is there a way to bring up
a message box with the MessageBox()
system call in such a way that it
does not cause a beep?
0
Comment
Question by:kaplan1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 2560007
No.  If the user has a sound attached to the "Exclamation" or "Asterisk" event, the sound will play when a message box comes. It's the user's individual choice, and you should respect it.

Otherwise, you can't respect it, then you'll have to avoid the MessageBox() API. You can create your own popup window that shows your text and doesn't trigger any of the sound events on the system.

..B ekiM
0
 
LVL 2

Expert Comment

by:DarrinE
ID: 2560866
Not that I like disagreeing with mikeblas - I have used MessageBoxIndirect to do what you want to do (no beep).

By filling in the lpMsgBoxParams params you can substitute your own procedure (similar to a dlgproc) - you can remove the beep in the WM_INITDIALOG procedure by returning TRUE


int MessageBoxIndirect(
CONST LPMSGBOXPARAMS lpMsgBoxParams  // message box parameters
);

DarrinE
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2561105
> I have used MessageBoxIndirect to do what you want to do (no beep).

Interesting!  That really does get around it?

..B ekiM
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 2

Expert Comment

by:DarrinE
ID: 2561728
I'll dig out and post the code shortly (its presently archived)

DarrinE
0
 
LVL 2

Expert Comment

by:DarrinE
ID: 2564478
I was wrong about the callback - my memory did not serve me well - but alas I knew I had done it before so .... OK guys - this is how it is done


MSGBOXPARAMS lpMsgBoxParams;

lpMsgBoxParams.cbSize = sizeof(MSGBOXPARAMS);
lpMsgBoxParams.hwndOwner = hDlg;
lpMsgBoxParams.hInstance = hInstance;
lpMsgBoxParams.lpszText = "This is a message box created with the MessageBoxIndirect API";
lpMsgBoxParams.lpszCaption = "This is a MessageBox";
lpMsgBoxParams.dwStyle = MB_OKCANCEL |MB_USERICON ;
lpMsgBoxParams.lpszIcon = MAKEINTRESOURCE(IDI_ICON1);
//lpMsgBoxParams.dwContextHelpId =
//lpMsgBoxParams.lpfnMsgBoxCallback = (MSGBOXCALLBACK) MsgBoxCallBack;
//lpMsgBoxParams.dwLanguageId =

/*
  typedef struct {
  UINT      cbSize;
  HWND      hwndOwner;
  HINSTANCE hInstance;
  LPCTSTR   lpszText;
  LPCTSTR   lpszCaption;
  DWORD     dwStyle;
  LPCTSTR   lpszIcon;
  DWORD_PTR dwContextHelpId;
  MSGBOXCALLBACK lpfnMsgBoxCallback;
  DWORD     dwLanguageId;
} MSGBOXPARAMS, *PMSGBOXPARAMS;
*/
      MessageBoxIndirect(&lpMsgBoxParams);

I hope the code formats correctly here.

In the dwStyle parameter you must use the MB_USERICON flag with a standard flag - if you dont you get a beep. Using the MB_USERICON flag seems to remove the beep.

ie lpMsgBoxParams.dwStyle = MB_OKCANCEL |MB_USERICON ;


The lpszIcon parameter must be set to a user defined icon (in this instance IDI_ICON1).

The rest of the parmeters are well documented.

Is this what was wanted ??

If you want complete sample code to compile in VC++ 6 then give me the private email address and I'll send it to you.

DarrinE
0
 

Author Comment

by:kaplan1
ID: 2566220
The answer that DarrinE gave in
the form of a comment was awesome.
It worked like a charm.  I want
to give the points to him.

DarrinE - Post an answer just saying
you want the points and I will give
them to you.
0
 
LVL 2

Accepted Solution

by:
DarrinE earned 400 total points
ID: 2566290
I was wrong about the callback - my memory did not serve me well - but alas I knew I had done it before so .... OK guys - this is how it is done


MSGBOXPARAMS lpMsgBoxParams;

lpMsgBoxParams.cbSize = sizeof(MSGBOXPARAMS);
lpMsgBoxParams.hwndOwner = hDlg;
lpMsgBoxParams.hInstance = hInstance;
lpMsgBoxParams.lpszText = "This is a message box created with the MessageBoxIndirect API";
lpMsgBoxParams.lpszCaption = "This is a MessageBox";
lpMsgBoxParams.dwStyle = MB_OKCANCEL |MB_USERICON ;
lpMsgBoxParams.lpszIcon = MAKEINTRESOURCE(IDI_ICON1);
//lpMsgBoxParams.dwContextHelpId =
//lpMsgBoxParams.lpfnMsgBoxCallback = (MSGBOXCALLBACK) MsgBoxCallBack;
//lpMsgBoxParams.dwLanguageId =

/*
  typedef struct {
  UINT      cbSize;
  HWND      hwndOwner;
  HINSTANCE hInstance;
  LPCTSTR   lpszText;
  LPCTSTR   lpszCaption;
  DWORD     dwStyle;
  LPCTSTR   lpszIcon;
  DWORD_PTR dwContextHelpId;
  MSGBOXCALLBACK lpfnMsgBoxCallback;
  DWORD     dwLanguageId;
} MSGBOXPARAMS, *PMSGBOXPARAMS;
*/
      MessageBoxIndirect(&lpMsgBoxParams);

I hope the code formats correctly here.

In the dwStyle parameter you must use the MB_USERICON flag with a standard flag - if you dont you get a beep. Using the MB_USERICON flag seems to remove the beep.

ie lpMsgBoxParams.dwStyle = MB_OKCANCEL |MB_USERICON ;


The lpszIcon parameter must be set to a user defined icon (in this instance IDI_ICON1).

The rest of the parmeters are well documented.

Is this what was wanted ??

If you want complete sample code to compile in VC++ 6 then give me the private email address and I'll send it to you.

DarrinE
Reposted as requested (someone else might require the answer)
0
 

Author Comment

by:kaplan1
ID: 2566323
Thanks!
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2568402
So, is it true that MessageBoxIndirect() really does skip the user's settings for sounds?

..B ekiM
0
 

Author Comment

by:kaplan1
ID: 2570152
Yes it works as long as you put
MB_USERICON for dwStyle.


0
 
LVL 2

Expert Comment

by:DarrinE
ID: 2570453
>>Yes it works as long as you put
>>MB_USERICON for dwStyle.

Combine it with the standard flags - without it - the normal sounds come through

DarrinE




0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2572802

 > Yes it works as long as you put

Cool!

 > MB_USERICON for dwStyle.  

Looks like that works to silence a regular MessageBox() call, as well.

..B ekiM
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question