kaplan1
asked on
MessageBox() without a beep
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?
a message box with the MessageBox()
system call in such a way that it
does not cause a beep?
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
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
> I have used MessageBoxIndirect to do what you want to do (no beep).
Interesting! That really does get around it?
..B ekiM
Interesting! That really does get around it?
..B ekiM
I'll dig out and post the code shortly (its presently archived)
DarrinE
DarrinE
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.dwContext HelpId =
//lpMsgBoxParams.lpfnMsgBo xCallback = (MSGBOXCALLBACK) MsgBoxCallBack;
//lpMsgBoxParams.dwLanguag eId =
/*
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(&lpMsgB oxParams);
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
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
lpMsgBoxParams.dwStyle = MB_OKCANCEL |MB_USERICON ;
lpMsgBoxParams.lpszIcon = MAKEINTRESOURCE(IDI_ICON1)
//lpMsgBoxParams.dwContext
//lpMsgBoxParams.lpfnMsgBo
//lpMsgBoxParams.dwLanguag
/*
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(&lpMsgB
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
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks!
So, is it true that MessageBoxIndirect() really does skip the user's settings for sounds?
..B ekiM
..B ekiM
ASKER
Yes it works as long as you put
MB_USERICON for dwStyle.
MB_USERICON for dwStyle.
>>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
>>MB_USERICON for dwStyle.
Combine it with the standard flags - without it - the normal sounds come through
DarrinE
> 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
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