简体   繁体   English

随机像素出现在控制台窗口中

[英]Random pixels appearing in console window

I am writing a C Windows console application and strange pixels sometimes apper on the screen. 我正在编写一个C Windows控制台应用程序,屏幕上有时会出现奇怪的像素。

More specifically, the application writes and deletes characters in different colors on the screen, and sometimes it appears to not be able to delete them completely, instead leaving a single pixel behind. 更具体地说,应用程序在屏幕上写入和删除不同颜色的字符,有时它似乎无法完全删除它们,而是留下一个像素。

The function which I use exclusively to print is: 我专门用来打印的功能是:

STATIC
STATUS
PositionPrint(
    __in    COORD           tPosition,
    __in    WORD            wColorAttributes,
    __in    TCHAR           cChar
    )
{
    SNOWFLAKE__STATUS   eRetval         =   STATUS_INVALID;
    BOOL                bConsoleRetval  =   FALSE;

    bConsoleRetval = SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), tPosition);
    RETVAL_CHECK(
        bConsoleRetval,
        STATUS_SET_CONSOLE_CURSOR_POSITION_FAILED,
        "SetConsoleCursorPosition failed"
    );

    bConsoleRetval = SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColorAttributes);
    RETVAL_CHECK(
        bConsoleRetval,
        STATUS_SET_CONSOLE_TEXT_ATTRIBUTES_FAILED,
        "SetConsoleTextAttribute failed"
    );

    _tcprintf(_T("%c"), cChar);
lblCleanup:
    return eRetval;
}

The RETVAL_CHECK macro (just in case): RETVAL_CHECK宏(以防万一):

#ifdef _DEBUG
#define DEBUG_PRINT(message) (printf("%s %d %s %d %s\n", __FILE__, __LINE__, __FUNCTION__, GetLastError(), (message)))
#else
#define DEBUG_PRINT(message)
#endif

#define RETVAL_CHECK(_condition, _error, _message)   \
do                                                   \
{                                                    \
    if (!(_condition))                               \
    {                                                \
        eRetval = (_error);                          \
        DEBUG_PRINT(_message);                       \
        goto lblCleanup;                             \
    }                                                \
} while (0,0)

To delete a character, I just print a space in the same location. 要删除字符,我只需在同一位置打印一个空格。

I have windows 10 on my computer. 我的电脑上有Windows 10。

Does anyone have any idea what causes the problem or how to fix it? 有没有人知道导致问题的原因或解决方法?

I think it was just a problem with my font. 我认为这只是我的字体问题。
I set my default CMD font to Courier New (for hebrew support). 我将默认的CMD字体设置为Courier New(希伯来语支持)。
Changing it back to Lucida Console seems to have solved the problem. 将它改回Lucida Console似乎已经解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM