Cursor auf Konsole positionieren und bunt schreiben, wie geht das?



  • Find eure Tipps ziemlich dumm aber meine Meinung ist ja nicht wichtig bin ja nicht ma registriert 😉

    So änderst du Farben:
    #include<windows.h>

    Und im Programm:
    system ("color 3c"); //Nur ein Beispiel

    Die kompletten Farben bekommste wenn du in der Konsole "help color" eingibst
    Oder in einem Programm
    system ("help color");
    system ("pause");

    Die Cursorposition setzt du so:
    #include <iostream.h>
    #include <windows.h>
    #include <winuser.h>

    Und im Programm:
    BOOL rc;
    rc = SetCursorPos(x,y);

    Feedback wäre nice
    Hoffe ich konnt dir helfen



  • Eigentlich ganz einfach unter C++

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), farbcode);



  • fdhgfjhgjhg schrieb:

    Die Cursorposition setzt du so:
    #include <iostream.h>
    #include <windows.h>
    #include <winuser.h>

    Und im Programm:
    BOOL rc;
    rc = SetCursorPos(x,y);

    mmmmm ja und wie kann ich das jetzt anwenden? ich möchte ein zeichen z.B. ein O auf die position 12,12 schreiebn ...... wie geht das?



  • 1. Improved Console installieren
    2.:

    #include <iostream>
    #include "ic.h"
    using namespace std;
    
    int main ()
    {
        gotoxy(12,12);
        cout << 'O';
    
        return 0;
    }
    

    3. STRG+F5 drücken (zumindest im Visual Studio)

    MfG SideWinder



  • laut turbopascal referenzhandbuch sollte doch

    uses crt;

    TextColor(Color: Byte);
    TextBackground(Color: Byte);
    Goto(X, Y:Byte);

    Write('Text');

    das Problem vollständig in pascal lösen ? 🙄



  • fdhgfjhgjhg schrieb:

    Find eure Tipps ziemlich dumm aber meine Meinung ist ja nicht wichtig bin ja nicht ma registriert 😉

    jupp

    fdhgfjhgjhg schrieb:

    So änderst du Farben:
    #include<windows.h>

    Und im Programm:
    system ("color 3c"); //Nur ein Beispiel

    nope
    also der ändert immer alles und das will ja keiner 😉

    cu

    P.S. nein, es ist KEIN turbo-pascal gefragt.



  • Ich denke er meinte, ob so einen Befehl gibt der vergleichbar ist mit GotoXY in TP.
    Oder er hat sich komisch ausgedrückt.



  • z.B.:
    #include<conio.h>

    int main()
    {
    textcolor(LIGHTGREEN);
    gotoxy(12,12);
    printf("O");
    }
    🕶



  • #include <windows.h>
    
    void gotoxy(int x,int y){
    	COORD c={x,y};
    	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
    }
    
    const int t_black=0x0000;
    const int t_blue=0x0001;
    const int t_green=0x0002;
    const int t_red=0x0004;
    const int t_intensity=0x0008;
    
    const int b_black=0x0000;
    const int b_blue=0x0010;
    const int b_green=0x0020;
    const int b_red=0x0040;
    const int b_intensity=0x0080;
    
    void color(int a){
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
    }
    
    #include <iostream>
    
    int main(void){
    	gotoxy(50,20);
    	color(t_black|b_intensity);
    	std::cout<<"* <--(x=50,y=20)";
    	gotoxy(1,0);
    	color(t_green|t_blue);
    	std::cout<<"* <--(x=1,y=0)";
    	std::cin.get();
    }
    


  • @Der Baumfäller: Ohne einen flush wird das nicht zuverlässig funktionieren.


Anmelden zum Antworten