c - Windows 10 COMMON_LVB_UNDERSCORE 仅在我退出程序后生效
问题描述
我试图让 microemacs 做下划线。
行为是下划线在程序运行时不起作用,但在程序退出后出现下划线。
为什么会这样,有没有办法让它发挥作用?
演示这一点的示例代码是:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <windows.h>
#define SC_CHAR char
#define BG_GREY (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
HANDLE g_ConsOut; /* Handle to the console */
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; /* Console information */
void flagerr(const char * fmt)
{ printf(fmt, GetLastError());
}
int main(int argc, char * argv[])
{ HANDLE g_ConsIn = GetStdHandle( STD_INPUT_HANDLE );
if (g_ConsIn < 0) /* INVALID_HANDLE_VALUE */
flagerr("Piperr %d\n");
/* SetStdHandle( STD_INPUT_HANDLE, g_ConsIn ); */
if (0 == SetConsoleMode(g_ConsIn, ENABLE_WINDOW_INPUT))
flagerr("PipeC %d\n");
{ HANDLE g_ConsOut = GetStdHandle( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo( g_ConsOut, &csbiInfo );
SetConsoleTextAttribute(g_ConsOut, BG_GREY);
{ int len = csbiInfo.dwSize.X * csbiInfo.dwSize.Y;
COORD Coords;
Coords.Y = 0;
Coords.X = 0;
{//WORD attr = 0x70 | COMMON_LVB_UNDERSCORE; // black on white
WORD attr = BG_GREY | COMMON_LVB_UNDERSCORE; // black on white
WORD cuf[512];
int ix;
for (ix = 512; --ix >= 0; )
cuf[ix] = attr;
{ SC_CHAR * src = "The Rain in Spain";
SC_CHAR * blank = " ";
int sl = strlen(src);
unsigned long n_out;
FillConsoleOutputAttribute( g_ConsOut, BG_GREY, len, Coords, &n_out );
FillConsoleOutputCharacter( g_ConsOut, ' ', len, Coords, &n_out );
Coords.Y = 0;
SetConsoleCursorPosition( g_ConsOut, Coords);
printf("BG_GREY %x US %x A %x\n", BG_GREY, COMMON_LVB_UNDERSCORE, attr);
_getch();
Coords.Y = 1;
WriteConsoleOutputCharacter( g_ConsOut, blank, strlen(blank), Coords, &n_out );
WriteConsoleOutputAttribute( g_ConsOut, cuf, sl, Coords, &n_out );
WriteConsoleOutputCharacter( g_ConsOut, src, sl, Coords, &n_out );
_getch();
return 0;
}}}}}
在 Visual Studio 2019 中
属性 > 高级 > 字符集 > 未设置
在节目中
退出程序后
操作系统名称:Microsoft Windows 10 Pro
操作系统版本:10.0.19041 不适用 内部版本 19041
解决方案
推荐阅读
- java - 如何从组合键中设置和获取值
- scala - Spark 驱动程序以代码 137 终止并且没有错误消息。原因是什么?
- javascript - 如何检查数组是否包含任何两个特定字符串
- angular - Angular 发布请求没有 req.user 信息
- java - 类中的方法不能应用于给定类型。必需:无参数
- typescript - 从 Select 选项的值中为按钮动态添加 routerlink
- dart - Dart:如何检查变量类型是否为字符串
- javascript - 当我使用实时服务器查看页面时显示图像,但是当我在浏览器中打开 html 文件时没有显示
- apache-spark - Spark sql 在 Json 数据上使用 Kafka 流式传输:函数 from_json 无法解析来自 kafka 主题的多行 json
- laravel - Coinpayment Laravel 集成。除以零异常