Here is the crux of the class. You can change the implementation but it
should give you a good idea of how to handle it. Good call on getting
Mueller's book...it's a masterpiece.
Good Luck,
Bill
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Runtime. InteropServices ;
using System.Windows. Forms;
namespace ShowMessage
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows. Forms.Form
{
private System.Windows. Forms.Button btnQuit;
private System.Windows. Forms.Button btnTest;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new frmMain());
}
private void btnQuit_Click(o bject sender, System.EventArg s e)
{
// Exit the application.
Close();
}
// MessageBoxEx() provides features, including a language identifier,
// not found in the .NET Framework version. This function also enables
// you to add special buttons and other features to the message box.
[DllImport("user 32.dll", CharSet=CharSet .Auto)]
public static extern int MessageBoxEx(
IntPtr hWnd,
[MarshalAs(Unman agedType.LPTStr )]String Message,
[MarshalAs(Unman agedType.LPTStr )]String Header,
UInt32 Type,
UInt16 LanguageID);
// Create a list of buttons.
public class MBButton
{
public const UInt32 MB_OK = 0x00000000;
public const UInt32 MB_OKCANCEL = 0x00000001;
public const UInt32 MB_ABORTRETRYIG NORE = 0x00000002;
public const UInt32 MB_YESNOCANCEL = 0x00000003;
public const UInt32 MB_YESNO = 0x00000004;
public const UInt32 MB_RETRYCANCEL = 0x00000005;
public const UInt32 MB_CANCELTRYCON TINUE = 0x00000006;
public const UInt32 MB_HELP = 0x00004000;
}
// Create a list of icon types.
public class MBIcon
{
public const UInt32 MB_ICONHAND = 0x00000010;
public const UInt32 MB_ICONQUESTION = 0x00000020;
public const UInt32 MB_ICONEXCLAMAT ION = 0x00000030;
public const UInt32 MB_ICONASTERISK = 0x00000040;
public const UInt32 MB_USERICON = 0x00000080;
public const UInt32 MB_ICONWARNING = MB_ICONEXCLAMAT ION;
public const UInt32 MB_ICONERROR = MB_ICONHAND;
public const UInt32 MB_ICONINFORMAT ION = MB_ICONASTERISK ;
public const UInt32 MB_ICONSTOP = MB_ICONHAND;
}
// Create a list of default buttons.
public class MBDefButton
{
public const UInt32 MB_DEFBUTTON1 = 0x00000000;
public const UInt32 MB_DEFBUTTON2 = 0x00000100;
public const UInt32 MB_DEFBUTTON3 = 0x00000200;
public const UInt32 MB_DEFBUTTON4 = 0x00000300;
}
// Create a list of message box modalities.
public class MBModal
{
public const UInt32 MB_APPLMODAL = 0x00000000;
public const UInt32 MB_SYSTEMMODAL = 0x00001000;
public const UInt32 MB_TASKMODAL = 0x00002000;
}
// Create a list of special message box attributes.
public class MBSpecial
{
public const UInt32 MB_SETFOREGROUN D = 0x00010000;
public const UInt32 MB_DEFAULT_DESK TOP_ONLY = 0x00020000;
public const UInt32 MB_SERVICE_NOTI FICATION_NT3X = 0x00040000;
public const UInt32 MB_TOPMOST = 0x00040000;
public const UInt32 MB_RIGHT = 0x00080000;
public const UInt32 MB_RTLREADING = 0x00100000;
public const UInt32 MB_SERVICE_NOTI FICATION = 0x00200000;
}
// Return values can use an enum in place of a class.
public enum MBReturn
{
IDOK = 1,
IDCANCEL = 2,
IDABORT = 3,
IDRETRY = 4,
IDIGNORE = 5,
IDYES = 6,
IDNO = 7,
IDCLOSE = 8,
IDHELP = 9,
IDTRYAGAIN = 10,
IDCONTINUE = 11,
IDTIMEOUT = 32000
}
private void btnTest_Click(o bject sender, System.EventArg s e)
{
MBReturn Result; // Result of user input.
// Display a message box.
Result = (MBReturn)Messa geBoxEx(this.Ha ndle,
"Your message Here
"MessageBox Title Here",
MBButton.MB_CAN CELTRYCONTINUE | MBButton.MB_HEL P |
MBIcon.MB_ICONE XCLAMATION |
MBModal.MB_SYST EMMODAL |
MBDefButton.MB_ DEFBUTTON4 |
MBSpecial.MB_TO PMOST,
0);
// Determine a result.
switch (Result)
{
case MBReturn.IDCANC EL:
MessageBox.Show ("Cancel");
break;
case MBReturn.IDTRYA GAIN:
MessageBox.Show ("Try Again");
break;
case MBReturn.IDCONT INUE:
MessageBox.Show ("Continue") ;
break;
default:
MessageBox.Show ("?");
break;
}
}
private void frmMain_HelpReq uested(object sender,
System.Windows. Forms.HelpEvent Args hlpevent)
{
// Display information about the help request.
MessageBox.Show ("Here is your help message:\r\n" +
"\r\nSender : " + sender.ToString () +
"\r\nMouse Position: " + hlpevent.MouseP os,
"Title
MessageBoxButto ns.OK,
MessageBoxIcon. Information);
// Tell Windows that the help request was handled.
hlpevent.Handle d = true;
}
}
}
"Dennis C. Drumm" <de*******@prim acode.com> wrote in message
news:%2******** *********@TK2MS FTNGP09.phx.gbl ...
This is a restatement of an earlier post that evidently wasn't clear. I am
building a custom MessageBox dialog that has, among other things, a few
new button options (yes to all, no to all, etc.) and would like to make the
dialog look and act like the standard MessageBox. Therefore, I would like
to put in the message section the same type of icons found in the MessageBox
dialog, such as MessageBoxIcon. Exclamation. In another post here I had
asked about firing of sounds and it was suggested that I look at the book .NET
Framework Solutions, In Search of the Lost Win32 API by John Paul Meuller
for more information on rolling your own message dialogs. I have ordered
that book and it will be here in about a week. In the meantime, I thought
I would ask you guys how to put one of the standard MessageBox icons, such
as the exclamation icon, into my custom MessageBox dialog. Can someone tell
how that can be done?
Thanks,
Dennis