• ncurses简单的一个多窗体程序


    #include <ncurses.h>
    #include <string.h>
    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    
    void* head_refresh(void *arg);
    void* input_refresh(void *arg);
    void* output_refresh(void *arg);
    void* right_refresh(void *arg);
    class window
    {
            friend void* head_refresh(void *arg);
            friend void* input_refresh(void *arg);
        friend void* output_refresh(void *arg);
        friend void* right_refresh(void *arg);
        public:
        window()
        {
        initscr();
    
        getmaxyx(stdscr,y,x);
        }
        void create_head()
        {
        head_window = newwin(4,x,0,0);
        box(head_window,'.','.');
        mvwprintw(head_window,4/2,x/3,"|Welcome to here|");
        }
        void _refresh(WINDOW *win)
        {
           wrefresh(win);
           wgetch(win);
        }
        void create_input()
        {
         input_window = newwin(y-5,x/2,5,0);
         box(input_window,'.','.');
         mvwprintw(input_window,1,0,"input:");
        }
        void create_output()
        {
         output_window = newwin((y-5)/2,x/2,5+(y-5)/2+1,x/2);
         box(output_window,'.','.');
         mvwprintw(output_window,1,0,"output:");
        }
    
        void create_right()
        {
         right_window = newwin((y-5)/2,x/2,5,x/2);
         box(right_window,'.','.');
         mvwprintw(right_window,1,0,"friend:");
        }
    
        ~window()
        {
        endwin();
        }
    
        private:
        WINDOW *head_window;
        WINDOW *input_window;
        WINDOW *output_window;
        WINDOW *right_window;
        int x;
        int y;
    };
    
    void* head_refresh(void *arg)
    {
        window *win = (window*)arg;
    
            win->_refresh(win->head_window);
    
        return NULL;
    }
    
    void* input_refresh(void *arg)
    {   
        window *win = (window*)arg;
        win->_refresh(win->input_window);
        return NULL;
    }
    
    
    void* output_refresh(void *arg)
    {   
        window *win = (window*)arg;
        win->_refresh(win->output_window);
        return NULL;
    }
    void* right_refresh(void *arg)
    {   
        window *win = (window*)arg;
        win->_refresh(win->right_window);
        return NULL;
    }
    
    int main()
    {
        window win;
        win.create_head();
        win.create_input();
        win.create_output();
        win.create_right();
        pthread_t head_id,input_id,output_id,right_id;
    
        pthread_create(&head_id,NULL,head_refresh,(void *)&win);
        pthread_create(&input_id,NULL,input_refresh,(void *)&win);
        pthread_create(&output_id,NULL,output_refresh,(void *)&win);
        pthread_create(&right_id,NULL,right_refresh,(void *)&win);
    //由于终端无法同步刷新。所以使用多个线程来进行刷新,能够满足
    //同一时候显示多个窗体的需求。
        pthread_join(head_id,NULL);
        pthread_join(input_id,NULL);
        pthread_join(output_id,NULL);
        pthread_join(right_id,NULL);
    
        getch();
        return 0;
    }

    这里写图片描写叙述

  • 相关阅读:
    Linux Shell中管道的原理及C实现框架
    标准文件描述符与标准文件句柄
    Makefile:如何写目标依赖
    CODING 携手优普丰,道器合璧打造敏捷最佳实践
    CODING 邀您参与品牌认知度调查 赢得机会领取猴子抱枕好礼
    敏捷,持续集成/持续交付, DevOps 三者的区别
    从 IT 到 DevOps 实践
    腾讯云大学 x CODING | 远程协作办公新模式
    共同战“疫”,CODING 帮助研发团队高效协同
    研发团队远程办公——如何应用硬核工具无间协作?
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7255410.html
Copyright © 2020-2023  润新知