[仅使用ASCII字符时,所有字符和给定的颜色值都会正确显示,但是,每当我使用扩展ASCII或UNICODE字符时,都会收到此错误消息(并且我的g ++编译器指示问题是非ASCII字符:] >
warning: multi-character character constant [-Wmultichar] error: narrowing conversion of '14849683' from 'int' to 'WCHAR' {aka 'wchar_t'} inside { } [-Wnarrowing]
我在编译命令中使用
-lgdi32
参数。
我使用WriteConsoleOutputA
还是WriteConsoleOutputW
似乎都没有区别。
我相信默认情况下CHAR_INFO数组字符宽度为8bit,所以我认为应该对此进行更改,但是我在Windows Console API文档中找不到关于它的任何内容。
为清楚起见,所有的#个字符都显示正确,但是如果我使用的字符如:░或┐,则会收到上述错误消息。
CHAR_INFO map[400] = {
'#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C,'#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', 0x002C,
'#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C,'#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C, '#', 0x002C
};
COORD coordinateBufferSize;
coordinateBufferSize.Y = 10;
coordinateBufferSize.X = 10;
COORD topLeftCoordinate;
topLeftCoordinate.Y = 0;
topLeftCoordinate.X = 0;
PSMALL_RECT srcWriteRect;
srcWriteRect->Top = 10; // Number of rows to the top
srcWriteRect->Left = 10; // Numbers of columns to the side
srcWriteRect->Bottom = 19;
srcWriteRect->Right = 19;
HANDLE oldScreenBuffer, newScreenBuffer;
oldScreenBuffer = GetStdHandle(STD_OUTPUT_HANDLE);
newScreenBuffer = CreateConsoleScreenBuffer(
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL);
BOOL succes = WriteConsoleOutputA(
newScreenBuffer, // The new ScreenBuffer
map, // The char array we want to display
coordinateBufferSize, //
topLeftCoordinate,
srcWriteRect
);
SetConsoleActiveScreenBuffer(newScreenBuffer);
[仅使用ASCII字符时,所有字符和给定的颜色值都会正确显示,但是,每当我使用扩展ASCII或UNICODE字符时,都会收到此错误消息(和我的g ++ ...
您应使用WriteConsoleOutputW
。 CHAR_INFO类型是属性的结构(在您的情况下为颜色),并且是字符和宽字符的结合,因此这里没有问题。