Thread: menu with text

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    Post menu with text

    Hi,

    I am trying to make a program that displays a heading at the top center of the screen that says my name in blue, underneath that i am trying to put a menu with the options view, delete record, insert record. I got far as to use gotoxy with printf but i cannot figure the rest out.

    Do you know what the code is?

    Thank you

    Kendals
    Kendals

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    Here is some code ...which I use for my purposes ....
    U can modify it for Ur needs ...
    Works on DOS platform .....

    - Venu Gopal.

    int color;

    // Length of Help Menu items should be 80 ...
    menu_box(int c,int r,int fc,int bc,int br,int tc,int ac,int n,int l,char * title,char * menu,int w,int h,char * th,int centre)
    {
    char ch;
    int i,j,k,z;
    int cho,precho=1,maxcho,pcho=1;
    char far * scr=(char far *)0xb8000000;
    maxcho=n;color=0;
    r--;c--;
    // erase menu area
    for(i=c;i<=c+w;i++)
    for(j=r;j<=r+h;j++)
    {
    *(scr+(j*80+i)*2)=' ';
    *(scr+(j*80+i)*2+1)=bc*16+fc;
    }
    // border
    *(scr+(r*80+c)*2)=218;
    *(scr+(r*80+c)*2+1)=(char )bc*16+br;
    for(i=c+1;i<c+w;i++)
    {
    *(scr+(r*80+i)*2)=196;
    *(scr+(r*80+i)*2+1)=(char )bc*16+br;
    }
    *(scr+(r*80+c+w)*2)=191;
    *(scr+(r*80+c+w)*2+1)=(char )bc*16+br;

    for(i=r+1;i<r+h;i++)
    {
    *(scr+(i*80+c)*2)=179;
    *(scr+(i*80+c)*2+1)=(char )bc*16+br;
    *(scr+(i*80+c+w)*2)=179;
    *(scr+(i*80+c+w)*2+1)=(char )bc*16+br;
    }
    *(scr+(i*80+c)*2)=192;
    *(scr+(i*80+c)*2+1)=(char)bc*16+br;
    for(i=c+1;i<c+w;i++)
    {
    *(scr+((r+h)*80+i)*2)=196;
    *(scr+((r+h)*80+i)*2+1)=(char)bc*16+br;
    }
    *(scr+((r+h)*80+c+w)*2)=217;
    *(scr+((r+h)*80+c+w)*2+1)=(char)bc*16+br;
    for(i=c+2;i<=c+w+1;i++)
    {
    *(scr+((r+h+1)*80+i)*2)=32;
    *(scr+((r+h+1)*80+i)*2+1)=(char)0;
    }
    for(i=r+1;i<=r+h+1;i++)
    {
    *(scr+(i*80+c+w+1)*2)=32;
    *(scr+(i*80+c+w+1)*2+1)=(char)0;
    *(scr+(i*80+c+w+2)*2)=32;
    *(scr+(i*80+c+w+2)*2+1)=(char)0;
    }
    k=strlen(title);
    i=c+w/2-k/2;
    for(j=0;j<k;j++)
    {
    *(scr+(r*80+i)*2)=title[j];
    *(scr+(r*80+i)*2+1)=(char)bc*16+tc;
    i++;
    }
    //r++;c++;
    for(i=0;i<n;i++)
    {
    k=r+2+i;
    j=0;
    if (centre==0) z=c+2;
    else
    {
    z=c+w/2-(strlen(menu+i*l))/2;
    }
    while(*(menu+i*l+j)!=0)
    {
    *(scr+(k*80+z+j)*2)=*(menu+i*l+j);
    *(scr+(k*80+z+j)*2+1)=bc*16+fc;
    j++;
    }
    }
    ch=0;
    dbl("Use Arrows to select item & ENTER to confirm.");
    while((ch!=27)&&(ch!=13))
    {
    for(j=0;j<=w-2;j++) *(scr+((r+2+pcho-1)*80+c+1+j)*2+1)=bc*16+fc;
    for(j=0;j<=w-2;j++) *(scr+((r+2+precho-1)*80+c+1+j)*2+1)=ac*16+fc;
    dbl((th+(precho-1)*80));
    ch=getch();
    if (ch==0) ch=getch();
    switch(ch)
    {
    case 72:
    case 75:
    pcho=precho;
    precho=precho-1;
    break;
    case 77:
    case 80:
    pcho=precho;
    precho=precho+1;
    break;
    case 13:
    case 27:
    break;
    default:sound(300);delay(100);nosound();
    }
    if (precho<1) precho=maxcho;
    if (precho>maxcho) precho=1;
    }
    color=4;
    if (ch==13) return(precho);
    else return(-1);
    }



    box(int c,int r,int w,int h,int fc,int bc,int br,int tc,char * title,int s)
    {
    int i,j,k;
    char far * scr=(char far *)0xb8000000;

    r--;c--;
    // erase box area
    for(i=c;i<=c+w;i++)
    for(j=r;j<=r+h;j++)
    {
    *(scr+(j*80+i)*2)=' ';
    *(scr+(j*80+i)*2+1)=bc*16+fc;
    }
    // border
    *(scr+(r*80+c)*2)=201;
    *(scr+(r*80+c)*2+1)=(char )bc*16+br;
    for(i=c+1;i<c+w;i++)
    {
    *(scr+(r*80+i)*2)=205;
    *(scr+(r*80+i)*2+1)=(char )bc*16+br;
    }
    *(scr+(r*80+c+w)*2)=187;
    *(scr+(r*80+c+w)*2+1)=(char )bc*16+br;

    for(i=r+1;i<r+h;i++)
    {
    *(scr+(i*80+c)*2)=186;
    *(scr+(i*80+c)*2+1)=(char )bc*16+br;
    *(scr+(i*80+c+w)*2)=186;
    *(scr+(i*80+c+w)*2+1)=(char )bc*16+br;
    }
    *(scr+(i*80+c)*2)=200;
    *(scr+(i*80+c)*2+1)=(char)bc*16+br;
    for(i=c+1;i<c+w;i++)
    {
    *(scr+((r+h)*80+i)*2)=205;
    *(scr+((r+h)*80+i)*2+1)=(char)bc*16+br;
    }
    *(scr+((r+h)*80+c+w)*2)=188;
    *(scr+((r+h)*80+c+w)*2+1)=(char)bc*16+br;
    if (s==1)
    {
    for(i=c+2;i<=c+w+1;i++)
    {
    *(scr+((r+h+1)*80+i)*2)=32;
    *(scr+((r+h+1)*80+i)*2+1)=(char)0;
    }
    for(i=r+1;i<=r+h+1;i++)
    {
    *(scr+(i*80+c+w+1)*2)=32;
    *(scr+(i*80+c+w+1)*2+1)=(char)0;
    *(scr+(i*80+c+w+2)*2)=32;
    *(scr+(i*80+c+w+2)*2+1)=(char)0;
    }
    }
    k=strlen(title);
    i=c+w/2-k/2;
    for(j=0;j<k;j++)
    {
    *(scr+(r*80+i)*2)=title[j];
    *(scr+(r*80+i)*2+1)=(char)br*16+tc;
    i++;
    }
    return(0);
    }

    dbl(char * s)
    {
    int i,j=24,k;
    char far * scr=(char far *)0xb8000000;
    for(i=0;i<=80;i++)
    {
    *(scr+(j*80+i)*2)=' ';
    *(scr+(j*80+i)*2+1)=112+color;
    }
    k=strlen(s);
    for(i=0;i<k;i++)
    {
    *(scr+(j*80+40-k/2+i)*2)=s[i];
    }
    return(0);
    }

    bl(int c,char * s)
    {
    int i,j=24,k;
    char far * scr=(char far *)0xb8000000;
    for(i=0;i<=80;i++)
    {
    *(scr+(j*80+i)*2)=' ';
    *(scr+(j*80+i)*2+1)=112+c;
    }
    k=strlen(s);
    for(i=0;i<k;i++)
    {
    *(scr+(j*80+40-k/2+i)*2)=s[i];
    }
    return(0);
    }

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    how do you put that code in?

    Hi i wanted to know how you put that code in?
    what #includes do i need? can you tell me how i would put i so i if i copy the code and paste it in to my complier it will work as i do not understand how to use your code.

    thanks

    kendals
    Kendals

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Do you still want help with a menu style program?
    The world is waiting. I must leave you now.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    Cool yes i still need help

    Yes i still need help, can you help?

    thanks
    Kendals

  6. #6
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    #include <stdio.h>
    #include <<conio.h>
    #include <stdlib.h>
    
    int main()
    {
    char selection;
    repeat_menu:
        clrscr();
        printf("\t\t\t\tKendals\n");
        printf("1 = Menu option 1\n");
        printf("2 = Menu option 2\n");
        // etc
        selection=getch();
        switch(selection)
        {
        case '1':
        // do stuff for case 1
        goto repeat_menu;
        break; // just in case
    
        case '2':
        // same as 1, do stuff, loop it back to beginning
    
        default:
        // user did not choose a valid option, loop
        goto repeat_menu;
        break;
    
        case 27:
        // if the user presses escape, close
        break;
        }
    return 0;
    }
    pc_apocalypse, VortexOfTech on Yahoo! Messenger.
    [email protected]

    I've made a few of these. The one I'm working on, having a projected 10,000 lines of code, I could help with anything I can manage to help with!

    let me know if this helps...
    Last edited by Shadow; 02-20-2002 at 09:36 PM.
    The world is waiting. I must leave you now.

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    Thumbs up thanks, it works

    Hi,

    thanks for your help, i got a c programming book to help me,
    its the sams teach yourself C programming in 21 days.

    thanks again

    Kendals
    Kendals

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  2. URGENT! Menu driven & records handling
    By ravccc in forum C Programming
    Replies: 5
    Last Post: 11-18-2005, 12:52 PM
  3. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  4. Small HTML question
    By Thantos in forum Tech Board
    Replies: 4
    Last Post: 12-29-2003, 12:37 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM