Thread: Console applications interface

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    48

    Console applications interface

    Hi everyone, i'm developing a simple application wich will interact with a database, adding, changing and deleting records of it. I want to create a friendly and intuitive interface to allow users doing that. I've seen applications that user can jump from and to an option using tab key, and instead of textboxes data is entered in a line fill with ........................... I hope you can understand what i'm looking for, i don't know if it was a fine explanation.
    Regards.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    You are probably looking for Curses, also called NCurses.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    48
    That's what i'm looking for. I'm developing this software for windows platform, I also have read that conio.h is the file wich replace curses.h for windows. But I'm using dev-c++ and conio.h only have a few definitions and I may not be able to get all functionality of it. So, is there another way to do it?

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    1
    Hi . You have to include windows.h and use console API

    See http://msdn2.microsoft.com/en-us/lib...73(VS.85).aspx

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you want to use curses, there is a library called pdcurses that works with Windows.

    Otherwise, the native Windows console API functions as linked to above will do these sort of things, probably requiring a bit of wrapping them into more suitable functions for your application, e.g. you may want a function that reads a string of certain length from a specific location on the screen:
    Code:
    // Return 0 on success, otherwise non-zero. 
    int readStringXY(int x, int y, char *str, size_t maxlen, const char *allowedChars);
    The last argument, allowedchars, is used to tell the function for example to only accept digits for reading an integer (and perhaps '-', '+', 'e', '.' for a float) - you can then wrap up a function like this:
    Code:
    // Returns 1 on invalid number, 0 on valid. 
    int checkValidNumber(const char *buf, int *value, int min, int max)
    {
        char *ptr;
        *value = strtol(buf, 0, &ptr);
        if (*ptr) return 1;  // Last char parsed is not NUL - we didn't accept the whole string.
        if (*value > max || *value < min) return 1;
        return 0;
    }
    
    // Return 0 on success. 
    int readIntXY(int x, int y, int *value, size_t ndigits, int min, int max)
    {
         char buf[12];
         if (ndigits == 0 || ndigits > 11) ndigits = 11;
         sprintf(buf, "%d", *value);
         do {
            readStringXY(x, y, buf, ndigits, "0123456789"); 
         } while(checkValidNumber(buf, value, min, max)); 
         return 0;
    }
    You will probably also find yourself adding a function pointer to check the validity for special cases (social security number or such, post/zip-code, telephone numbers, etc, etc). Something like this:
    Code:
    typedef int (*CheckFunc)(const char *buf);
    int readStringXYCheck(int x, int y, char *buf, size_t maxlen, const char *allowedChars, CheckFunc checkfunc)
    {
        do
        {
            readStringXY(x, y, buf, maxlen, allowedchars);
        } while(checkfunc(buf));
        return 0;
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    48
    Thank you guys. That's just what I was looking for.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    48
    I have a new problem. Windows.h file from Dev-C++ compilator doesn't have defined any function mentioned above. I don't have any trouble to change to another compilator, but what will be the best choice, if I also need to work with databases (so, sql.h need to have all required functions definition)?

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Yes, you'll probably have to install the libraries/headers for your compiler -- go to the pdcurses website.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console to interface
    By PAragonxd in forum C++ Programming
    Replies: 1
    Last Post: 08-09-2008, 02:35 PM
  2. Adding interface to Win32 console application
    By motiz in forum Windows Programming
    Replies: 5
    Last Post: 01-03-2008, 03:17 AM
  3. Console User Interface : A Project
    By ra21vi in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-01-2006, 01:41 PM
  4. Using .NET for console applications
    By neandrake in forum C++ Programming
    Replies: 4
    Last Post: 11-23-2004, 08:49 PM