#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{Friendvoid*Head_refresh (void *ARG); Friendvoid*Input_refresh (void *ARG); Friendvoid*Output_refresh (void *ARG); Friendvoid*Right_refresh (void *ARG); Public: Window () {INITSCR (); Getmaxyx (STDSCR,Y,X); }voidCreate_head () {Head_window=Newwin (4X0,0); Box (Head_window,'. ','. '); MVWPRINTW (Head_window,4/2, x/3,"| Welcome to Here| "); }void_refresh (WINDOW*Win) {Wrefresh (win); Wgetch (Win); }voidCreate_input () {Input_window=Newwin (y-5, x/2,5,0); Box (Input_window,'. ','. '); MVWPRINTW (Input_window,1,0,"Input:"); }voidCreate_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:"); }voidCreate_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);//Because the terminal cannot synchronize refreshes, the refresh is done using multiple threads to satisfy//The need to display multiple windows at the same time. Pthread_join (head_id,NULL); Pthread_join (input_id,NULL); Pthread_join (output_id,NULL); Pthread_join (right_id,NULL); Getch ();return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ncurses Simple one multi-window program