MessageBox (user32)
Last changed: -106.166.110.35

.
Summary
The MessageBox API(CHS:系统消息框API)

C# Signature:

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern MessageBoxResult MessageBox(IntPtr hWnd, String text, String caption, int options);

uint range:0~6

VB.NET Signature:

<DllImport("user32.dll", EntryPoint:="MessageBoxW", SetLastError:=True, Charset:=Charset.Unicode)> _
Public Function MessageBox(hwnd As IntPtr, _
      <MarshalAs(UnmanagedType.LPTSTR)> lpText As String, _
      <MarshalAs(UnmanagedType.LPTSTR)>lpCaption As String, _
      <MarshalAs(UnmanagedType.U4)>uType As MessageBoxOptions) As <MarshalAs(UnmanagedType.U4)>MessageBoxResult
End Function    

VB Signature:

Public Declare Function MessageBox Lib "user32.dll" Alias "MessageBoxA" _
         (ByVal prmlngWindowHandle As Long, _
          ByVal prmstrMessage As String, _
          ByVal prmstrCaption As String, _
          ByVal prmlngType As MessageBoxOptions) As MessageBoxResult

C++ Signature:

[DllImport("user32.DLL", EntryPoint="MessageBox", SetLastError=true, CharSet=CharSet::Auto, CallingConvention=CallingConvention::StdCall)]
MessageBoxResult MessageBox(IntPtr hWnd, String^ Text, String^ Caption, MessageBoxOptions Options);

User-Defined Types:

MessageBoxOptions, MessageBoxResult

Notes:

None.

Tips & Tricks:

Input something

Sample Code C#:

using System;
using System.Runtime.InteropServices;    

class Class1
{
    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    static extern int MessageBox(IntPtr hWnd, String text, String caption, int options);

    [STAThread]
    static void Main(string[] args)
    {
        MessageBox(IntPtr.Zero, "Text", "Caption", 0);
    }
}

Sample Code VB.NET:

Imports System;
Imports System.Runtime.InteropServices;    

Class Class1
     <DllImport("user32.dll", EntryPoint:="MessageBoxW", SetLastError:=True, Charset:=Charset.Unicode)> _
     Public Function MessageBox(hwnd As IntPtr, _
           <MarshalAs(UnmanagedType.LPTSTR)> lpText As String, _
           <MarshalAs(UnmanagedType.LPTSTR)>lpCaption As String, _
           <MarshalAs(UnmanagedType.U4)>uType As MessageBoxOptions) As <MarshalAs(UnmanagedType.U4)>MessageBoxResult
     End Function    

    <STAThread> _
    Public Sub Main()
        MessageBox(IntPtr.Zero, "Text", "Caption", MessageBoxOptions.Ok or MessageBoxOptions.IconWarning)
    End Sub
End Class

Sample Code VB:

Public Declare Function MessageBox Lib "user32.dll" Alias "MessageBoxA" _
         (ByVal prmlngWindowHandle As Long, _
          ByVal prmstrMessage As String, _
          ByVal prmstrCaption As String, _
          ByVal prmlngType As MessageBoxOptions) As MessageBoxResult

MessageBox(0, "Text", "Caption", MessageBoxOptions.Ok or MessageBoxOptions.IconWarning)

Sample Code C++:

MessageBox(IntPtr::Zero, "Text", "Caption", MessageBoxOptions::OkCancel | MessageBoxOptions::IconWarning);

Sample code for tiny c compler ( http://bellard.org/tcc/ ):

// compile with: tcc trial.c -luser32
// reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx

save as file trial.c:

#include <windows.h>
int main() {
    MessageBox(NULL, "Text", "Caption", 0);
    return 0;
}

contibuted by John Refling

Alternative Managed API:

System.Windows.Forms.MessageBox.Show

Documentation
MessageBox on MSDN