473,372 Members | 861 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,372 software developers and data experts.

System Modal Message Boxes

Hi,

I am wondering why the .NET Framework is quite different from Win32 API when
it comes to displaying system modal message boxes.

Consider the four following types of system modal message boxes (please see
associated source code below):
1) Win32 API with context ("btnWin32WithContext_Click")
2) .NET Framework with context ("btnFrameworkWithContext_Click")
3) Win32 API withOUT context ("btnWin32WithOUTContext_Click")
4) .NET Framework withOUT context ("btnFrameworkWithOUTContext_Click")

Message box (1) will display on the same screen as the caller.
Message box (2) will throw an exception.
Message box (3) will display on the same screen as the caller.
Message box (4) will NOT display on the same screen as the caller.

I would like to use the .NET Framework to display a system modal message box
on the same screen as the caller. Any ideas why this doesn't work in (2) or
(4)?

Thanks,
Nate

>>>>

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace DifferentTypesOfSystemModalMessageBoxes
{
public partial class Form1 : Form
{
/// <summary>
/// Standard Windows point
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
/// <summary>
/// x
/// </summary>
public long x;
/// <summary>
/// y
/// </summary>
public long y;
};

/// <summary>
/// From winuser.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct HELPINFO
{
/// <summary>
///
/// </summary>
public uint cbSize;
/// <summary>
///
/// </summary>
public int iContextType;
/// <summary>
///
/// </summary>
public int iCtrlId;
/// <summary>
///
/// </summary>
public IntPtr hItemHandle;
/// <summary>
///
/// </summary>
public IntPtr dwContextId;
/// <summary>
///
/// </summary>
public POINT MousePos;

/// <summary>
/// Unmarshal the helpinfo out of the given intptr, which is
presumably the lParam received
/// in a WM_HELP message.
/// </summary>
/// <param name="lParam"></param>
/// <returns></returns>
public static HELPINFO UnmarshalFrom(IntPtr lParam)
{
return (HELPINFO)Marshal.PtrToStructure(lParam,
typeof(HELPINFO));
}
};

/// <summary>
/// Delegate declaration for a callback that gets called when the
help button is pushed.
/// </summary>
public delegate void MsgBoxCallback(HELPINFO lpHelpInfo);

/// <summary>
/// From winuser.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct MSGBOXPARAMS
{
/// <summary>
///
/// </summary>
public uint cbSize;
/// <summary>
///
/// </summary>
public IntPtr hwndOwner;
/// <summary>
///
/// </summary>
public IntPtr hInstance;
/// <summary>
///
/// </summary>
public String lpszText;
/// <summary>
///
/// </summary>
public String lpszCaption;
/// <summary>
///
/// </summary>
public uint dwStyle;
/// <summary>
///
/// </summary>
public IntPtr lpszIcon;
/// <summary>
///
/// </summary>
public IntPtr dwContextHelpId;
/// <summary>
///
/// </summary>
public MsgBoxCallback lpfnMsgBoxCallback;
/// <summary>
///
/// </summary>
public uint dwLanguageId;
};

/// <summary>
/// The actual MessageBoxIndirect API declaration.
/// </summary>
/// <param name="msgboxParams"></param>
/// <returns></returns>
[DllImport("user32", EntryPoint = "MessageBoxIndirect")]
private static extern int _MessageBoxIndirect(ref MSGBOXPARAMS
msgboxParams);

public Form1()
{
InitializeComponent();
}

private void btnWin32WithContext_Click(object sender, EventArgs e)
{
MSGBOXPARAMS parms = new MSGBOXPARAMS();
parms.dwStyle = 0x00000000 | 0x00001000; // MB_OK |
MB_SYSTEMMODAL
parms.lpszText = "testing";
parms.lpszCaption = "test caption";
parms.hwndOwner = this.Handle; // Window context
parms.hInstance = IntPtr.Zero;
parms.cbSize = (uint)Marshal.SizeOf(typeof(MSGBOXPARAMS));
parms.lpszIcon = IntPtr.Zero;

DialogResult dr = (DialogResult)_MessageBoxIndirect(ref parms);
}

private void btnFrameworkWithContext_Click(object sender, EventArgs e)
{
MessageBox.Show(
this,
"testing",
"test caption",
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}

private void btnWin32WithOUTContext_Click(object sender, EventArgs e)
{
MSGBOXPARAMS parms = new MSGBOXPARAMS();
parms.dwStyle = 0x00000000 | 0x00001000; // MB_OK |
MB_SYSTEMMODAL
parms.lpszText = "testing";
parms.lpszCaption = "test caption";
parms.hwndOwner = IntPtr.Zero; // Window context
parms.hInstance = IntPtr.Zero;
parms.cbSize = (uint)Marshal.SizeOf(typeof(MSGBOXPARAMS));
parms.lpszIcon = IntPtr.Zero;

DialogResult dr = (DialogResult)_MessageBoxIndirect(ref parms);
}

private void btnFrameworkWithOUTContext_Click(object sender,
EventArgs e)
{
MessageBox.Show(
"testing",
"test caption",
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}
}
}
Jul 10 '07 #1
2 4472
Nathan,

Can you post a more complete example? You are missing all of the code
in InitializeComponent.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.comwrote in message
news:1E**********************************@microsof t.com...
Hi,

I am wondering why the .NET Framework is quite different from Win32 API
when
it comes to displaying system modal message boxes.

Consider the four following types of system modal message boxes (please
see
associated source code below):
1) Win32 API with context ("btnWin32WithContext_Click")
2) .NET Framework with context ("btnFrameworkWithContext_Click")
3) Win32 API withOUT context ("btnWin32WithOUTContext_Click")
4) .NET Framework withOUT context ("btnFrameworkWithOUTContext_Click")

Message box (1) will display on the same screen as the caller.
Message box (2) will throw an exception.
Message box (3) will display on the same screen as the caller.
Message box (4) will NOT display on the same screen as the caller.

I would like to use the .NET Framework to display a system modal message
box
on the same screen as the caller. Any ideas why this doesn't work in (2)
or
(4)?

Thanks,
Nate

>>>>>


using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace DifferentTypesOfSystemModalMessageBoxes
{
public partial class Form1 : Form
{
/// <summary>
/// Standard Windows point
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
/// <summary>
/// x
/// </summary>
public long x;
/// <summary>
/// y
/// </summary>
public long y;
};

/// <summary>
/// From winuser.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct HELPINFO
{
/// <summary>
///
/// </summary>
public uint cbSize;
/// <summary>
///
/// </summary>
public int iContextType;
/// <summary>
///
/// </summary>
public int iCtrlId;
/// <summary>
///
/// </summary>
public IntPtr hItemHandle;
/// <summary>
///
/// </summary>
public IntPtr dwContextId;
/// <summary>
///
/// </summary>
public POINT MousePos;

/// <summary>
/// Unmarshal the helpinfo out of the given intptr, which is
presumably the lParam received
/// in a WM_HELP message.
/// </summary>
/// <param name="lParam"></param>
/// <returns></returns>
public static HELPINFO UnmarshalFrom(IntPtr lParam)
{
return (HELPINFO)Marshal.PtrToStructure(lParam,
typeof(HELPINFO));
}
};

/// <summary>
/// Delegate declaration for a callback that gets called when the
help button is pushed.
/// </summary>
public delegate void MsgBoxCallback(HELPINFO lpHelpInfo);

/// <summary>
/// From winuser.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct MSGBOXPARAMS
{
/// <summary>
///
/// </summary>
public uint cbSize;
/// <summary>
///
/// </summary>
public IntPtr hwndOwner;
/// <summary>
///
/// </summary>
public IntPtr hInstance;
/// <summary>
///
/// </summary>
public String lpszText;
/// <summary>
///
/// </summary>
public String lpszCaption;
/// <summary>
///
/// </summary>
public uint dwStyle;
/// <summary>
///
/// </summary>
public IntPtr lpszIcon;
/// <summary>
///
/// </summary>
public IntPtr dwContextHelpId;
/// <summary>
///
/// </summary>
public MsgBoxCallback lpfnMsgBoxCallback;
/// <summary>
///
/// </summary>
public uint dwLanguageId;
};

/// <summary>
/// The actual MessageBoxIndirect API declaration.
/// </summary>
/// <param name="msgboxParams"></param>
/// <returns></returns>
[DllImport("user32", EntryPoint = "MessageBoxIndirect")]
private static extern int _MessageBoxIndirect(ref MSGBOXPARAMS
msgboxParams);

public Form1()
{
InitializeComponent();
}

private void btnWin32WithContext_Click(object sender, EventArgs e)
{
MSGBOXPARAMS parms = new MSGBOXPARAMS();
parms.dwStyle = 0x00000000 | 0x00001000; // MB_OK |
MB_SYSTEMMODAL
parms.lpszText = "testing";
parms.lpszCaption = "test caption";
parms.hwndOwner = this.Handle; // Window context
parms.hInstance = IntPtr.Zero;
parms.cbSize = (uint)Marshal.SizeOf(typeof(MSGBOXPARAMS));
parms.lpszIcon = IntPtr.Zero;

DialogResult dr = (DialogResult)_MessageBoxIndirect(ref parms);
}

private void btnFrameworkWithContext_Click(object sender, EventArgs
e)
{
MessageBox.Show(
this,
"testing",
"test caption",
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}

private void btnWin32WithOUTContext_Click(object sender, EventArgs
e)
{
MSGBOXPARAMS parms = new MSGBOXPARAMS();
parms.dwStyle = 0x00000000 | 0x00001000; // MB_OK |
MB_SYSTEMMODAL
parms.lpszText = "testing";
parms.lpszCaption = "test caption";
parms.hwndOwner = IntPtr.Zero; // Window context
parms.hInstance = IntPtr.Zero;
parms.cbSize = (uint)Marshal.SizeOf(typeof(MSGBOXPARAMS));
parms.lpszIcon = IntPtr.Zero;

DialogResult dr = (DialogResult)_MessageBoxIndirect(ref parms);
}

private void btnFrameworkWithOUTContext_Click(object sender,
EventArgs e)
{
MessageBox.Show(
"testing",
"test caption",
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}
}
}
Jul 10 '07 #2
Hi Nicholas,

The UI is just a simple form with four buttons. Here is the .resx file and
the designer generated source.

Thanks,
Nate

Form1.resx
>>>>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader,
System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter,
System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is
a comment</comment></data>
<data name="Color1" type="System.Drawing.Color,
System.Drawing">Blue</data>
<data name="Bitmap1"
mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing"
mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of
the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapF ormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0"
msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0"
msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"
msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string"
msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string"
msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0"
msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
>>>>
Form1.Designer.cs
>>>>
namespace DifferentTypesOfSystemModalMessageBoxes
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.grpWithWindowContext = new System.Windows.Forms.GroupBox();
this.lblInstructions = new System.Windows.Forms.Label();
this.btnWin32WithContext = new System.Windows.Forms.Button();
this.btnFrameworkWithContext = new System.Windows.Forms.Button();
this.grpWithoutWindowContext = new
System.Windows.Forms.GroupBox();
this.btnFrameworkWithOUTContext = new
System.Windows.Forms.Button();
this.btnWin32WithOUTContext = new System.Windows.Forms.Button();
this.grpWithWindowContext.SuspendLayout();
this.grpWithoutWindowContext.SuspendLayout();
this.SuspendLayout();
//
// grpWithWindowContext
//

this.grpWithWindowContext.Controls.Add(this.btnFra meworkWithContext);
this.grpWithWindowContext.Controls.Add(this.btnWin 32WithContext);
this.grpWithWindowContext.Location = new
System.Drawing.Point(12, 53);
this.grpWithWindowContext.Name = "grpWithWindowContext";
this.grpWithWindowContext.Size = new System.Drawing.Size(146, 80);
this.grpWithWindowContext.TabIndex = 0;
this.grpWithWindowContext.TabStop = false;
this.grpWithWindowContext.Text = "With Window Context";
//
// lblInstructions
//
this.lblInstructions.Location = new System.Drawing.Point(12, 9);
this.lblInstructions.Name = "lblInstructions";
this.lblInstructions.Size = new System.Drawing.Size(146, 41);
this.lblInstructions.TabIndex = 1;
this.lblInstructions.Text = "Click buttons to show system modal
message boxes with different options";
this.lblInstructions.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// btnWin32WithContext
//
this.btnWin32WithContext.Location = new System.Drawing.Point(6,
19);
this.btnWin32WithContext.Name = "btnWin32WithContext";
this.btnWin32WithContext.Size = new System.Drawing.Size(134, 23);
this.btnWin32WithContext.TabIndex = 2;
this.btnWin32WithContext.Text = "Win32 API";
this.btnWin32WithContext.UseVisualStyleBackColor = true;
this.btnWin32WithContext.Click += new
System.EventHandler(this.btnWin32WithContext_Click );
//
// btnFrameworkWithContext
//
this.btnFrameworkWithContext.Location = new
System.Drawing.Point(6, 48);
this.btnFrameworkWithContext.Name = "btnFrameworkWithContext";
this.btnFrameworkWithContext.Size = new System.Drawing.Size(134,
23);
this.btnFrameworkWithContext.TabIndex = 3;
this.btnFrameworkWithContext.Text = "Dot Net 2.0";
this.btnFrameworkWithContext.UseVisualStyleBackCol or = true;
this.btnFrameworkWithContext.Click += new
System.EventHandler(this.btnFrameworkWithContext_C lick);
//
// grpWithoutWindowContext
//

this.grpWithoutWindowContext.Controls.Add(this.btn FrameworkWithOUTContext);

this.grpWithoutWindowContext.Controls.Add(this.btn Win32WithOUTContext);
this.grpWithoutWindowContext.Location = new
System.Drawing.Point(12, 139);
this.grpWithoutWindowContext.Name = "grpWithoutWindowContext";
this.grpWithoutWindowContext.Size = new System.Drawing.Size(146,
80);
this.grpWithoutWindowContext.TabIndex = 2;
this.grpWithoutWindowContext.TabStop = false;
this.grpWithoutWindowContext.Text = "Without Window Context";
//
// btnFrameworkWithOUTContext
//
this.btnFrameworkWithOUTContext.Location = new
System.Drawing.Point(6, 48);
this.btnFrameworkWithOUTContext.Name =
"btnFrameworkWithOUTContext";
this.btnFrameworkWithOUTContext.Size = new
System.Drawing.Size(134, 23);
this.btnFrameworkWithOUTContext.TabIndex = 3;
this.btnFrameworkWithOUTContext.Text = "Dot Net 2.0";
this.btnFrameworkWithOUTContext.UseVisualStyleBack Color = true;
this.btnFrameworkWithOUTContext.Click += new
System.EventHandler(this.btnFrameworkWithOUTContex t_Click);
//
// btnWin32WithOUTContext
//
this.btnWin32WithOUTContext.Location = new
System.Drawing.Point(6, 19);
this.btnWin32WithOUTContext.Name = "btnWin32WithOUTContext";
this.btnWin32WithOUTContext.Size = new System.Drawing.Size(134,
23);
this.btnWin32WithOUTContext.TabIndex = 2;
this.btnWin32WithOUTContext.Text = "Win32 API";
this.btnWin32WithOUTContext.UseVisualStyleBackColo r = true;
this.btnWin32WithOUTContext.Click += new
System.EventHandler(this.btnWin32WithOUTContext_Cl ick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(173, 232);
this.Controls.Add(this.grpWithoutWindowContext);
this.Controls.Add(this.lblInstructions);
this.Controls.Add(this.grpWithWindowContext);
this.Name = "Form1";
this.Text = "MessageBox";
this.grpWithWindowContext.ResumeLayout(false);
this.grpWithoutWindowContext.ResumeLayout(false);
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.GroupBox grpWithWindowContext;
private System.Windows.Forms.Button btnFrameworkWithContext;
private System.Windows.Forms.Button btnWin32WithContext;
private System.Windows.Forms.Label lblInstructions;
private System.Windows.Forms.GroupBox grpWithoutWindowContext;
private System.Windows.Forms.Button btnFrameworkWithOUTContext;
private System.Windows.Forms.Button btnWin32WithOUTContext;

}
}
>>>>
"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

Can you post a more complete example? You are missing all of the code
in InitializeComponent.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.comwrote in message
news:1E**********************************@microsof t.com...
Hi,

I am wondering why the .NET Framework is quite different from Win32 API
when
it comes to displaying system modal message boxes.

Consider the four following types of system modal message boxes (please
see
associated source code below):
1) Win32 API with context ("btnWin32WithContext_Click")
2) .NET Framework with context ("btnFrameworkWithContext_Click")
3) Win32 API withOUT context ("btnWin32WithOUTContext_Click")
4) .NET Framework withOUT context ("btnFrameworkWithOUTContext_Click")

Message box (1) will display on the same screen as the caller.
Message box (2) will throw an exception.
Message box (3) will display on the same screen as the caller.
Message box (4) will NOT display on the same screen as the caller.

I would like to use the .NET Framework to display a system modal message
box
on the same screen as the caller. Any ideas why this doesn't work in (2)
or
(4)?

Thanks,
Nate

>>>>

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace DifferentTypesOfSystemModalMessageBoxes
{
public partial class Form1 : Form
{
/// <summary>
/// Standard Windows point
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
/// <summary>
/// x
/// </summary>
public long x;
/// <summary>
/// y
/// </summary>
public long y;
};

/// <summary>
/// From winuser.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct HELPINFO
{
/// <summary>
///
/// </summary>
public uint cbSize;
/// <summary>
///
/// </summary>
public int iContextType;
/// <summary>
///
/// </summary>
public int iCtrlId;
/// <summary>
///
/// </summary>
public IntPtr hItemHandle;
/// <summary>
///
/// </summary>
public IntPtr dwContextId;
/// <summary>
///
/// </summary>
public POINT MousePos;

/// <summary>
/// Unmarshal the helpinfo out of the given intptr, which is
presumably the lParam received
/// in a WM_HELP message.
/// </summary>
/// <param name="lParam"></param>
/// <returns></returns>
public static HELPINFO UnmarshalFrom(IntPtr lParam)
{
return (HELPINFO)Marshal.PtrToStructure(lParam,
typeof(HELPINFO));
}
};

/// <summary>
/// Delegate declaration for a callback that gets called when the
help button is pushed.
/// </summary>
public delegate void MsgBoxCallback(HELPINFO lpHelpInfo);

/// <summary>
/// From winuser.h
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct MSGBOXPARAMS
{
/// <summary>
///
/// </summary>
public uint cbSize;
/// <summary>
///
/// </summary>
public IntPtr hwndOwner;
/// <summary>
///
/// </summary>
public IntPtr hInstance;
/// <summary>
///
/// </summary>
public String lpszText;
/// <summary>
///
/// </summary>
public String lpszCaption;
/// <summary>
///
/// </summary>
public uint dwStyle;
/// <summary>
///
/// </summary>
public IntPtr lpszIcon;
/// <summary>
///
/// </summary>
public IntPtr dwContextHelpId;
/// <summary>
///
/// </summary>
public MsgBoxCallback lpfnMsgBoxCallback;
/// <summary>
///
/// </summary>
public uint dwLanguageId;
};

/// <summary>
/// The actual MessageBoxIndirect API declaration.
/// </summary>
/// <param name="msgboxParams"></param>
/// <returns></returns>
[DllImport("user32", EntryPoint = "MessageBoxIndirect")]
private static extern int _MessageBoxIndirect(ref MSGBOXPARAMS
msgboxParams);

public Form1()
{
InitializeComponent();
}

private void btnWin32WithContext_Click(object sender, EventArgs e)
{
MSGBOXPARAMS parms = new MSGBOXPARAMS();
parms.dwStyle = 0x00000000 | 0x00001000; // MB_OK |
MB_SYSTEMMODAL
parms.lpszText = "testing";
parms.lpszCaption = "test caption";
parms.hwndOwner = this.Handle; // Window context
parms.hInstance = IntPtr.Zero;
parms.cbSize = (uint)Marshal.SizeOf(typeof(MSGBOXPARAMS));
parms.lpszIcon = IntPtr.Zero;

DialogResult dr = (DialogResult)_MessageBoxIndirect(ref parms);
}

private void btnFrameworkWithContext_Click(object sender, EventArgs
e)
{
MessageBox.Show(
this,
"testing",
"test caption",
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}

private void btnWin32WithOUTContext_Click(object sender, EventArgs
e)
{
MSGBOXPARAMS parms = new MSGBOXPARAMS();
parms.dwStyle = 0x00000000 | 0x00001000; // MB_OK |
MB_SYSTEMMODAL
parms.lpszText = "testing";
parms.lpszCaption = "test caption";
parms.hwndOwner = IntPtr.Zero; // Window context
parms.hInstance = IntPtr.Zero;
parms.cbSize = (uint)Marshal.SizeOf(typeof(MSGBOXPARAMS));
parms.lpszIcon = IntPtr.Zero;

DialogResult dr = (DialogResult)_MessageBoxIndirect(ref parms);
}

private void btnFrameworkWithOUTContext_Click(object sender,
EventArgs e)
{
MessageBox.Show(
"testing",
"test caption",
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}
}
}
Jul 10 '07 #3

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

Similar topics

3
by: Andrew Baker | last post by:
OK this has me perplexed, puzzled and bamboozled! I have a remoting service which I displayed a message box in. I then wondered what would happen if a client made a call to the service while the...
4
by: Brian Henry | last post by:
Hi, is there a way to get a form to post back to a modal dialog box when it was posted from a modal dialog to start with? here is the problem... I have a form with combo boxes and when you select...
0
by: Lee | last post by:
I wonder if there's any way around this. I open a window as a modal form, but I would like to have pop up message boxes appearing on top of this that are non modal (so the user can close...
5
by: Dmitry Akselrod | last post by:
Hi Everyone, I am working in VB.NET, Framework v.1.0. I have tons of forms in my application. I have a situation, where a form starts another form as a Modal Dialog. The Modal Dialog then...
4
by: Greg Smith | last post by:
I have a user who likes to keep my application minimized. He wants to have a pop up of some sort come up to tell him he needs to return to the application to take action. I have used both...
4
by: mpreston | last post by:
I'm following the example from the MSDN library on how to create modal dialog boxes in C#, but something isn't working properly. If I create a modal dialog box and show it using ShowDialog(), the...
24
malav123
by: malav123 | last post by:
Hi, I am using ajax toolkit's modal popup extender which contains few text boxes and two buttons on it... i want to put validation on some of text boxes but my problem is after...
3
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
5
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi all Have a couple of issues with the modal popup extender (asp.net 3.5, vb.net, visual studio 2008): I have created a user control (e-mail enquiry form) which is designed to accept text...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.