473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Create Custom Dialog like MessageBox

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

Nov 15 '05 #1
2 30103
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.Collections;
using System.ComponentModel;
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.ComponentModel.Container components = null;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}

private void btnQuit_Click(object sender, System.EventArgs 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("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBoxEx(
IntPtr hWnd,
[MarshalAs(UnmanagedType.LPTStr)]String Message,
[MarshalAs(UnmanagedType.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_ABORTRETRYIGNORE = 0x00000002;
public const UInt32 MB_YESNOCANCEL = 0x00000003;
public const UInt32 MB_YESNO = 0x00000004;
public const UInt32 MB_RETRYCANCEL = 0x00000005;
public const UInt32 MB_CANCELTRYCONTINUE = 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_ICONEXCLAMATION = 0x00000030;
public const UInt32 MB_ICONASTERISK = 0x00000040;
public const UInt32 MB_USERICON = 0x00000080;
public const UInt32 MB_ICONWARNING = MB_ICONEXCLAMATION;
public const UInt32 MB_ICONERROR = MB_ICONHAND;
public const UInt32 MB_ICONINFORMATION = 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_SETFOREGROUND = 0x00010000;
public const UInt32 MB_DEFAULT_DESKTOP_ONLY = 0x00020000;
public const UInt32 MB_SERVICE_NOTIFICATION_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_NOTIFICATION = 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(object sender, System.EventArgs e)
{
MBReturn Result; // Result of user input.

// Display a message box.
Result = (MBReturn)MessageBoxEx(this.Handle,
"Your message Here
"MessageBox Title Here",
MBButton.MB_CANCELTRYCONTINUE | MBButton.MB_HELP |
MBIcon.MB_ICONEXCLAMATION |
MBModal.MB_SYSTEMMODAL |
MBDefButton.MB_DEFBUTTON4 |
MBSpecial.MB_TOPMOST,
0);

// Determine a result.
switch (Result)
{
case MBReturn.IDCANCEL:
MessageBox.Show("Cancel");
break;
case MBReturn.IDTRYAGAIN:
MessageBox.Show("Try Again");
break;
case MBReturn.IDCONTINUE:
MessageBox.Show("Continue");
break;
default:
MessageBox.Show("?");
break;
}
}

private void frmMain_HelpRequested(object sender,
System.Windows.Forms.HelpEventArgs hlpevent)
{
// Display information about the help request.
MessageBox.Show("Here is your help message:\r\n" +
"\r\nSender: " + sender.ToString() +
"\r\nMouse Position: " + hlpevent.MousePos,
"Title
MessageBoxButtons.OK,
MessageBoxIcon.Information);

// Tell Windows that the help request was handled.
hlpevent.Handled = true;
}
}
}

"Dennis C. Drumm" <de*******@primacode.com> wrote in message
news:%2*****************@TK2MSFTNGP09.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

Nov 15 '05 #2

Hi Dennis,

I have added a reply to another posts of you in this group,
Please check if my reply was useful.
Thanks

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Dennis C. Drumm" <de*******@primacode.com>
| From: "Dennis C. Drumm" <de*******@primacode.com>
| Subject: Create Custom Dialog like MessageBox
| Date: Sat, 6 Sep 2003 04:33:31 -0400
| Lines: 20
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#X*************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: ipn36372-d67497.net-resource.net 216.204.76.41
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:182818
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| 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
|
|
|
|

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RobJUK66 | last post by:
have a 3rd party .Net dll that wraps a set of further unmanaged dll's. The ..Net DLL basically uses pinvoke to wrap the calls. The low level dlls provide an API to talk to a complex device which...
0
by: Chris Powell | last post by:
I am using Excel/Access 2000 and have two large Excel files (25,000 rows each) that I wish to create linked tables in Access rather than importing into Access. The two source Excel files change...
7
by: WindAndWaves | last post by:
Hi Gurus I am trying to make a custom message box with a dialog form. Here is how I would like to do it: 1- anywhere in the database, in any procedure, I call the function that opens a dialog...
5
by: Dennis C. Drumm | last post by:
I have a windows form configured as a fixed dialog I'm using as a custom MessageBox (has some additional buttons). How do I get it to play the standard windows sounds when envoked and can I insert...
4
by: ronenk | last post by:
I have this code to load an authentication form once my app is loaded. I want the authentication form to be closed if a user is authenticated successfully and to give the option to close app on his...
1
by: rn5a | last post by:
I have created a custom control button which when clicked displays a message in the JavaScript alert dialog. I could successfully compile the VB class file into a DLL & also could add it to the...
2
by: forest demon | last post by:
I need to be able to create an appender to direct output to a MessageBox. The API does not have a MessageBox appender like nLog does. What would be the easiest way to do this. The examples...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
9
by: Gord | last post by:
In VB6, a custom dialog can be easily created by adding a new form, adding whatever controls you like, sizing it as you like, adding code and then just loading/unloading it whenever you like....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.