Displaying extended ascii code

I would like to make a frame like by using extended ascii code, but it failed.
my code is as follow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
#include <windows.h>

using namespace std;

WORD GetConsoleTextAttribute(HANDLE hCon);
char getinput();
void banner(string);
void Display_Message(int);
void New_Record(){}
void Browse_Record(){}
void Settings(){}

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
const int saved_colors = GetConsoleTextAttribute(hConsole);

char Location[100];
const int max_for_main = 4;
const int max_for_settings = 2;

int main() {
    char key;
    int choice_for_menu;
    
    while (choice_for_menu != max_for_main) {
        choice_for_menu = 1;
        key = '0';
        while (key != 13) {
            Display_Message(choice_for_menu);
            key = getinput();
            if (key == 72) {
                choice_for_menu -= 1;
                if (choice_for_menu < 1) choice_for_menu = max_for_main;
            }
            else if (key == 80) {
                choice_for_menu += 1;
                if (choice_for_menu > max_for_main) choice_for_menu = 1;
            }
        }
        switch (choice_for_menu) {
            case 1: New_Record(); break;
            case 2: Browse_Record(); break;
            case 3: Settings();
        }
    }
    return 0;
}

WORD GetConsoleTextAttribute(HANDLE hCon) {
	CONSOLE_SCREEN_BUFFER_INFO con_info;
	GetConsoleScreenBufferInfo(hCon, &con_info);
	return con_info.wAttributes;
}

char getinput()
{
    char key;
    while (!(_kbhit()))
    {
        key = getch();                      
        if (key == -32) return _getch();    
        else if (key == 13) return key;
    }
    return 0;
}

void banner(string banner_word) {        
	SetConsoleTextAttribute(hConsole, 6 | FOREGROUND_INTENSITY);
	cout << (char)201;
    for (int i = 1; i <= banner_word.length()+ 2; i++) cout << (char)205;
    cout << (char)187 << endl;
    cout << (char)186;
	SetConsoleTextAttribute(hConsole, 2 | FOREGROUND_INTENSITY);
	cout << " " << banner_word << " ";
	SetConsoleTextAttribute(hConsole, 6 | FOREGROUND_INTENSITY);
	cout << (char)186 << endl;
    cout << (char)200;
    for (int i = 1; i <= banner_word.length()+ 2; i++) cout << (char)205;
    cout << (char)188 << endl << endl;
    SetConsoleTextAttribute(hConsole, saved_colors);
}

void Display_Message(int count) {
    string Menu_Message[] = {" ", "1. Insert New Record", "2. Search Old Record", "3. Settings", "4. Exit"};
   
    int max_string = 0;                                                   
    for (int x = 1; x <= max_for_main; x++)                                   
        if (Menu_Message[x].length() > max_string)
            max_string = Menu_Message[x].length();
            
    system("cls");
    banner("Library Management System");
    SetConsoleTextAttribute(hConsole, 5 | FOREGROUND_INTENSITY);
    cout << (char)201;
    for (int x = 1; x <= max_string + 2; x++) cout << (char)205;        
    cout << (char)187 << endl;
        
    for (int x = 1; x <= max_for_main; x++) {
        SetConsoleTextAttribute(hConsole, 5 | FOREGROUND_INTENSITY);
        cout << (char)186;
        if (count == x) SetConsoleTextAttribute(hConsole, 4 | FOREGROUND_INTENSITY);
        else SetConsoleTextAttribute(hConsole, 6 | FOREGROUND_INTENSITY);
        cout << " " << Menu_Message[x] << " ";
        SetConsoleTextAttribute(hConsole, 5 | FOREGROUND_INTENSITY);
        cout << (char)186 << endl;
    }
    
    cout << (char)200;
    for (int x = 1; x <= max_string + 2; x++) cout << (char)205;
    cout << (char)188;
    
    SetConsoleTextAttribute(hConsole, saved_colors);
} 


I have searched through this website and found that some platforms may not support extended ascii code.

Can anyone show me how to write the program so that extended ascii code can be output at whatever platform?


Thanks for the debugging and the recommendation of using the code page 1252.
But I don't know what steps I should take so that cp1252 can be implemented in console application. I am using Dev-C++ 4.9.9.2.
Maybe it is a silly question. But please help me. Thanks you all for your help.
Last edited on
Well, your frame was almost right - just a couple of lines out of place.
I'm sure you can correct that.

Anyway, the code you have so far is Microsoft Windows specific - so you might just as well draw your frame in a Micrsoft Windows specific way.
"Extended ASCII" is Microsoft/PC manufacturer specific stuff. Microsoft calls it "Code Page 1252". For every platform you wish to display this stuff, you will need to provide a cp1252 typeface (or "font"). On Windows, it is "Lucida Console".

Good luck.
Topic archived. No new replies allowed.