473,734 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 30160
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

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*******@prim acode.com>
| From: "Dennis C. Drumm" <de*******@prim acode.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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: ipn36372-d67497.net-resource.net 216.204.76.41
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1828 18
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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
445
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 appears as a USB hub (with a scanner, flash drive and some other bits and pieces). Using a VB.Net windows app, we call the main unmanaged API function (lets call it doStuff() ) and then call messagebox.show to pop up a modal results dialog. This...
0
8682
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 frequently, so I want to: A) prompt the user, using a custom form, for the specific Excel files to be linked; B) create the links dynamically; C) insert the linked tables into a select query grid and include the SQL statement in the VBA...
7
15264
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 form 2- users clicks on a button in the custom form 3- answer from user is passed back to original procedure (e.g. whether the answer was Yes or No).
5
7191
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 the standard MessageBox icons into this dialog? Thanks, Dennis
4
2716
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 decision. private void MainForm_Activated(object sender, EventArgs e) { AuthFrm StartUpfrm = new AuthFrm(); if (StartUpfrm.ShowDialog() == DialogResult.OK)
1
4808
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 Toolbox in Visual Web Developer 2005 Express Edition but the alert message isn't popping up when I am implementing this control in an ASP.NET page & clicking the Button in the ASPX page. This is the class file: Imports System Imports System.Web...
2
20037
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 supplied with the source are anything but helpful. Thanks for any input. -fd
11
5294
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 / dangerous? How can I force shutdown code within the dialog's Form.FormClosed event run? Zytan
9
5492
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. Using Access 07, a form is a little different beast and it would appear a custom dialog cannot be created in the same way. How does one go about creating a custom dialog? Note that I am not well experienced in programming but I have a couple of...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.