New to nCurses here so forgive me the simplicity, but how can I use create a Window trough a function and return this to Main? Below is kind of the idea I am trying to create.
Any tips in this case? Not sure if this a logical way to go.
char createwindow();
int main()
{
initscr();
createwindow(border);
wgetch(border);
endwin();
return 0;
}
char createwindow(char _temp)
{
WINDOW *temp=newwin(30,30,30,30);
box(temp,0,0);
return temp;
}
CodePudding user response:
You can return a pointer to the new window in the same way you can return any other value: Make sure your return value matches return type of your function.
If you want to return a WINDOW*
change your function as follows:
WINDOW *createwindow(char _temp)
{
WINDOW *temp=newwin(30,30,30,30);
box(temp,0,0);
return temp;
}
Then you can store the result of that function in the caller function:
WINDOW *newwindow = createwindow(border);
CodePudding user response:
Found the solution with your tips and did it as follows:
WINDOW* createwindow(); //Prototype function
main()
{
WINDOW *border = createwindow();
}
WINDOW* createwindow()
{
int ymax,xmax;
getmaxyx(stdscr,ymax,xmax);
WINDOW *temp=newwin(ymax-1,xmax-1,1,1);
box(temp,0,0);
return temp;
}