Results 1 to 10 of 10

Thread: CONIO.H alternative for Dev-C++ IDE Users

  1. #1
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default CONIO.H alternative for Dev-C++ IDE Users

    I've noticed that the standard conio.h for Dev-C++ doesn't include gotoxy() and other functions that are in relation to such. Here is an alternative to conio.h that I came up with for those of you Dev-C++ users:

    Code:
    #ifndef _ALT_CONIO_H_
    #define _ALT_CONIO_H_
    
    #include "windows.h"
    #include "conio.h"
    #include "time.h"
    
    #define WIN_32_LEAN_AND_MEAN
    
    #define BLACK           0
    #define DARK_BLUE       1
    #define GREEN           2
    #define TURQUOISE       3
    #define DARK_RED        4
    #define PURPLE          5
    #define FOREST_GREEN    6
    #define LIGHT_GRAY      7
    #define GRAY            8
    #define BLUE            9
    #define LIGHT_GREEN    10
    #define LIGHT_BLUE     11
    #define RED            12
    #define PINK           13
    #define YELLOW         14
    #define WHITE          15
    #define STDALERT      140
    #define STDHEADER     143
    #define STDBACKGROUND 159
    
    #define _NOCURSOR       0
    #define _SOLIDCURSOR    1
    #define _NORMALCURSOR   2
    
    #define LEFT            0
    #define CENTER          1
    #define RIGHT           2
    
    void gotoxy(int x,int y);
    void setx(int x);
    void sety(int y);
    void setcolor(unsigned short color);
    void delay(unsigned long milisec);
    void setcursor(int ctype);
    void clrscr(void);
    int getx(void);
    int gety(void);
    int align(int align, char str[]);
    
    void gotoxy(int x,int y)
    {
    setx(x);
    sety(y);
    }
    
    void setx(int x)
    {
    COORD pos;
    pos.X = x;
    pos.Y = gety();
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    }
    
    void sety(int y)
    {
    COORD pos;
    pos.X = getx();
    pos.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    }
    
    void setcolor(unsigned short int color)
    {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
    }
    
    void delay(unsigned long int milisec)
    {
    clock_t start,end,loop;
    
    start = clock();
    end = (start+milisec);
    
    do {
        loop = clock();
    } while(loop<end);
    }
    
    void setcursor(int ctype) 
    {
    CONSOLE_CURSOR_INFO type;
    switch(ctype)
    {
        case _NOCURSOR:
        type.bVisible = false;
        break;
        case _SOLIDCURSOR:
        type.dwSize = 100;
        type.bVisible = true;
        break;
        case _NORMALCURSOR:
        type.dwSize = 1;
        type.bVisible = true;
        default:
        type.dwSize = 1;
        type.bVisible = true;
        break;
    }
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&type);
    }
    
    void clrscr(void)
    {
    CONSOLE_SCREEN_BUFFER_INFO window;
    setcolor(WHITE);
    for(int y = 0; y < window.dwSize.Y; y++)
    {
        for(int x = 0; x < window.dwSize.X; x++)
        {
            gotoxy(x,y);printf(" ");
        }
    }
    }
    
    int getx(void)
    {
    CONSOLE_SCREEN_BUFFER_INFO window;
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &window);
    return window.dwCursorPosition.X;
    }
    
    int gety(void)
    {
    CONSOLE_SCREEN_BUFFER_INFO window;
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &window);
    return window.dwCursorPosition.Y;
    }
    
    int align(int align, char str[])
    {
    int x;
    switch(align)
    {
    case 0:
    x = (0);
    break;
    case 1:
    x = (40-(strlen(str)/2));
    break;
    case 2:
    x = (79-(strlen(str)));
    break;
    default:
    printf("ERROR:\nalign(int align, char str[]) aborted.\nERROR CAUSE:\nnon-feasible parameter number in int align detected.");
    getche();
    exit(0);
    break;
    }
    if(strlen(str) > 79) {
    printf("ERROR:\nalign(int align, char str[]) aborted.\nERROR CAUSE:\nnon-feasible parameter number in int align detected."); 
    exit(0);
    }
    else {
    gotoxy(x,gety());printf("%s",str);
    }
    }
    
    #endif
    It is only 4KB large!! Hope this helps with everyday programming!

    -magicyte

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    b u m p
    Last edited by magicyte; 10-26-2008 at 12:55 AM.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, it is forbidden. As punishment, you are hereby forbidden from coding until you learn to indent properly.

    In seriousness... it seems nobody's interested, so don't keep bumping. Most people don't code for the console in Windows. Those that do are probably *nix developers working with mingw32 anyway.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Yup. That's me. Sure. Won't bump THIS one any more. Anyway, can you teach me how to indent properly? Please! Also, what is a 'nix' developer?

    -magicyte

  5. #5
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    EDIT:

    Code:
    #ifndef __ALT_CONIO_H__
    #define __ALT_CONIO_H__
    
    /*
      Name: alt.h [Alternative Conio]
      Copyright: 2008
      Author: Arthur Christopher Watkins
      Date: 26/10/08 21:14
      Description: Alternative conio.h
      file for Dev-C++ users
      Version: 1.0
    */
    
    void gotoxy(int x,int y);
    void setx(int x);
    void sety(int y);
    void setcolor(unsigned short color,unsigned short bg);
    void delay(unsigned long milisec);
    void setcursor(int ctype);
    void clrscr(void);
    int getx(void);
    int gety(void);
    int assert(int x);
    #ifndef ALT_OUTPUT
    int print(const char *x);
    #endif
    char getc(int kc);
    int align(int align,const char *str);
    
    #include "windows.h"
    #include "conio.h"
    #include "time.h"
    
    #define WIN_32_LEAN_AND_MEAN
    
    #define KEY_HOME   71
    #define KEY_UP     72
    #define KEY_PGUP   73
    #define KEY_LEFT   75
    #define KEY_CENTER 76
    #define KEY_RIGHT  77
    #define KEY_END    79
    #define KEY_DOWN   80
    #define KEY_PGDN   81
    #define KEY_INSERT 82
    #define KEY_DELETE 83
    #define KEY_F1     59
    #define KEY_F2     60
    #define KEY_F3     61
    #define KEY_F4     62
    #define KEY_F5     63
    #define KEY_F6     64
    #define KEY_F7     65
    #define KEY_F8     66
    #define KEY_F9     67
    #define KEY_SPC    32
    #define KEY_BACKSPACE 8
    #define KEY_TAB     9
    #define KEY_ENTER  13
    #define KEY_ESC    27
    
    #define LEFT   0
    #define CENTER 1
    #define RIGHT  2
    
    #define _NOCURSOR     0
    #define _SOLIDCURSOR  1
    #define _MEDIUMCURSOR 2
    #define _NORMALCURSOR 3
    
    #ifdef ALT_OUTPUT
    #define write(x) printf(x)
    #else
    #define write(x)
    #endif
    
    enum colors { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, GRAY, LIGHTBLUE, LIGHTGREEN, TURQUOISE, LIGHTRED, PINK, YELLOW, WHITE };
    
    union k
    {
          char c;
          int i;
    } key;
    
    void gotoxy(int x,int y)
    {
         setx(x);
         sety(y);
    }
    
    void setx(int x)
    {
         COORD pos;
         pos.X = x;
         pos.Y = gety();
         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    }
    
    void sety(int y)
    {
         COORD pos;
         pos.X = getx();
         pos.Y = y;
         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    }
    
    void setcolor(unsigned short int color,unsigned short int bg)
    {
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),((bg*16)+(color)));
    }
    
    void delay(unsigned long int milisec)
    {
         clock_t start,end,loop;
         start = clock();
         end = (start+milisec);
         
         do {
             loop = clock();
         } while(loop<end);
    }
    
    void setcursor(int ctype)
    {
         CONSOLE_CURSOR_INFO type;
         switch(ctype)
         {
                      case _NOCURSOR:
                           type.bVisible = 0;
                           break;
                      case _SOLIDCURSOR:
                           type.dwSize = 100;
                           type.bVisible = 1;
                           break;
                      case _MEDIUMCURSOR:
                           type.dwSize = 50;
                           type.bVisible = 1;
                           break;
                      case _NORMALCURSOR:
                           type.dwSize = 1;
                           type.bVisible = 1;
                           break;
                      default:
                           type.dwSize = 1;
                           type.bVisible = 1;
                           break;
         }
         SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&type);
    }
    
    void clrscr()
    {
         COORD pos;
         COORD cs = { 0, 0 };  
         DWORD written;
         CONSOLE_SCREEN_BUFFER_INFO window;
         pos.X = 0;
         pos.Y = 0;
         GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&window);
         FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE),' ',window.dwSize.X*window.dwSize.Y,cs,&written);
         gotoxy(0,0);
    }
    
    int getx(void)
    {
        CONSOLE_SCREEN_BUFFER_INFO window;
        GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&window);
        return window.dwCursorPosition.X;
    }
    
    int gety(void)
    {
        CONSOLE_SCREEN_BUFFER_INFO window;
        GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&window);
        return window.dwCursorPosition.Y;
    }
    
    int assert(int x)
    {
        if(!(x)) return 1;
        else if(x) return 0;
    }
    
    #ifndef ALT_OUTPUT
    int print(const char *x)
    {
        printf("%s",x);
    }
    #endif
    
    char getc(int kc)
    {
         key.i = kc;
         key.c = (char)key.i;
         return key.c;
    }
    
    int align(int align,const char *str)
    {
    int x;
    switch(align)
    {
    case 0:
    x = (0);
    break;
    case 1:
    x = (40-(strlen(str)/2));
    break;
    case 2:
    x = (80-(strlen(str)));
    break;
    default:
    return 1;
    break;
    }
    if(strlen(str) > 79) {
    }
    else {
    gotoxy(x,gety());printf("%s",str);
    }
    }
    
    #endif
    -magicyte

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    *nix is a common term for 'anything UNIXy' — GNU, BSD, AIX, Solaris, &c.

    Indentation is quite simple: indent one 'tab' for each new block you enter. If you get a good editor, it'll even do it for you.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    I have a bad editor that does it for me and it is bad... Dev-C++... Yeah.

    I == PC
    I != UNIX

    I use the 4.9.9.2 beta version of Dev-C++. Fairly new, 'tis.

    -magicyte

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I really do, and always have, recommended switching to Linux for new programmers. Most APIs developed by Microsoft, especially the low-level ones, are utter beasts to manage, and the system doesn't lend itself well to investigation and study.

    As for your editor, I strongly suggest emacs, or XEmacs for Windows.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Okay. I've always wanted to do this. I will respond to you in JavaScript!!

    Code:
    <script type="text/javascript">
    var i = "magicyte";
    var UNIX = "operating system";
    var MAC = "operating system";
    var TOO_MUCH = "cannot buy now...";
    var why_use_a_unix_or_mac_instead_of_windows = 1;
    var compiler = 0;
    var microsoft = 1;
    var bloodshed = 0;
    
    if(i != UNIX && i == TOO_MUCH) {
    alert(what_do_I_do_q());
    }
    else if(i != MAC /* or whatever you said */ && i == TOO_MUCH) {
    alert(what_do_I_do_q());
    }
    
    function what_do_I_do_q() {
    return "What do I do???";
    }
    
    eval("tellim()");
    
    function tellim() {
    return "for(dev = compiler; dev != microsoft, dev == bloodshed; dev++);";
    }
    
    eval("doiteth()");
    
    function doiteth() {
    return "(why_use_a_unix_or_mac_instead_of_windows) ? alert(because('list')) : alert(because('list'));
    }
    
    function because(para) {
    return para;
    }
    </script>
    Please report any errors with my script.

    -magicyte

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    From what I can see, mismatched quotes and eval() usage
    Code:
    var OSAdvocacy = {
      OS: function(name, price) {
        this.name = name;
        this.price = price;
      },
    
      Person: (function() {
        function Person(name, funds) {
          this.name = name;
          this.funds = funds;
        }
    
        Person.prototype = {
          canGet: function(os) {
            return os.price <= this.funds;
          },
    
          shouldGet: function(os, hasReason) {
            return (hasReason || !os.isPants) && this.canGet(os);
          },
    
          get: function(os) {
            alert(this.name + ", go and get a copy of " + os.name + " already!");
          }
        };
      })(),
    
      compiler: 1,
    
      development: 3
    };
    
    (function() {
      var linux    = new OSAdvocacy.OS("GNU/Linux", 0),
          magicyte = new OSAdvocacy.Person("magicyte", 0),
          reason   = (development & compiler) < development;
    
      if (magicyte.shouldGet(linux, reason))
        magicyte.get(linux);
    })();
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •