|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
MENU DEROULANT EN MODE GRAPHIQUE
Information sur la source
Description
Bah oui, c'est un menu déroulant en mode graphique. J'ai inséré plusieurs exemples dans le code pour expliquer les paramètres.
Source
- #include<conio.h>
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include <graphics.h>
- #include<dos.h>
-
- #define KEY_UP 72
- #define KEY_DOWN 80
-
- enum aff
- {
- min=12,
- norm=25,
- zoom=50,
- max=100
- };
-
-
- int gostmenu(int,int,int,char*,int,int,int,int,int,int);
- void gost(char*);
- void getchx(int);
-
-
- #define n_ele 7
- #define n_car 10
- #define adresse &menu1[0][0]
- #define desc 200
- #define mont 300
-
- #define TAILLE_ECRITURE 1
-
- void main()
- {
- int pos,use;
- char menu1[n_ele][n_car]={"Menu 0",
- "Menu 1",
- "Menu 2",
- "Menu 3",
- "Menu 4",
- "Menu 5",
- "Menu 6"
- };
-
-
- //Initialisation au mode graphique
- gost("x:\\tc3\\bgi");
-
- textcolor(BLUE);//couleur de fond
- clrscr();//nettoyage
- //choix,positionnement,taille de l'ecriture
- settextstyle(GOTHIC_FONT,HORIZ_DIR,TAILLE_ECRITURE);
-
- /*le menu renvoie la position dans le menu
- apres validation*/
- pos=gostmenu((getmaxx()/2)-25,getmaxy()/4,norm,
- adresse,n_ele,n_car,WHITE,BLACK,desc,mont);
-
- if (pos==0) getchx(0);
- else if (pos==1) getchx(1);
- else if (pos==2) getchx(2);
- else if (pos==3) getchx(3);
- else if (pos==4) getchx(4);
- else if (pos==5) getchx(5);
- else if (pos==6) getchx(6);
-
- }
-
-
- /*
- -----------------------Menu deroulant mode graph-----------------------------
- deb_col==> indique a partir de quelle col commencer le menu
- deb_lig==> indique a quelle ligne commencer l'affichage
- indice===> indique un espace entre chaque ligne usage de nbre ou enumeration
- (min,norm,zoom,max)
- tab======> donner l'adresse du tableau de ce menu
- a========> nombre d'element du tableau
- f========> nombre de caractere
- color1===> couleur general du menu
- color2===> couleur de selection
- down=====> son descendre
- up=======> son monter
- exemple:gostmenu(getmaxx()/2,10,25,&tab[0][0],7,20,10,129,200,300);
- */
-
- int gostmenu(int deb_col,int deb_lig,int indice,char*tab,int a,int f,int color1,int color2,int down,int up)
- {int ancpos,
- anci,
- pos,
- i,
- touche,
- ddd,
- max=a;
-
- _setcursortype(_NOCURSOR);
-
- pos=deb_lig+indice;
-
- for(i=0;i<max;i++)
- {
- setcolor(color1);
- _setcursortype(_NOCURSOR);
-
- deb_lig=deb_lig+indice;
- outtextxy(deb_col,(deb_lig+i),&tab[i*f]);
- if(i==0)
- {
- ddd=(deb_lig+i);
- }
- }//Fin FOR
-
- i=0;
- do
- {
-
- setcolor(color2);
- outtextxy(deb_col,(pos),&tab[i*f]);
- setcolor(color1);
- touche=getch();
- ancpos=pos;anci=i;
- if(touche==0)
- { touche=getch();
- if(touche==KEY_DOWN)
- {
- sound(down);
- delay(100);
- nosound();
- if(i==max-1)
- {
- pos=ddd;
- i=0;
- }
- else {
- pos=pos+(indice)+1;
- ++i;
- }
-
- }
- if(touche==KEY_UP)
- {
- sound(up);
- delay(100);
- nosound();
- if(i==0)
- {
- pos=(deb_lig+a)-1;
- i=max-1;
-
- }
- else {
- pos=pos-indice-1;
- --i;
- }
-
- }
-
- outtextxy(deb_col,(ancpos),&tab[anci*f]);
- }
-
- }
- while(touche!=13);
- clrscr();
- return i;
- }
-
- void gost(char*graph)
- { /* request autodetection */
- int gdriver = DETECT, gmode, errorcode;
- /* initialize graphics and local variables */
- initgraph(&gdriver, &gmode, graph);
-
- /* read result of initialization */
- errorcode = graphresult();
- if (errorcode != grOk) /* an error occurred */
- {
- printf("Graphics error: %s\n", grapherrormsg(errorcode));
- printf("Press any key to halt:");
- getch();
- exit(1); /* terminate with an error code */
- }
-
- }
-
- #undef TAILLE_ECRITURE
- #define SCOOL_WRITE 5
- #define TAILLE_ECRITURE 3
-
- void getchx(int x)
- { int pos;
- char y[5],n[16]="Menu ";
- char m2[3][n_car]={"Menu 1",
- "Menu 2",
- "Menu 3",
- };
- textcolor(10);
- setcolor(0);
- clrscr();
-
- itoa(x,y, 10);
- strcat(n,y);
- outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,n);
- settextstyle(SCOOL_WRITE,VERT_DIR,TAILLE_ECRITURE);
-
- pos=gostmenu(10,1,100,
- &m2[0][0],3,n_car,BLUE,RED,desc,mont);
-
- settextstyle(TRIPLEX_FONT,HORIZ_DIR,TAILLE_ECRITURE);
- textcolor(9);
- setcolor(1);
- clrscr();
-
-
- if (pos==0)outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,"SEC MENU 0");
- else if (pos==1)outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,"SEC MENU 1");
- else if (pos==2)outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,"SEC MENU 2");
-
-
-
-
- getch();
- closegraph();
- }
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <graphics.h>
#include<dos.h>
#define KEY_UP 72
#define KEY_DOWN 80
enum aff
{
min=12,
norm=25,
zoom=50,
max=100
};
int gostmenu(int,int,int,char*,int,int,int,int,int,int);
void gost(char*);
void getchx(int);
#define n_ele 7
#define n_car 10
#define adresse &menu1[0][0]
#define desc 200
#define mont 300
#define TAILLE_ECRITURE 1
void main()
{
int pos,use;
char menu1[n_ele][n_car]={"Menu 0",
"Menu 1",
"Menu 2",
"Menu 3",
"Menu 4",
"Menu 5",
"Menu 6"
};
//Initialisation au mode graphique
gost("x:\\tc3\\bgi");
textcolor(BLUE);//couleur de fond
clrscr();//nettoyage
//choix,positionnement,taille de l'ecriture
settextstyle(GOTHIC_FONT,HORIZ_DIR,TAILLE_ECRITURE);
/*le menu renvoie la position dans le menu
apres validation*/
pos=gostmenu((getmaxx()/2)-25,getmaxy()/4,norm,
adresse,n_ele,n_car,WHITE,BLACK,desc,mont);
if (pos==0) getchx(0);
else if (pos==1) getchx(1);
else if (pos==2) getchx(2);
else if (pos==3) getchx(3);
else if (pos==4) getchx(4);
else if (pos==5) getchx(5);
else if (pos==6) getchx(6);
}
/*
-----------------------Menu deroulant mode graph-----------------------------
deb_col==> indique a partir de quelle col commencer le menu
deb_lig==> indique a quelle ligne commencer l'affichage
indice===> indique un espace entre chaque ligne usage de nbre ou enumeration
(min,norm,zoom,max)
tab======> donner l'adresse du tableau de ce menu
a========> nombre d'element du tableau
f========> nombre de caractere
color1===> couleur general du menu
color2===> couleur de selection
down=====> son descendre
up=======> son monter
exemple:gostmenu(getmaxx()/2,10,25,&tab[0][0],7,20,10,129,200,300);
*/
int gostmenu(int deb_col,int deb_lig,int indice,char*tab,int a,int f,int color1,int color2,int down,int up)
{int ancpos,
anci,
pos,
i,
touche,
ddd,
max=a;
_setcursortype(_NOCURSOR);
pos=deb_lig+indice;
for(i=0;i<max;i++)
{
setcolor(color1);
_setcursortype(_NOCURSOR);
deb_lig=deb_lig+indice;
outtextxy(deb_col,(deb_lig+i),&tab[i*f]);
if(i==0)
{
ddd=(deb_lig+i);
}
}//Fin FOR
i=0;
do
{
setcolor(color2);
outtextxy(deb_col,(pos),&tab[i*f]);
setcolor(color1);
touche=getch();
ancpos=pos;anci=i;
if(touche==0)
{ touche=getch();
if(touche==KEY_DOWN)
{
sound(down);
delay(100);
nosound();
if(i==max-1)
{
pos=ddd;
i=0;
}
else {
pos=pos+(indice)+1;
++i;
}
}
if(touche==KEY_UP)
{
sound(up);
delay(100);
nosound();
if(i==0)
{
pos=(deb_lig+a)-1;
i=max-1;
}
else {
pos=pos-indice-1;
--i;
}
}
outtextxy(deb_col,(ancpos),&tab[anci*f]);
}
}
while(touche!=13);
clrscr();
return i;
}
void gost(char*graph)
{ /* request autodetection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, graph);
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
}
#undef TAILLE_ECRITURE
#define SCOOL_WRITE 5
#define TAILLE_ECRITURE 3
void getchx(int x)
{ int pos;
char y[5],n[16]="Menu ";
char m2[3][n_car]={"Menu 1",
"Menu 2",
"Menu 3",
};
textcolor(10);
setcolor(0);
clrscr();
itoa(x,y, 10);
strcat(n,y);
outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,n);
settextstyle(SCOOL_WRITE,VERT_DIR,TAILLE_ECRITURE);
pos=gostmenu(10,1,100,
&m2[0][0],3,n_car,BLUE,RED,desc,mont);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,TAILLE_ECRITURE);
textcolor(9);
setcolor(1);
clrscr();
if (pos==0)outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,"SEC MENU 0");
else if (pos==1)outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,"SEC MENU 1");
else if (pos==2)outtextxy((getmaxx()/2)-50,(getmaxy()/4)-100,"SEC MENU 2");
getch();
closegraph();
}
Sources de la même categorie
Commentaires et avis
|
Comparez les prix Nouvelle version

HTC Touch HD
Entre 25€ et 605€
|