Funktionen Zusammenbauen z.B für Textfarbe



  • wie wär's mit

    // Standard C++ Library
    #include <iostream>
    
    // Platform Specific
    #include <windows.h>
    
    using namespace std;
    
    typedef unsigned char color_t;
    
    const color_t color_black         = 0x00;
    const color_t color_blue          = 0x01;
    const color_t color_green         = 0x02;
    const color_t color_cyan          = 0x03;
    const color_t color_red           = 0x04;
    const color_t color_magenta       = 0x05;
    const color_t color_brown         = 0x06;
    const color_t color_lightgray     = 0x07;
    const color_t color_darkgray      = 0x08;
    const color_t color_lightblue     = 0x09;
    const color_t color_lightgreen    = 0x0A;
    const color_t color_lightcyan     = 0x0B;
    const color_t color_lightred      = 0x0C;
    const color_t color_lightmagenta  = 0x0D;
    const color_t color_yellow        = 0x0E;
    const color_t color_white         = 0x0F;
    
    void textcolor( color_t color );
    void textbackground( color_t color );
    
    int main( )
    {
        textbackground( color_white );
        textcolor( color_black );
        cout << "white" << endl;
    
        textbackground( color_black );
        textcolor( color_blue );
        cout << "blue" << endl;
    
        textcolor( color_green );
        cout << "green" << endl;
    
        textcolor( color_cyan );
        cout << "cyan" << endl;
    
        textcolor( color_red );
        cout << "red" << endl;
    
        textcolor( color_magenta );
        cout << "magenta" << endl;
    
        textcolor( color_brown );
        cout << "brown" << endl;
    
        textcolor( color_lightgray );
        cout << "lightgray" << endl;
    
        textcolor( color_darkgray );
        cout << "darkgray" << endl;
    
        textcolor( color_lightblue );
        cout << "lightblue" << endl;
    
        textcolor( color_lightgreen );
        cout << "lightgreen" << endl;
    
        textcolor( color_lightcyan );
        cout << "lightcyan" << endl;
    
        textcolor( color_lightred );
        cout << "lightred" << endl;
    
        textcolor( color_lightmagenta );
        cout << "lightmagenta" << endl;
    
        textcolor( color_yellow );
        cout << "yellow" << endl;
    
        textcolor( color_white );
        cout << "white" << endl;
    
        textbackground( color_blue );
        textcolor( color_lightred );
        cout << "lightred" << endl;
    
        textbackground( color_black );
        textcolor( color_lightgray );
        cout << endl;
    }
    
    void textcolor( color_t color )
    {	
        if( color_white < color ) {
    
            return;
        }
    
        void *console_output = GetStdHandle( STD_OUTPUT_HANDLE );
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        GetConsoleScreenBufferInfo( console_output, &csbi );
        SetConsoleTextAttribute( console_output, ( csbi.wAttributes & 0xFFF0 ) | color );	
    }
    
    void textbackground( color_t color )
    {
        if( color_white < color ) {
    
            return;
        }
    
        void *console_output = GetStdHandle( STD_OUTPUT_HANDLE );
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        GetConsoleScreenBufferInfo( console_output, &csbi );
        SetConsoleTextAttribute( console_output, ( ( csbi.wAttributes & 0xFF0F ) | ( color << 4 ) ) );	
    }
    

    ?

    Greetz, Swordfish

    [edit] da ich den typedef unsigned short color_t auf typedef unsigned char color_t geändert habe machen auch die 2-Byte Werte für die color_-Konstanten keinen Sinn mehr. Auf 1-Byte Werte geändert. [/edit]

    [edit] Definition von void textbackground( unsigned short color ) auf void textbackground( color_t color ) geändert. [/edit]



  • wenns keine schwertfische geben würde *g*



  • Oki... ich glaube ich habs Verstanden ! Danke !!!!

    das mit dem multithreading hab ich auch hinbekommen.... es leuft fehlerfrei wenn ich alle threads in insgesammt 1. sec durchlaufen lasse...

    dazu aber noch ne frage.... gibt es auch ne vernünftigere art und weise threads zu syncroniesieren ohne _sleep() weil je mehr threads das prog hatt desto schlechter funktioniert es... dabei sollte es doch eigendlich pro thread mehr prozesse/systemtackt geben.... habsch irgendwo gelesen...
    es muss doch noch ne elegantere art geben als z.B:

    #include <time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <process.h>
    #include <textfarbe.h>
    
    //#include <windows.h>
    void Baltur( void *data )
    {
        int i=0,old_x=0,old_y=0;
    
        //_beginthread( Baltur, 0, 0 );
        // #include <process.h>
    
        do
        {
        old_x = where_x();old_y = where_y();
    
        if(i==0)
        {
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 0 );printf("(-)(-)            ");
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 1 );printf(" |__|             ");
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 2 );printf(" (  )      __     ");  
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 3 );printf("  )(    -      -  ");
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 4 );printf(" (  )_(  ( O )   )");
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 5 );printf("  )             ( ");
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 6 );printf(" (_______________)");
                Text_Farbe_Gruen;gotoxy( get_max_x( ) - 17, 7 );printf("                 ");
                i=1;goto Weiter;
        }
        if(i==1)
        {
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 0 );printf("(-)(-)");
                i=2;goto Weiter;
        }
        if(i==2)
        {
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 0 );printf("(o)(-)");
                Text_Farbe_Blau;gotoxy( get_max_x( ) - 17, 7 );printf("www.baltur.ath.cx");
                i=3;goto Weiter;
        }
        if(i==3)
        {
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 0 );printf("(O)(-)");
                i=4;goto Weiter;
        }
        if(i==4)
        {
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 0 );printf("(O)(o)");
                Text_Farbe_Rot;gotoxy( get_max_x( ) - 17, 7 );printf("www.baltur.ath.cx");
                i=5;goto Weiter;
        }
        if(i==5)
        {
                Text_Farbe_Gelb;gotoxy( get_max_x( ) - 18, 0 );printf("(O)(O)");
                i=0;goto Weiter;
        }
    
            Weiter:
            Text_Farbe_Normal;
            gotoxy( old_x, old_y );
            _sleep( 1000 );
    
    }while( true );
    }
    
    void clock( void *data );
    void clock1( void *data );
    void eingabe ( void *data)
    {
        char buffer[ 81 ];
        Text_Farbe_Normal;
        gotoxy(0,6);
        printf( "Enter a single 0 (null) at the beginning of a line to exit:\n" );
    
        while(1)
        {
            Text_Farbe_Normal;
            scanf ("%39[^\n]",buffer);
        }  
    
    }
    
    int main( )
    {
        int eing;
        //_beginthread( clock, 0, 0 );
        _beginthread( Baltur, 0, 0 );
        //_beginthread( eingabe, 0, 0 );
        //_beginthread( Baltur, 0, 0 );
        //_beginthread( clock, 0, 0 );
        //_beginthread( clock1, 0, 0 );
    
        gotoxy(0,8);   
        Text_Farbe_Normal;
        printf("Hallo");
        scanf("%i",&eing);
        gotoxy(0,9);
        printf("%i",eing);
        gotoxy(0,10);
        system("pause");
    
    }
    
    void clock( void *data )
    {
        time_t now_sec;
        tm *now_asc;
        int old_x, old_y;
    
        do {
            time( &now_sec );
            now_asc = gmtime( &now_sec );
    
            old_x = where_x( );
            old_y = where_y( );
    
            gotoxy( 0,0 );
            printf( " %02i:%02i:%02i ", now_asc->tm_hour, now_asc->tm_min, now_asc->tm_sec );
    
            gotoxy( old_x, old_y );
    
            _sleep( 333 );
    
        } while( true );
    } 
    void clock1( void *data )
    {
        time_t now_sec;
        tm *now_asc;
        int old_x, old_y;
    
        do {
            time( &now_sec );
            now_asc = gmtime( &now_sec );
    
            old_x = where_x( );
            old_y = where_y( );
    
            gotoxy( 0,2 );
            printf( " %02i:%02i:%02i ", now_asc->tm_hour, now_asc->tm_min, now_asc->tm_sec );
    
            gotoxy( old_x, old_y );
    
            _sleep( 333 );
    
        } while( true );
    }
    

    Diese frage richte ich vorallem an swordfish.... der mensch hatt ahnung !!!



  • [Linker error] undefined reference to `textbackground(unsigned char)'
    iss die fehlermeldung die bei deinem script kommt... wie gez ? doch nix verstanden....



  • Hallo,

    Na fällt dir was auf:

    void textbackground( unsigned short color )
    
    void textbackground( color_t color );
    
    typedef unsigned char color_t;
    

    MFG winexec*



  • Ups... Hab's gerade gesehen und ge'edited. Ich hab' in meinem Beispiel bei textbackground( ) den Parameter color tatsächlich als unsigned short definiert, Sorry.

    Greetz, Swordfish



  • ja , nö ??? irgendwie nicht wirklich.... unsigned.... aber wo iss da der fehler ?
    hätte der als int definiert werden müssen oder wie oder was ? ich binn doch voll der Lamer (aber man muss ja auch ma klein anfangen *g*)
    naja finds scho irgendwie raus, wenn meine kleinen mich in ruhe lassen *g*



  • alles klaro.....
    habs verstanden unsignet char..... fruchtet !!! Danke !!!!



  • mir kahm da noch so ne frage *g*

    also ich weis wass n unsigned int oder double ist... aber bei nem char string ????
    kann mir des einer von euch erklähren ? irgendwie bin ich sau froh das es dieses forum gibt !!!!

    DANKE AN EUCH WEBMASTER !!!!!!!

    und danke für die antworten und die antwort die bestimmt noch kommt...

    mfg Baltur....



  • Hallo,

    Also char strings sind mir unbekannt. Strings sind Kettungen von chars mit einer 0-Terminierung.

    MFG winexec*


Anmelden zum Antworten