本文整理汇总了C#中COORD类的典型用法代码示例。如果您正苦于以下问题:C# COORD类的具体用法?C# COORD怎么用?C# COORD使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
COORD类属于命名空间,在下文中一共展示了COORD类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadConsoleOutput
static extern bool ReadConsoleOutput(
IntPtr hConsoleOutput,
[Out] CHAR_INFO[,] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCoord,
ref SMALL_RECT lpReadRegion
);
示例2: ColorConsole
// Constructor.
public ColorConsole()
{
ConsoleInfo = new CONSOLE_SCREEN_BUFFER_INFO();
ConsoleOutputLocation = new COORD();
hConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleHandle, ref ConsoleInfo);
OriginalColors = ConsoleInfo.wAttributes;
}
示例3: WriteConsoleOutput
public static extern bool WriteConsoleOutput(
IntPtr hConsoleOutput,
/* This pointer is treated as the origin of a two-dimensional array of CHAR_INFO structures
whose size is specified by the dwBufferSize parameter.*/
[MarshalAs(UnmanagedType.LPArray), In] CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCoord,
ref SMALL_RECT lpWriteRegion);
示例4: InitConsole
public static bool InitConsole()
{
if (Application.platform != RuntimePlatform.WindowsPlayer)
return false;
AllocConsole();
SetConsoleCtrlHandler(null, true);
StdOutHandle = GetStdHandle(unchecked((uint)STD_OUTPUT_HANDLE));
StdInHandle = GetStdHandle(unchecked((uint)STD_INPUT_HANDLE));
// 允许控制台右键菜单
uint dwConsoleMode = 0;
GetConsoleMode(StdInHandle, out dwConsoleMode);
SetConsoleMode(StdInHandle, ~ENABLE_MOUSE_INPUT & dwConsoleMode);
// forbid close
IntPtr hWnd = GetConsoleWindow();
IntPtr hMenu = GetSystemMenu(hWnd, 0);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
COORD BufferSize = new COORD()
{
X = 120,
Y = 320,
};
SMALL_RECT WinRect = new SMALL_RECT()
{
Left = 0,
Top = 0,
Right = (short)(BufferSize.X - 1),
Bottom = 30,
};
IntPtr pBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(BufferSize));
Marshal.StructureToPtr(BufferSize, pBuffer, false);
Debug.Log(SetConsoleScreenBufferSize(StdOutHandle, pBuffer));
Marshal.FreeHGlobal(pBuffer);
IntPtr pWinRect = Marshal.AllocHGlobal(Marshal.SizeOf(WinRect));
Marshal.StructureToPtr(WinRect, pWinRect, false);
Debug.Log(SetConsoleWindowInfo(StdOutHandle, true, pWinRect));
Marshal.FreeHGlobal(pWinRect);
ConsoleAlive = true;
Thread th = new Thread(new ThreadStart(WorkingThread));
th.Start();
return true;
}
示例5: ReadFromBuffer
public static IEnumerable<string> ReadFromBuffer(short x, short y, short width, short height)
{
IntPtr buffer = Marshal.AllocHGlobal(width * height * Marshal.SizeOf(typeof(CHAR_INFO)));
if (buffer == null)
throw new OutOfMemoryException();
try
{
COORD coord = new COORD();
SMALL_RECT rc = new SMALL_RECT();
rc.Left = x;
rc.Top = y;
rc.Right = (short)(x + width - 1);
rc.Bottom = (short)(y + height - 1);
COORD size = new COORD();
size.X = width;
size.Y = height;
const int STD_OUTPUT_HANDLE = -11;
if (!ReadConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE), buffer, size, coord, ref rc))
{
// 'Not enough storage is available to process this command' may be raised for buffer size > 64K (see ReadConsoleOutput doc.)
throw new Win32Exception(Marshal.GetLastWin32Error());
}
IntPtr ptr = buffer;
for (int h = 0; h < height; h++)
{
StringBuilder sb = new StringBuilder();
for (int w = 0; w < width; w++)
{
CHAR_INFO ci = (CHAR_INFO)Marshal.PtrToStructure(ptr, typeof(CHAR_INFO));
char[] chars = Console.OutputEncoding.GetChars(ci.charData);
sb.Append(chars[0]);
ptr += Marshal.SizeOf(typeof(CHAR_INFO));
}
yield return sb.ToString();
}
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
示例6: readvalue
public string readvalue(ref System.IntPtr ptr, short a)
{
SMALL_RECT srctReadRect = new SMALL_RECT
{
Top = 0,
Left = 0,
Bottom = 1,
Right = 80
};
CHAR_INFO[,] chiBuffer = new CHAR_INFO[2, 80]; // [2][80];10 lines, with 50 characters
COORD coordBufSize = new COORD
{
X = 80,
Y = 2
};
COORD coordBufCoord = new COORD
{
X = 0,
Y = 0
};
bool fSuccess;
int i = 0;
int j = 0;
string chartostring = "start";
string previousstring = "";
short g = a;
short h = (short)(g + 1);
srctReadRect.Top = g;
srctReadRect.Bottom = h;
int count = 0;
//System.Console.WriteLine(g + "." + h);
while (count < 1)//Hunting:if it find 1 empty rows with text then it will stop reading
{
previousstring = chartostring;
srctReadRect.Top = g;
srctReadRect.Bottom = h;
fSuccess = ReadConsoleOutput(ptr, chiBuffer, coordBufSize, coordBufCoord, ref srctReadRect);
i = 0;
j = 0;
chartostring = "";
while (j < coordBufSize.Y)
{
while (i < coordBufSize.X)
{
if (chiBuffer[j, i].UnicodeChar != 0 && chiBuffer[j, i].UnicodeChar != 32)
chartostring += chiBuffer[j, i].UnicodeChar;
i++;
}
i = 0;
j++;
}
if (chartostring.Length == 0)//The character length is zero, reverse the top of the source rect
{
count++;
}
else
{
count = 0;
}
g += 1;
h += 1;
}
return previousstring;
}
示例7: SetConsoleScreenBufferSize
internal static extern bool SetConsoleScreenBufferSize(IntPtr hConsoleOutput, COORD size);
示例8: SetConsoleCursorPosition
public static extern bool SetConsoleCursorPosition(
IntPtr hConsoleOutput,
COORD dwCursorPosition
);
示例9: ConvertLineAndColumnToOffset
private int ConvertLineAndColumnToOffset(COORD coord)
{
int offset;
int x = _initialX;
int y = _initialY + Options.ExtraPromptLineCount;
int bufferWidth = _console.BufferWidth;
var continuationPromptLength = Options.ContinuationPrompt.Length;
for (offset = 0; offset < _buffer.Length; offset++)
{
// If we are on the correct line, return when we find
// the correct column
if (coord.Y == y && coord.X <= x)
{
return offset;
}
char c = _buffer[offset];
if (c == '\n')
{
// If we are about to move off of the correct line,
// the line was shorter than the column we wanted so return.
if (coord.Y == y)
{
return offset;
}
y += 1;
x = continuationPromptLength;
}
else
{
int size = LengthInBufferCells(c);
x += size;
// Wrap? No prompt when wrapping
if (x >= bufferWidth)
{
int offsize = x - bufferWidth;
if (offsize % size == 0)
{
x -= bufferWidth;
}
else
{
x = size;
}
y += 1;
}
}
}
// Return -1 if y is out of range, otherwise the last line was shorter
// than we wanted, but still in range so just return the last offset.
return (coord.Y == y) ? offset : -1;
}
示例10: WriteConsoleOutput
internal static unsafe extern bool WriteConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
示例11: FillConsoleOutputCharacter
private static extern int FillConsoleOutputCharacter(int hConsoleOutput, byte cCharacter, int nLength, COORD dwWriteCoord, ref int lpNumberOfCharsWritten);
示例12: ReadConsoleOutputAttribute
public static extern bool ReadConsoleOutputAttribute(
IntPtr hConsoleOutput,
[Out] ushort[] lpAttribute,
uint nLength,
COORD dwReadCoord,
out uint lpNumberOfAttrsRead
);
示例13: SetConsoleCursorPosition
internal static extern bool SetConsoleCursorPosition(IntPtr hConsoleOutput,
COORD cursorPosition);
示例14: WriteConsoleOutputAttribute
public static extern bool WriteConsoleOutputAttribute(
IntPtr hConsoleOutput,
ushort[] lpAttribute,
uint nLength,
COORD dwWriteCoord,
out uint lpNumberOfAttrsWritten
);
示例15: WriteConsoleOutputCharacter
public static extern bool WriteConsoleOutputCharacter(
IntPtr hConsoleOutput,
string lpCharacter,
uint nLength,
COORD dwWriteCoord,
out uint lpNumberOfCharsWritten
);