Skip to content

Instantly share code, notes, and snippets.

@CycloneRing
Created April 7, 2024 05:08
Show Gist options
  • Save CycloneRing/f68da85ecbf1bb2ad5ac33d7dc428d8a to your computer and use it in GitHub Desktop.
Save CycloneRing/f68da85ecbf1bb2ad5ac33d7dc428d8a to your computer and use it in GitHub Desktop.
MessageBoxFlagDemo
using System;
namespace MessageBoxFlagDemo
{
class Program
{
public static class MBFlags
{
// Message Icon
public const uint MB_ICONINFORMATION = 0x00000040;
public const uint MB_ICONWARNING = 0x00000030;
public const uint MB_ICONERROR = 0x00000010;
public const uint MB_ICONQUESTION = 0x00000020;
// Message Type
public const uint MB_OK = 0x00000000;
public const uint MB_OKCANCEL = 0x00000001;
public const uint MB_ABORTRETRYIGNORE = 0x00000002;
public const uint MB_YESNOCANCEL = 0x00000003;
public const uint MB_YESNO = 0x00000004;
public const uint MB_RETRYCANCEL = 0x00000005;
// Message Commands
public const int IDOK = 1;
public const int IDCANCEL = 2;
public const int IDABORT = 3;
public const int IDRETRY = 4;
public const int IDIGNORE = 5;
public const int IDYES = 6;
public const int IDNO = 7;
public const int IDCLOSE = 8;
public const int IDHELP = 9;
public const int IDTRYAGAIN = 10;
public const int IDCONTINUE = 11;
}
static void FindMessageIcon(uint msgFlags)
{
// Process Icon
if ((msgFlags & MBFlags.MB_ICONINFORMATION) != 0) { Console.WriteLine("Message Icon Is Information"); return; }
if ((msgFlags & MBFlags.MB_ICONWARNING) != 0) { Console.WriteLine("Message Icon Is Warning"); return; }
if ((msgFlags & MBFlags.MB_ICONERROR) != 0) { Console.WriteLine("Message Icon Is Error"); return; }
if ((msgFlags & MBFlags.MB_ICONQUESTION) != 0) { Console.WriteLine("Message Icon Is Question"); return; }
Console.WriteLine("Message Has No Icon");
}
static void FindMessageType(uint msgFlags)
{
if ((msgFlags & MBFlags.MB_OKCANCEL) != 0) { Console.WriteLine("Message Type Is Ok Cancel"); return; }
if ((msgFlags & MBFlags.MB_ABORTRETRYIGNORE) != 0) { Console.WriteLine("Message Type Is Abort Retry Ignore"); return; }
if ((msgFlags & MBFlags.MB_YESNOCANCEL) != 0) { Console.WriteLine("Message Type Is Yes No Cancel"); return; }
if ((msgFlags & MBFlags.MB_YESNO) != 0) { Console.WriteLine("Message Type Is Yes No"); return; }
if ((msgFlags & MBFlags.MB_RETRYCANCEL) != 0) { Console.WriteLine("Message Type Is Retry Cancel"); return; }
Console.WriteLine("Message Type Is Default");
}
static void Main(string[] args)
{
uint messageFlags = MBFlags.MB_ICONERROR | MBFlags.MB_ABORTRETRYIGNORE;
FindMessageIcon(messageFlags);
FindMessageType(messageFlags);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment