0
CLIをWindowのCMDと似たものにする必要があります。カラーコマンドを作成するには、rlutil::setColor
とrlutil::setBackgroundColor
をrlutil.hに使用しています。しかし、すべてのコンソールで色を変更するには、画面(rlutil::cls()
)をクリアするか、画像にあるようにこの変更を加えた新しい出力のみが表示されます。 コンソールの色を変更し、出力をC++に保存してください
:CLSで
:CMD(私は現在のディレクトリを表示しないようにオフ@echo使用)で
これは私が作った機能です:
void colors(string value) {//I recive the user's input (like in the cmd)
char foo[3];//I save each character in this array
int c_text = 0, c_bg = 0;//Variables to get the numeric value of each character
if(value.length() == 2) {//This is to only accept 2 characters as parameter for the command
strcpy(foo, value.c_str());//Copy the values of the string in the array
c_bg= chartoHEX(foo[0]);//Take the int value of each character
//(if the parameter in chartoHEX is '0', returns 0, if it's 'A', returns 10, and so on)
c_text = chartoHEX(foo[1]);
//If the function returns -1 means that the parameter wasn't an HEX number
if(c_text != -1 && c_bg != -1) {
rlutil::setColor(c_text);//Changes the text color
rlutil::setBackgroundColor(c_bg);//Changes the background color
}
}
}
私は関数を呼び出す:
colors("0a");
rlutil::cls();
cout << "C:\\Users\\Raven>";
私は色を変更した後、出力を維持するにはどうすればよいですか?
これは動作しませんでしたが、これは解決策を見つけるのに役立ちました。代わりに、 'WriteConsoleOutputAttribute'を使用する代わりに' FillConsoleOutputAttribute'を使用しました。とにかくありがとう。 –
@ RavenH.-ここで解決方法を明らかにするのはどうですか? – lit
FillConsoleOutputAttributeはすべてのセルを同じ色で塗りつぶすため、WriteConsoleOutputAttributeは配列内のセルごとの色を指定します。あなたのニーズに最も適した機能を選択するだけです。 – Anders