Thread: menu with conio.h help needed

  1. #1
    Registered User Solarwin's Avatar
    Join Date
    Dec 2012
    Posts
    50

    Exclamation menu with conio.h help needed

    Hey guys,
    I am trying to make cool main menu,but i am not sure how to do this correctly.
    so i am trying to make something like this:

    at the start:

    --> Start
    How to play
    Exit

    after clicked down arrow:

    Start
    --> How to play
    Exit

    after clicked down arrow twice:

    Start
    How to play
    --> Exit
    I hope you get the point. ;)
    This is what i have done so far:

    Code:
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
        int option;
        cout<<"    Menu:"<<endl;
              cout<<'\t'<<"--> "<<"  Start"<<endl;
              cout<<'\t'<<"     How to play"<<endl;
              cout<<'\t'<<"     Exit"<<endl;
    
    
        while( option != 27){
        option = getch();
    
        switch(option){
        case 80:
           cout<<" --> "<<"  How to play"<<endl;
        break;
        case 72:
            cout<<"  - "<<endl;
        break;
        case 27:
        cout<<"  - "<<endl;
        break;
        }
    }
        return 0;
    }

    Hope for help, Thanks in advance! ;)

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So keep track of where your arrow is and when a down arrow is pressed change the position and redraw the screen.

    I have no idea what character code (if any) you'll get from down arrow and don't want to know, but presumably documentation may still exist for getch.

    (EDIT: I feel like I must for form's sake say "conio????????????????" so there you go.)

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    I did something like this a long while back (the option pointed to by the arrow was also changed to red), but it was in 'C' (and completely non-portable).

    Rather than hard coding it like you did, I created a function to print the menu items. I also passed a code to that function to indicate the currently "highlighted" option. In that function, I printed something before each menu item. For the non-highlighted options, I just printed four spaces. For the highlighted option, I printed " -> ".

    Each time an arrow key is pressed, I would increment/decrement (or wrap around) the value of the option to highlight, then simply call the function again.

    If you need information on using the arrow keys, check the FAQ.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu Driven Array of Function Pointers Calculator, Help Needed
    By SarahDaniella in forum C Programming
    Replies: 4
    Last Post: 05-13-2013, 09:18 PM
  2. C++ menu - help needed
    By dlf in forum C++ Programming
    Replies: 3
    Last Post: 11-17-2005, 05:06 PM
  3. DevC++ accepts neither "conio.h" nor "conio.c"
    By Nutshell in forum C Programming
    Replies: 9
    Last Post: 01-18-2003, 04:35 AM
  4. How to modify a menu into a menu Folder(contains submenus) ??
    By L.O.K. in forum Windows Programming
    Replies: 3
    Last Post: 01-09-2003, 02:26 PM
  5. Conio.h
    By Seal in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2002, 11:26 AM

Tags for this Thread