Current location - Recipe Complete Network - Catering industry - Make popup menu in c
Make popup menu in c
void Menu()

{

system("cls"); /*call the system's clear screen command*/

textbackground(BLUE);/*set the background to blue*/

textmode(2);

window(1, 1,25,80);

clrscr();

textx=3;/* cursor initialization position */

texty=2;

gotoxy(1,2);

cprintf("%c",218);/* draw the upper left corner */

for(i =0;i<78;i++)

cprintf("%c",196); /*draw horizontal straight line*/

cprintf("%c",191);/*draw upper right corner*/

for(i=3;i<=23;i++)

{

gotoxy(1,i);

cprintf("%c",179); /*draw vertical line*/

gotoxy(80,i);

cprintf("%c",179);

}

cprintf("%c",192); /*draw lower left corner*

for(i=3;i<=23;i++) {

{

for(i=3;i<=23;i++)

for(i=0;i<78;i++)

cprintf("%c",196);

cprintf("%c",217); /*draw lower right corner*

gotoxy(1,1);

textcolor(7); /*set gray */

for(i=0;i<80;i++)

cprintf("%c",219);/* Symbolic implementation of drawing the gray background area of the main menu */

Selectitem(); /* Call the option function */

DrawSelectitem(); / * draw options*/

gettext(2,3,78,23,c); /* save the current text area */

}

/* define the menu */

void Selectitem()

{

strcpy(ml[0].name, "File ");/* The specific options below are complementary spaces in order to have the same black background for each menu*

strcpy(ml[0].str[0], "Open ALT-O");

strcpy(ml[0].str[1], "New ALT-N");

strcpy(ml[0]. str[2], "Save Ctrl-S");

strcpy(ml[0].str[3], "Write to... ");

strcpy(ml[0].str[4], "Exit ");

ml[0].n=5; /*Save the number of items in the menu**

strcpy(ml[1].name, "Edit");

strcpy(ml[1].str[0], "Cut Ctrl+X");

strcpy(ml[1].str[1], "Copy Ctrl+C");

strcpy(ml[1].str[2], "Paste Ctrl+V");

strcpy(ml[1].str[3], "Find ");

strcpy(ml[1].str[4], "Find&Replace ");

ml[1].n=5;

strcpy(ml[2].name, "Help");/* System Help**

strcpy(ml[2].str[0]," This System ");

strcpy(ml[2].str[1], "Ver ");

ml[2].n=2;

}

//*Display the main list name */

void DrawSelectitem()

{

for(i=0;i<3;i++)

RedText(i,1,ml[i].name); /* Display the main menu name with initial red color */

}

//*Display the menu normally */

void RedText(int x,int y,char *z)< /p>

{

textbackground(7); /* set background color to light gray */

gotoxy(3+x*20,y);

for(j=0;z[j];j++)

{

if(j==0)

textcolor(RED);/* show red color for the first letter */

else

textcolor(BLACK); /* set black color */

cprintf("%c",z[j]); /* output menu name */

}

}

/ * show selected menu */

void BlackText(int x,int y,char *z)

{

textbackground(0); /* set background color to black */

textcolor(15); /* set text color to white */

gotoxy(3+20*x,y); /* locate coordinates */

cputs(z); /* output menu name string */

}

//* DrawFrame function */

void DrawFrame(int l,int u,int r,int d,int tcolor,int bcolor)

{

textbackground(bcolor); /*Background color**/

textcolor(bcolor); /*Text color**/

for(i=l;i<=r;i++) /*Output background area*/

{

for(j=u;j<=d;j++)

{

gotoxy(i,j);

cprintf("%c",219); /* outputs the background characters*/

}

}

textcolor(tcolor);/* border color */

for(i=u+1;i<d;i++) /* output border line in background area */

{

gotoxy(l,i);

cprintf("%c",179); /* vertical line */

gotoxy(r,i);

cprintf("%c",179);

}

for(i=l+1;i<r;i++)

{

gotoxy(i,u);

cprintf("%c",196); /* horizontal line**

gotoxy(i,d);

cprintf("%c",196);

}

gotoxy(l,u);

cprintf("%c",218);/* upper left corner**

gotoxy(r,u);<

cprintf("%c",191);/* top right corner*/

gotoxy(l,d);

cprintf("%c",192);/* bottom left corner*/

gotoxy(r,d);

cprintf("%c",217); /* rownodeptr *R,pformateptr *P,operationptr *C,editptr *E)

{

gettext(1,1,80,25,save);/*Save the masked area**

BlackText(n,1,ml[n]. name);/* Inverse selection to show main menu */

DrawFrame(3+20*n-1,2,3+20*n+19,3+ml[n].n,0,7);/* Border for dropdown menu */

for(i=3;i<3+ml[n].n;i++)/* Output each option of selected menu */

{

if(i==3)

BlackText(n,i,ml[n].str[i-3]);/* Default to the first selected item */

else

RedText(n,i,ml[n].str[i-3]);/* First character of the rest of the items is shown in red */

}

The first character of each item is shown in red.

}

gotoxy(79,1);

MoveMl(n,3,L,R,P,C,E);/* control of the menu options */

}

//* control of the menu options, n determines the horizontal items, x determines the drop down options */

void MoveMl( int n,int x,charnodeptr *L,rownodeptr *R,pformateptr *P,operationptr *C,editptr *E)

{

int flag=1;

while(flag)

{

gotoxy(79,1);

key=bioskey(0);/*receive key presses**

gotoxy(79,1);

switch(key)

{

case ESC:/*exit the loop**

puttext (1,1,80,25,save);/* restore what it looked like before opening the menu**

flag=0;

break;

case LEFT:/* move to the left option**

puttext(1,1,80,25,save);/* restore what it looked like before opening the menu**

if ESC:/* move to the left option**

puttext(1,1,80,25,save);/* restore what it looked like before opening the menu**

if ESC:/* move to the left option*

if(n==0)/* move to the last option if you move left out of bounds**

DrawMl(2,L,R,P,C,E);

else

DrawMl(n-1,L,R,P,C,E);

flag=0;

break;< /p>

case RIGHT:/* move right option */

puttext(1,1,80,25,save);/* restore what it looked like before opening the menu */

if(n==2)/* move to the first option if it crosses the line to the right */

DrawMl(0,L,R,P,C. E);

else

DrawMl(n+1,L,R,P,C,E);

flag=0;

break;

case UP:/* move up to the specific option */

RedText(n,x,ml[n].str[x-3]) .str[x-3];/* output red font */

if(x==3)/* move to the top and press up again, it moves to the bottom */

x=3+ml[n].n-1;

else

x--;/* move to the new one to be displayed */

BlackText(n,x,ml[n]. .str[x-3]);/* output black font */

flag=1;

break;

case DOWN:/* specific option to move down */

RedText(n,x,ml[n].str[x-3]);

if(x==(3+ml[ n].n-1))/* move to the bottom and press the key again to move to the top*/

x=3;

else

x++;/* move to the new one to be displayed*/

BlackText(n,x,ml[n].str[x-3]);

flag=1;

break;

case ENTER:

puttext(1,1,80,25,save);/* Restore what it looked like before the menu was opened */

Enter(n,x-3,L,R,P,C,E);/* Specific function of menu option */

flag=0;< /p>

break;

}

gotoxy(79,1);

}

}

/*Specific function of menu options*/

void Enter(int m,int n,charnodeptr *L,rownodeptr *R. pformateptr *P,operationptr *C,editptr *E)

{

switch(m)

{

case 0:switch(n)

{

case 0:Openfile(L,R,P,C ,E);break; /*Open an existing file*/

case 1:Newfile(L,R,P,C,E);break; /*Create a file*/

case 2:Savefile(L);break; /*Save the current operation and the file*/

case 3. Writeto(L); /*Save As*/

case 4:Exit(L); /*Exit the system*/

} break;

case 1: switch(n)

{

case 0: cut(L,R,P,C,E);break; /*cut*

case 1: switch(n)

{

case 0: cut(L,R,P,C,E);break; /*Cut

case 1: copy(L,R,P,C,E);break; /*copy*/

case 2: paste(L,R,P,C,E);break; /*paste*/

case 3:find(L,R,P,C,E);break; /*find*/

< p> case 4:replace(L,R,P,C,E);break; /*replace**

}break;

case 2:switch(n) /*Help menu option selected*

{

case 0:Help();break;

case 1:Ver();

}

}/*End outside switch**

}

//This is part of the program, if you want the full example program, let me know the email address and I'll send it to you.