Problem with displaying character that code number is 219 (after SetConsoleTextAttribute)?

Joined
Nov 24, 2022
Messages
79
Reaction score
7
Compiler is devc++ 6.3 and OS is windows10.
Application creates an array of names (tab), draw frame, fills it with this names, and according to user keypress moves cursor up or down.
But there is problem with displaying a character that has code number 219. Console application doesn't display it but shows some blue lines instead at the end of string.
At the begining of this program, everything works fine, but after using "SetConsoleTextAttribute(console, 0x07);" or " SetConsoleOutputCP(852);" (I assume) it starts to show this blue and red lines at the begining of the string and at the end.
Output of draw_cursor should be beautiful white field from the begining of current name highlighted string to the end of frame.
What is important is function "draw_cursor()".

I also send printscreen of output.

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#include <iostream>

using namespace std;
char tab[10][30]; // an array of names
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // console handle


// placing cursor into new position
void gotoxy(short x, short y) {COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}

// hiding cursor
void hidecursor(){
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);}

void draw_cursor(int pos){
SetConsoleOutputCP(852);
SetConsoleTextAttribute(console, 0x07);
int poz=2;

for(int i=0;i<9;i++){
gotoxy(2,poz+i);
printf("%s",tab);}

gotoxy(2,pos+2);
SetConsoleTextAttribute(console, 0x70);

// PROBLEM !!!!
// DOESN'T DISPLAY 219 CHARACTER BUT BLUE LINES
for(int u=2;u<18;u++){
gotoxy(u,pos+2);
printf("%c",219);
//cout<<(unsigned char)219; doesn't work also
}

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
gotoxy(2,pos+2);
printf("%s",tab[pos]);}

void draw_frame(){


short start_x,start_y;
start_x=1;start_y=8;
// upper horizonttal
gotoxy(start_x,1);printf("%c",201);gotoxy(25,1);printf("%c",187);
for(int i=0;i<24;i++){gotoxy(i+start_x,1);printf("%c",205);}
gotoxy(start_x,1);
printf("%c",201);
// lower horizontal
gotoxy(start_x,1+10);
printf("%c",200);
gotoxy(25,1+10);
printf("%c",188);
for(int i=0;i<24;i++){gotoxy(i+start_x,1+10);printf("%c",205);}
gotoxy(start_x,1+10);
printf("%c",200);

for(int i=1;i<10;i++){gotoxy(start_x,i+1);printf("%c",186);gotoxy(start_x+24,i+1);printf("%c",186);}}



void prepare_an_array(){ strcpy(tab[0],"Charlie");
strcpy(tab[1],"John");
strcpy(tab[2],"Mike");
strcpy(tab[3],"Robert");
strcpy(tab[4],"Thomas");
strcpy(tab[5],"Endriu");
strcpy(tab[6],"James");
strcpy(tab[7],"Lucas");
strcpy(tab[8],"Bradley");}


int main()
{
hidecursor();
char z;
int position=0;

prepare_an_array();
draw_frame();
draw_cursor(0);

do{
z=getch();

if(z!=27){

if(z==80 && position<8){position++;draw_cursor(position);}
if(z==72 && position>0){position--;draw_cursor(position);}}

}while(z!=27);

return 0;
}
 

Attachments

  • problem.jpg
    problem.jpg
    18.2 KB · Views: 6
  • problem2.txt
    2.4 KB · Views: 3
Joined
Dec 21, 2022
Messages
28
Reaction score
4
SetConsoleOutputCP(852);
why do you change the code page?

All characters above 127 (non ASCII) will be displayed by the capabilities of the current code page. So, is character 219 in CP 852 that what you want?
Windows + Console + Non-ASCII is really big story, too long for here...

Maybe we can solve it the other way around. What is your goal? what do you want to achieve?

Did you you try to use the "Windows Terminal" App from the MS Store to run the Command Prompt in it? Is it change the behavior?
 
Joined
Nov 24, 2022
Messages
79
Reaction score
7
problem_1.jpg
problem_2.jpg

What I wrote is on the first picture, what I needed on the second. Actually, I talked to microsoft engeneers on microsoft A&Q and they told me to use "%-22s" formatter, and it works. However before I used draw_cursor() my solution worked fine also. What happend nor I neither they know. Interesting thing are those red and blue lines. You can read our conversation at - https://learn.microsoft.com/en-us/a...lem-with-displaying-a-character-that-has-code .

"It seems that 219 is a "Full Block" — a filled rectangle. The previous proposal uses spaces (which are added by "%-22s") to fill the row.
It is not clear why the red and blue lines appear. Maybe due to some approximations and anti-aliasing."
 

Attachments

  • 1673515194226.png
    1673515194226.png
    6.3 KB · Views: 5
Joined
Dec 21, 2022
Messages
28
Reaction score
4
Great that it could be solved!!

I did not know, that you can ask those kind of developer questions at MS.
Now, I just opened a bug report by myself as well. I will post it here, if they answer it (its also related to text output.)

Seems like you want to program an ASCII menu / ASCII art app?
The Win32 API offers also Console Virtual Terminal Sequences:
Do you know / use them?

Little bit off-topic: Would you be interested to use a Script language (which can be integrated into C++ apps as well),
which offers a small and tiny API for manipulate the Console Window? Like move cursor, change color, etc..?
Such a small and tiny API is on the feature list of my Script language I am working on. Thats why I ask.... Although that feature has not the highest priority to be implemented by me. But personally I would like to play around in the console as well...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,560
Members
45,035
Latest member
HoTaKeDai

Latest Threads

Top