begin process at 2012 05 27 18:38:50
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > MENU ET CONTROLE DE LA SAISIE D'UN ENTIER

MENU ET CONTROLE DE LA SAISIE D'UN ENTIER


 Information sur la source

Note :
10 / 10 - par 1 personne
10,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Divers Niveau :Débutant Date de création :20/10/2003 Date de mise à jour :21/10/2003 21:16:24 Vu :5 048

Auteur : Boygen

Ecrire un message privé
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
La fonction "short int menu(char*, short int, bool);"


La fonction menu()
Prototype:
short int menu(char *, short int, bool)
entrées:
1er paramatre: pointeur vers 1er element d'un vecteur de char comme suit:
char elemmenu[] = "Titre du menu\0Sortie/retour du menu(0)\01er prop(1)\02eme prop(2)\0etc...\0";
2eme parametre: short int qui donne le choix par défaut.
3eme paramatre: bool, si à vrai affiche les messages d'erreurs en cas d'erreur.

sortie: short int, "-1" en cas d'erreur, "0" en pour la sortie/retour, Si >1 donne le numéro de la proposition.

Utilisation:
Fleche du haut/bas pour changer de propsition (ou raccourci avec le pavé numérique pour les choix de 0 à maximum la 9eme propostion, si il y a)
valider avec la touche [ENTER]
Sortie rapide avec la touche [ESC] (choisi sortie/retour, donc retourne "0")



La fonction "int SaisirEntier(char[]);"
retourne un entier saisie au clavier (controle la saisie)

Source

  • /*******************************************************************************\
  • * Nom: Thomas * Lieu: Belgique *
  • * Pseudo: boygen * Projet: Bibliotheque de fonctions *
  • * E-mail: boygen81@hotmail.com* Compilateur: Microsoft Visual C++ (6.0) *
  • * Langage:C & C++ * O.S.: Windows 2000 Professionnel *
  • * Fichier:fctperso.cpp * Rapport: (voir commentaires) *
  • \*******************************************************************************/
  • /*******************************************************************************
  • les definitions des fonctions=
  • int SaisirEntier(char[]);
  • short int menu(char*, short int, bool);
  • *******************************************************************************/
  • // les includes pour toutes les fonctions...
  • #include <conio.h>
  • #include <limits.h>
  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <windows.h>
  • /*******************************************************************************/
  • // define pour "int SaisirEntier(char[]);"
  • #define KEY_0 (int) '0' // definition des codes touche
  • #define KEY_9 (int) '9'
  • #define KEY_ENTER 13
  • #define KEY_BKDEL 8
  • #define KEY_MOINS (int) '-'
  • #define KEY_PLUS (int) '+'
  • /*******************************************************************************/
  • // define pour "short int menu(char*, short int, bool);"
  • #define NBCOLSRC 80
  • #define NBLGNSRC 25
  • #define MENUSELECTED (FOREGROUND_BLUE|FOREGROUND_INTENSITY)
  • #define MENUNOSELECTED (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)
  • #define MENUFORM (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY)
  • #define MENUBK (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)
  • #define MENUTXT 0
  • #define NORMTXT (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY)
  • #define NORMBK 0
  • #define ERRORCOLOR (FOREGROUND_RED)
  • #define textattr(color) SetConsoleTextAttribute(STDOUT,color)
  • #define textcolor(color) SetConsoleTextAttribute(STDOUT,back_color|(front_color=(color)))
  • #define textbackground(color) SetConsoleTextAttribute(STDOUT,(back_color=((color)<<4))|front_color)
  • #define HAUT 72
  • #define BAS 80
  • #define ESC 27
  • #define ENTER 13
  • #define NUMZERO 48
  • #define NORM (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)
  • #define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
  • WORD front_color=NORM;
  • WORD back_color=0;
  • /*******************************************************************************/
  • // les fonctions...
  • /*******************************************************************************/
  • // La fonction "int SaisirEntier(char[]);"
  • int SaisirEntier(char msg[]){
  • bool sgplus = false, sgmoins = false, zero = false;
  • int entier = 0, keymax;
  • char touche;
  • do{
  • system("cls");
  • printf("%s", msg); //affiche la demande
  • if(sgplus) printf("+"); // gestion de l'affichage des signes
  • else if(sgmoins) printf("-");
  • if(zero) printf("0"); // gestion de l'affichage du zero
  • else if(entier) printf("%d",entier); // sinon de l'entier
  • touche=getch(); // saisie d'un chiffre ou d'une touche commande
  • if(touche == 0) getch(); // vide le buffer (ex: protection contre les touches etendues)
  • if(touche == KEY_BKDEL) { //gère la touche d'effacement
  • if(!entier) {zero?zero = false :sgmoins = sgplus = false;}
  • else entier /= 10;
  • }
  • if(!zero){ // gère les touches de signe
  • if(!entier && !sgmoins && !sgplus){
  • if(touche == KEY_MOINS) sgmoins = true;
  • else if(touche == KEY_PLUS) sgplus = true;
  • }
  • if(entier <= (INT_MAX / 10)){ // gere la taille mx de l'entier
  • if(touche == KEY_0 && !entier) zero = true;
  • else{
  • keymax = KEY_9;
  • if(entier == (INT_MAX / 10)) keymax = KEY_0 + (INT_MAX % 10);
  • if(touche >= KEY_0 && touche <= keymax) entier = (entier * 10) + (touche - KEY_0); // ajoute un chiffre au nombre
  • }
  • }
  • }
  • }while(touche != KEY_ENTER || (!entier && !zero)); // condition de sortie
  • if(sgmoins) entier = -entier; // adapte la valeur en fonction du signe
  • return entier; // retourne la valeur
  • }
  • /*******************************************************************************/
  • // La fonction "short int menu(char*, short int, bool);"
  • /*
  • La fonction menu()
  • Prototype:
  • short int menu(char *, short int, bool)
  • entrées:
  • 1er paramatre: pointeur vers 1er element d'un vecteur de char comme suit:
  • char elemmenu[] = "Titre du menu\0Sortie/retour du menu(0)\01er prop(1)\02eme prop(2)\0etc...\0";
  • 2eme parametre: short int qui donne le choix par défaut.
  • 3eme paramatre: bool, si à vrai affiche les messages d'erreurs en cas d'erreur.
  • sortie: short int, "-1" en cas d'erreur, "0" en pour la sortie/retour, Si >1 donne le numéro de la proposition.
  • Utilisation:
  • Fleche du haut/bas pour changer de propsition (ou raccourci avec le pavé numérique pour les choix de 0 à maximum la 9eme propostion, si il y a)
  • valider avec la touche [ENTER]
  • Sortie rapide avec la touche [ESC] (choisi sortie/retour, donc retourne "0")
  • A faire:
  • Géré les caractère spéciaux tel que \t,
  • Convertir les saut de ligne de \0 à \n,
  • ...
  • */
  • void gotoxy(int x,int y){
  • COORD pos={x-1,y-1};
  • SetConsoleCursorPosition(STDOUT,pos);
  • }
  • void procchar(unsigned short int xfois, char cara){
  • for(unsigned short int i = 1; i <= xfois; i++) printf("%c", cara);
  • }
  • void writelgn(char *ligne, unsigned short int noprop){
  • unsigned short int c = -1;
  • for(unsigned short int curprop = 0; curprop < noprop; curprop++) while(*(ligne + (++c)));
  • for(unsigned short int i = c+1; *(ligne + i); i++) printf("%c", *(ligne + i));
  • }
  • short int menu(char *propositions, short int choix, bool prterr){
  • unsigned short int nblignes=0, max, lgtitre, curlg=-1, decalage, pavnum, debutlgn;
  • short int poiderror = -1, errorcode = 0;
  • char touche;
  • bool error = false;
  • while(*(propositions + (++curlg)));// donne la longeure du titre
  • debutlgn = max = lgtitre = curlg;
  • while(*(propositions + debutlgn) || *(propositions + debutlgn + 1)){ // donne la ligne la plus grande et compte le nombre de ligne
  • curlg = 0;
  • while(*(propositions + (debutlgn + (++curlg) + 1)));
  • if(curlg > max) max = curlg;
  • debutlgn+= (curlg + 1);
  • nblignes++;
  • }
  • textcolor(ERRORCOLOR);
  • textbackground(NORMBK);
  • if(nblignes == 1){
  • if(prterr) printf("*** Erreur menu : il faut au moins un titre et un element de fin ***\n");
  • errorcode += poiderror;
  • }
  • poiderror *= 2;
  • if((nblignes* 2 + 6) > NBLGNSRC){
  • if(prterr) printf("*** Erreur menu : trop de proposition pour l'ecran ***\n");
  • errorcode += poiderror;
  • }
  • poiderror *= 2;
  • if((max + 5) > NBCOLSRC){
  • if(prterr) printf("*** Erreur menu : proposition(s) trop longue(s) ***\n");
  • errorcode += poiderror;
  • }
  • poiderror *= 2;
  • if(choix < 0 || choix >= nblignes){
  • if(prterr) printf("*** Erreur menu : choix par defaut hors des possibilitees ***\n");
  • errorcode += poiderror;
  • }
  • if(errorcode) return errorcode;
  • else{
  • decalage = (NBCOLSRC - (max + 4))/2;
  • system("cls");// efface l'ecran
  • // dessinne le tableau
  • textbackground(NORMBK);
  • procchar(decalage, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("ÉÍ");
  • procchar(max, 'Í');
  • printf("Í»\n");
  • textbackground(NORMBK);
  • procchar(decalage, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("º");
  • procchar((max-lgtitre)/2, ' ');
  • printf("Ú");
  • procchar(lgtitre, 'Ä');
  • printf("¿");
  • procchar((max-lgtitre)/2 + (max-lgtitre)%2, ' ');
  • printf("º");
  • textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);
  • textbackground(NORMBK);
  • procchar(decalage, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("º");
  • procchar((max-lgtitre)/2, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("³");
  • writelgn(propositions, 0); // affichage du titre
  • printf("³");
  • procchar((max-lgtitre)/2 + (max-lgtitre)%2, ' ');
  • printf("º");
  • textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);
  • textbackground(NORMBK);
  • procchar(decalage, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("º");
  • procchar((max-lgtitre)/2, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("À");
  • procchar(lgtitre, 'Ä');
  • printf("Ù");
  • procchar((max-lgtitre)/2 + (max-lgtitre)%2, ' ');
  • printf("º");
  • textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);
  • for(int i = 1; i <= (nblignes * 2)+1; i++){ // pas i<= nblignes car il y a le titre
  • textbackground(NORMBK);
  • procchar(decalage, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("º ");
  • procchar(max, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf(" º");
  • textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);
  • }
  • textbackground(NORMBK);
  • procchar(decalage, ' ');
  • textcolor(MENUTXT);textbackground(MENUFORM);
  • printf("ÈÍ");
  • procchar(max, 'Í');
  • printf("ÍO");
  • textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);
  • textbackground(NORMBK);
  • procchar(decalage+1, ' ');
  • textbackground(MENUBK);procchar(max+4, ' ');
  • textbackground(MENUFORM);
  • do{
  • for(int i = 2; i <= nblignes; i++){
  • if (choix == (i-1)) textcolor(MENUSELECTED);
  • else textcolor(MENUNOSELECTED);
  • gotoxy(decalage+3,4+2*(i-1));
  • writelgn(propositions, i); // affichage des propostitions
  • }
  • if (choix == 0) textcolor(MENUSELECTED);
  • else textcolor(MENUNOSELECTED);;
  • gotoxy(decalage+3,4+2*nblignes);
  • writelgn(propositions, 1); // affichage de la proposition de sortie
  • touche=getch();
  • if(choix == 0) choix = nblignes;
  • if(touche == BAS) choix = ++choix;
  • if(touche == HAUT) choix = --choix;
  • if(touche == ESC) choix = 0;
  • if(nblignes > 10) pavnum = 10;
  • else pavnum = nblignes;
  • if (touche >= NUMZERO && touche < (NUMZERO + pavnum)) choix = touche - NUMZERO;
  • choix %= nblignes;
  • }while (touche!=ENTER && touche!=ESC);
  • textcolor(NORMTXT);textbackground(NORMBK);gotoxy(1,1);system("cls"); // retour à un ecran vierge
  • return choix;
  • }
  • }
  • void main(void){
  • int choix=2, a;
  • do{
  • switch(choix = menu("DEMO\0Quitter la demo\0Saisir un entier\0choix par defaut\0choix 3\0", choix, false)){
  • case 1: a = SaisirEntier("Entrer un entier:"); printf("\nVoici l'entier: %d\n", a);
  • break;
  • case 2: printf("Choix par defaut\n");
  • break;
  • case 3: printf("Choix 3\n");
  • }
  • system("pause");
  • }while(choix);
  • }
/*******************************************************************************\
*   Nom:    Thomas                  *   Lieu:           Belgique                    *
*   Pseudo: boygen              *   Projet:         Bibliotheque de fonctions   *
*   E-mail: boygen81@hotmail.com*   Compilateur:    Microsoft Visual C++ (6.0)  *
*   Langage:C & C++             *   O.S.:           Windows 2000 Professionnel  *
*   Fichier:fctperso.cpp        *   Rapport:        (voir commentaires)         *
\*******************************************************************************/

/*******************************************************************************
    les definitions des fonctions=

int SaisirEntier(char[]);
short int menu(char*, short int, bool);

*******************************************************************************/
// les includes pour toutes les fonctions...

#include <conio.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>


/*******************************************************************************/
// define pour "int SaisirEntier(char[]);"




#define KEY_0       (int) '0'   // definition des codes touche
#define KEY_9       (int) '9'
#define KEY_ENTER   13
#define KEY_BKDEL   8
#define KEY_MOINS   (int) '-'
#define KEY_PLUS    (int) '+'


/*******************************************************************************/
// define pour "short int menu(char*, short int, bool);"




#define     NBCOLSRC                80
#define     NBLGNSRC                25

#define     MENUSELECTED     (FOREGROUND_BLUE|FOREGROUND_INTENSITY)
#define     MENUNOSELECTED  (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)
#define     MENUFORM         (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY)
#define     MENUBK          (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)   
#define  MENUTXT            0
#define     NORMTXT          (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY)
#define     NORMBK      0
#define     ERRORCOLOR                  (FOREGROUND_RED)


#define     textattr(color)     SetConsoleTextAttribute(STDOUT,color)
#define     textcolor(color)    SetConsoleTextAttribute(STDOUT,back_color|(front_color=(color)))
#define     textbackground(color)   SetConsoleTextAttribute(STDOUT,(back_color=((color)<<4))|front_color)
#define     HAUT                    72
#define     BAS                  80
#define     ESC                     27
#define     ENTER                13
#define     NUMZERO              48

#define     NORM    (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)
#define     STDOUT          GetStdHandle(STD_OUTPUT_HANDLE)

WORD        front_color=NORM;
WORD        back_color=0;



/*******************************************************************************/
// les fonctions...                                                         
/*******************************************************************************/
// La fonction "int SaisirEntier(char[]);"





int SaisirEntier(char msg[]){
    bool sgplus = false, sgmoins = false, zero = false;
    int entier = 0, keymax;
    char touche;

    do{
        system("cls");
        

        printf("%s", msg);  //affiche la demande

        if(sgplus) printf("+"); // gestion de l'affichage des signes
        else if(sgmoins) printf("-"); 

        if(zero) printf("0");   // gestion de l'affichage du zero
        else if(entier) printf("%d",entier);    // sinon de l'entier

        touche=getch(); // saisie d'un chiffre ou d'une touche commande

        if(touche == 0) getch(); // vide le buffer (ex: protection contre les touches etendues)



        
        if(touche == KEY_BKDEL) {   //gère la touche d'effacement
            if(!entier) {zero?zero = false :sgmoins = sgplus = false;}
            else entier /= 10;
        }


        if(!zero){  // gère les touches de signe
            if(!entier && !sgmoins && !sgplus){
                if(touche == KEY_MOINS) sgmoins = true;
                else if(touche == KEY_PLUS) sgplus = true;
            }

            if(entier <= (INT_MAX / 10)){   // gere la taille mx de l'entier
                if(touche == KEY_0 && !entier) zero = true;
                else{
                    keymax = KEY_9;
                    if(entier == (INT_MAX / 10)) keymax = KEY_0 + (INT_MAX % 10);
                    if(touche >= KEY_0 && touche <= keymax) entier = (entier * 10) + (touche - KEY_0);  // ajoute un chiffre au nombre
                }
            }       

        }
    
    
    }while(touche != KEY_ENTER || (!entier && !zero)); // condition de sortie

    if(sgmoins) entier = -entier; // adapte la valeur en fonction du signe
    return entier;  // retourne la valeur
}


/*******************************************************************************/
// La fonction "short int menu(char*, short int, bool);"

/*
La fonction menu()
    Prototype:
                short int menu(char *, short int, bool)
    entrées:
                1er paramatre:  pointeur vers 1er element d'un vecteur de char comme suit:
                                    char elemmenu[] = "Titre du menu\0Sortie/retour du menu(0)\01er prop(1)\02eme prop(2)\0etc...\0";
                2eme parametre: short int qui donne le choix par défaut.
                3eme paramatre: bool, si à vrai affiche les messages d'erreurs en cas d'erreur.

    sortie:     short int, "-1" en cas d'erreur, "0" en pour la sortie/retour, Si >1 donne le numéro de la proposition.
    
    Utilisation:
                Fleche du haut/bas pour changer de propsition (ou raccourci avec le pavé numérique pour les choix de 0 à maximum la 9eme propostion, si il y a)
                valider avec la touche [ENTER]
                Sortie rapide avec la touche [ESC] (choisi sortie/retour, donc retourne "0")
    A faire:
                Géré les caractère spéciaux tel que \t,
                Convertir les saut de ligne de \0 à \n,
                ...
*/





void gotoxy(int x,int y){
    COORD   pos={x-1,y-1};
    SetConsoleCursorPosition(STDOUT,pos);
}


void procchar(unsigned short int xfois, char cara){
    for(unsigned short int i = 1; i <= xfois; i++) printf("%c", cara);
}

void writelgn(char *ligne, unsigned short int noprop){
    unsigned short int c = -1;
    for(unsigned short int curprop = 0; curprop < noprop; curprop++) while(*(ligne + (++c)));
    for(unsigned short int i = c+1; *(ligne + i); i++) printf("%c", *(ligne + i));
}



short int menu(char *propositions, short int choix, bool prterr){
    unsigned short int nblignes=0, max, lgtitre, curlg=-1, decalage, pavnum, debutlgn;
    short int poiderror = -1, errorcode = 0;
    char touche;
    bool error = false;
    

    while(*(propositions + (++curlg)));// donne la longeure du titre
    debutlgn = max = lgtitre = curlg;

    while(*(propositions + debutlgn) || *(propositions + debutlgn + 1)){ // donne la ligne la plus grande et compte le nombre de ligne
        curlg = 0;
        while(*(propositions + (debutlgn + (++curlg) + 1))); 
        if(curlg > max) max = curlg;
        debutlgn+= (curlg + 1);
        nblignes++;
    }

    textcolor(ERRORCOLOR);
    textbackground(NORMBK);
    if(nblignes == 1){
        if(prterr) printf("*** Erreur menu : il faut au moins un titre et un element de fin ***\n");
        errorcode += poiderror;
    }
    poiderror *= 2;

    if((nblignes* 2 + 6) > NBLGNSRC){
        if(prterr) printf("*** Erreur menu : trop de proposition pour l'ecran ***\n");
        errorcode += poiderror;
    }
    poiderror *= 2;

    if((max + 5) > NBCOLSRC){
        if(prterr) printf("*** Erreur menu : proposition(s) trop longue(s) ***\n");
        errorcode += poiderror;
    }    
    poiderror *= 2;

    if(choix < 0 || choix >= nblignes){
        if(prterr) printf("*** Erreur menu : choix par defaut hors des possibilitees ***\n");
        errorcode += poiderror;
    }

    
    if(errorcode) return errorcode;
    else{

            decalage = (NBCOLSRC - (max + 4))/2;

            system("cls");// efface l'ecran


            // dessinne le tableau
            textbackground(NORMBK);
            procchar(decalage, ' ');
            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("ÉÍ");
            procchar(max, 'Í');
            printf("Í»\n");

            textbackground(NORMBK);
            procchar(decalage, ' ');
            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("º");
            procchar((max-lgtitre)/2, ' ');
            printf("Ú");
            procchar(lgtitre, 'Ä');
            printf("¿");
            procchar((max-lgtitre)/2 + (max-lgtitre)%2, ' ');
            printf("º");
            textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);

            textbackground(NORMBK);
            procchar(decalage, ' ');
            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("º");    
            procchar((max-lgtitre)/2, ' ');
            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("³");


            writelgn(propositions, 0); // affichage du titre
            
            printf("³");
            procchar((max-lgtitre)/2 + (max-lgtitre)%2, ' ');
            printf("º");
            textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);

            textbackground(NORMBK);
            procchar(decalage, ' ');

            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("º");
            procchar((max-lgtitre)/2, ' ');
            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("À");
            procchar(lgtitre, 'Ä');
            printf("Ù");
            procchar((max-lgtitre)/2 + (max-lgtitre)%2, ' ');
            printf("º");
            textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);

            for(int i = 1; i <= (nblignes * 2)+1; i++){ // pas i<= nblignes car il y a le titre
                textbackground(NORMBK);
                procchar(decalage, ' ');
                textcolor(MENUTXT);textbackground(MENUFORM);
                printf("º ");
                procchar(max, ' ');
                textcolor(MENUTXT);textbackground(MENUFORM);
                printf(" º");
                textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);
            }
            
            textbackground(NORMBK);
            procchar(decalage, ' ');
            textcolor(MENUTXT);textbackground(MENUFORM);
            printf("ÈÍ");
            procchar(max, 'Í');
            printf("ÍO");
            textbackground(MENUBK);printf(" \n");textbackground(MENUFORM);

            textbackground(NORMBK);
            procchar(decalage+1, ' ');
            textbackground(MENUBK);procchar(max+4, ' ');

            textbackground(MENUFORM);
            do{
                for(int i = 2; i <= nblignes; i++){
                    if (choix == (i-1)) textcolor(MENUSELECTED);
                    else textcolor(MENUNOSELECTED);
                    gotoxy(decalage+3,4+2*(i-1));
                    writelgn(propositions, i); // affichage des propostitions
                }

                if (choix == 0) textcolor(MENUSELECTED);
                else textcolor(MENUNOSELECTED);;
                gotoxy(decalage+3,4+2*nblignes);
                writelgn(propositions, 1); // affichage de la proposition de sortie
    
                touche=getch();

                if(choix == 0) choix = nblignes;
                if(touche == BAS) choix = ++choix;
                if(touche == HAUT) choix = --choix;
                if(touche == ESC) choix = 0;

                if(nblignes > 10) pavnum = 10;
                else pavnum = nblignes; 
                if (touche >= NUMZERO && touche < (NUMZERO + pavnum)) choix = touche - NUMZERO;

                choix %= nblignes;

    
            }while (touche!=ENTER && touche!=ESC);
            textcolor(NORMTXT);textbackground(NORMBK);gotoxy(1,1);system("cls"); // retour à un ecran vierge
            return choix;
    
        }
    
}


void main(void){

	int choix=2, a;

	do{
		switch(choix = menu("DEMO\0Quitter la demo\0Saisir un entier\0choix par defaut\0choix 3\0", choix, false)){
		case 1: a = SaisirEntier("Entrer un entier:"); printf("\nVoici l'entier: %d\n", a);
			break;
		case 2: printf("Choix par defaut\n");
			break;
		case 3: printf("Choix 3\n");
		}
        system("pause");
	}while(choix);

}

 Conclusion

A faire (pour le menu):
Géré les caractère spéciaux tel que \t,
Convertir les saut de ligne de \0 à \n,
...


 Sources du même auteur

Source avec Zip COMBAT NAVAL

 Sources de la même categorie

Source avec Zip KISIEL CD INFO DRIVE par kisiel0147852
Source avec une capture SUPPRESSION DES REDONDANCES DE FICHIERS par cyberntique
Source avec Zip ÉDITEUR DE RECTANGLES EN CONSOLE par seoseo
CONVERSION DE FICHIER EN FICHIER BMP par seoseo
Source avec Zip DETECTEUR EJP par idpro

Commentaires et avis

Commentaire de djl le 20/10/2003 20:19:38

ca claque, c justement ce dont j'avais besoin
tu pourrai faire un main de demo, c plus parlant pour moi!

Commentaire de djl le 21/10/2003 18:11:05

c bon c pas la peine, g piger comment ca marchait

Commentaire de temoin le 21/10/2003 19:21:39

Bonjour ton prog a l'air super sauf pour moi je une erreur de compile avec c++ 5.0    ! ERROR: Unresolved external ' _main' reference from D:BC5LIBCOX32.OBJ
Cette ligne  D:BC5LIBCOX32.OBJ c'est le repertoir ou j'ai installer le c++
entout cas moi je vois pas comment corriger cet erreur toi ou quelqu'un aide moi si vous savez aussi je roule sur xp prof merci.

Commentaire de djl le 21/10/2003 19:38:37

g suppose que ta pensé a mettre un main?

Commentaire de Boygen le 21/10/2003 21:18:43

Voilà, une demo "main" ajoutée. C'est un peu lourd comme code, mais j'avais fait ca en vitesse à l'époque.
Merci pour vos commentaires et bonne programmation

Commentaire de temoin le 21/10/2003 23:20:13

non javais pas mis un main  je pensais que tout etait dedans

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,562 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales