首页 > 解决方案 > 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

标签: cwindows

解决方案


推荐阅读