Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I'm been asked to draw buttons within a bordered screen on the screen.I work in a PuttY server.I know its done using ncurses.It would be nice if someone could ...
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    20

    Buttons using C

    Hi,

    I'm been asked to draw buttons within a bordered screen on the screen.I work in a PuttY server.I know its done using ncurses.It would be nice if someone could give me a helping hand.I came up with the following program

    Code:
    #include <stdio.h>
    #include <termios.h>
    #include <unistd.h>
    #include <time.h>
    #include <curses.h>
    
    int current_getch;
    int doloop = 1;
    static WINDOW *mainwnd;
    static WINDOW *screen;
    WINDOW *my_win;
    
    int now_sec, now_min, now_hour, now_day, now_wday, now_month, now_year;
    time_t now;
    struct tm *now_tm;
    
    void screen_init(void)
    {
       mainwnd = initscr();
       noecho();
       cbreak();
       nodelay(mainwnd, TRUE);
       refresh(); // 1)
       wrefresh(mainwnd);
       screen = newwin(13, 27, 1, 1);
       box(screen, ACS_VLINE, ACS_HLINE);
    }
    
    static void update_display(void) {
       curs_set(0);
       mvwprintw(screen,1,1,"-------- HEADER --------");
       mvwprintw(screen,3,6,"TIME: %d:%d:%d", now_hour, now_min, now_sec);
       mvwprintw(screen,5,6,"DATE: %d-%d-%d", now_day, now_month, now_year);
       mvwprintw(screen,7,6,"PRESS q TO END");
       mvwprintw(screen,10,1,"-------- FOOTER --------");
       wrefresh(screen);
       refresh();
    }
    
    void screen_end(void)
    {
       endwin();
    }
    
    void maketime(void) {
            // Get the current date/time
            now = time (NULL);
            now_tm = localtime (&now);
            now_sec = now_tm->tm_sec;
            now_min = now_tm->tm_min;
            now_hour = now_tm->tm_hour;
            now_day = now_tm->tm_mday;
            now_wday = now_tm->tm_wday;
            now_month = now_tm->tm_mon + 1;
            now_year = now_tm->tm_year + 1900;
    }
    
    int main(void)
      {
       screen_init();
       while (doloop)
         {
          current_getch = getch();
          if (current_getch == 113)
            {
             doloop = 0;
            }
          maketime();
          update_display();
          sleep(1);
          }
       screen_end();
       printf("program ended successfully\n");
       return 0;
      }
    This program produices the following output

    ┌─────────────────────────┐
    │-------- HEADER -------- │
    │ │
    │ TIME: 22:50:49 │
    │ │
    │ DATE: 28-8-2009 │
    │ │
    │ PRESS q TO END │
    │ │
    │ │
    │-------- FOOTER -------- │
    │ │
    └─────────────────────────┘


    pardon me for the poor bordering....but how do I modify this program to produce a similar screen with textboxes for Username and Passwords and buttons for Ok and RESET..

    Thanks.

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Posts
    58
    You can either do it in ncurses or you have to use GUI. There is no standard mouse interface that you can write everything for. ncurses does accept mount inputs but it's not very pretty and is a pain.

Posting Permissions

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