简体   繁体   中英

Random pixels appearing in console window

I am writing a C Windows console application and strange pixels sometimes apper on the screen.

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):

#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.

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).
Changing it back to Lucida Console seems to have solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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