//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Runtime.InteropServices;

namespace CommonHelpers {

//**************************************************************************************************
static partial class Win32_Console {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public const uint
   STD_OUTPUT_HANDLE    = unchecked((uint)-11),
   ERROR_INVALID_HANDLE = 6,
   SC_CLOSE             = 0xF060,
   MF_BYCOMMAND         = 0x0000;

public static readonly IntPtr
   INVALID_HANDLE_VALUE = (IntPtr)(-1);

//==================================================================================================

[StructLayout(LayoutKind.Sequential)]
public struct COORD
{
  public short X;
  public short Y;
}

[StructLayout(LayoutKind.Sequential)]
public struct SMALL_RECT
{
  public short Left;
  public short Top;
  public short Right;
  public short Bottom;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SCREEN_BUFFER_INFO
{
   public COORD      dwSize;
   public COORD      dwCursorPosition;
   public short      wAttributes;
   public SMALL_RECT srWindow;
   public COORD      dwMaximumWindowSize;
}

//==================================================================================================

[DllImport("Kernel32.dll",ExactSpelling=true,SetLastError=true)]
public static extern IntPtr GetStdHandle(uint uStdHandle);

[DllImport("Kernel32.dll",CharSet=CharSet.Unicode,SetLastError=true)]
public static extern bool GetConsoleScreenBufferInfo
(
   IntPtr hConsoleOutput,
   out CONSOLE_SCREEN_BUFFER_INFO consoleScreenBufferInfo
);

[DllImport("Kernel32.dll",CharSet=CharSet.Unicode,SetLastError=true)]
public static extern IntPtr GetConsoleWindow();

//--------------------------------------------------------------------------------------------------

[DllImport("User32.dll",CharSet=CharSet.Unicode,SetLastError=true)]
public static extern bool CharToOemBuff([HIn] char[] achSrc,[HOut] byte[] abyDst,uint uDstLength);

[DllImport("User32.dll",CharSet=CharSet.Unicode,SetLastError=true)]
public static extern bool OemToCharBuff([HIn] byte[] abySrc,[HOut] char[] achDst,uint uDstLength);

[DllImport("User32.dll",ExactSpelling=true,SetLastError=true)]
public static extern IntPtr GetSystemMenu(IntPtr hWnd,bool bRevert);

[DllImport("User32.dll",ExactSpelling=true,SetLastError=true)]
public static extern bool DeleteMenu(IntPtr hMenu,uint uPosition,uint uFlags);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // Win32_Console
//**************************************************************************************************

} // CommonHelpers
