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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-19 01:58:32

ncurses简单的一个多窗口程序的相关文章

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); c

如何用C#做一个悬浮窗口程序

用C#做一个像FlashGet的悬浮窗口,其实很简单,不像以前需要调用很多系统API.大致的步骤如下. 首先是主窗体部分,即要判断窗体的状态来决定是否显示悬浮窗口. 局部成员声明: private FormWindowState fwsPrevious; private frmTopMost myTopMost; 主窗体的Load事件: private void frmMain_Load(object sender, System.EventArgs e) { // Save window st

创建简单的窗口程序

#include <windows.h> /*窗口函数的函数原型*/ LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {     char szClassName[] = "MainWClass";     WND

windows笔记-一个简单的windows GUI应用程序

#include<windows.h> // 编写Windows程序必须包含的头文件 LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); // 声明窗口函数原型 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ HWND hwnd; // 定义窗口句柄 MSG msg; // 定义一个用来存储消息的变量

[MFC]_在vs2019中使用MFC快速构建简单windows窗口程序

微软基础类库(英语: Classes,简称MFC)是微软公司提供的一个类库(class libraries),以C++类的形式封装了Windows API,并且包含一个应用程序框架,以减少应用程序开发人员的工作量.其中包含大量Windows句柄封装类和很多Windows的内建控件和组件的封装类. vs 2019 最新版,在设计上又有了很大的变化,并且其所有的服务,模块都是自定义搭建的,所以在一开始安装的时候,没有勾选mfc模块的话,是无法快速构成mfc应用的. vs2019下MFC模块的安装:

《Python入门》第一个Python Web程序——简单的Web服务器

上一篇讲了<Python入门>Windows 7下Python Web开发环境搭建笔记,接下来讲一下Python语言Web服务的具体实现:第一个Python Web程序--简单的Web服务器. 与其它Web后端语言不同,Python语言需要自己编写Web服务器. 如果你使用一些现有的框架的话,可以省略这一步: 如果你使用Python CGI编程的话,也可以省略这一步: 用Python建立最简单的web服务器 利用Python自带的包可以建立简单的web服务器.在DOS里cd到准备做服务器根目录

简介(1)-概述、一个简单的时间获取客户程序

1.概述 大多数网络应用划分:客户(client)和服务器(server) 一些复杂的网络应用:异步回调通信,即服务器向客户发起请求消息. 协议栈:应用协议.TCP协议.IP协议.以太网协议 局域网(local area network,LAN),广域网(wide area network,WAN). 路由器是广域网的架构设备. 因特网:当今最大的广域网. POSIX:一种被多数厂商采纳的标准. 2.一个简单的时间获取客户程序 1)创建套接字 socket函数 2)指定服务器的IP地址和端口 s

NET简单的一个画图程序

using System; using System.Drawing; //HttpUtility.UrlEncode /// <summary> ///Curve 的摘要说明 /// </summary> public class Curve { public Curve() { // //TODO: 在此处添加构造函数逻辑 // } /*******************************************************属性设置*************

(1)风色从零单排《C++ Primer》 一个简单的c++程序

从零单排<C++ Primer> --(1)一个简单的c++程序 本次学习收获 0.写在前面 风色以前上过C++的课程,然而当时并没有认真去学,基本不能使用c++来作项目开发. 这次又一次学习c++,首先会阅读c++Prime英文版第五版,希望能够为以后的学习打下坚实的基础. 1.程序 一个简单的c++程序(P17),帮助我们高速了解c++的代码风格,并通过分析代码学习c++ 程序意图:在终端上输入一组数字.输出不同数字输出的次数.同样的数字必须是连续的. 如果输入: 42 42 42 42