2014-07-08 4 views
1

Ive가 해결책을 찾았으나, 왜 그 창이 보이지 않는지 모르겠다. 코드는 매우 간단하고 간단합니다. 왜 이런 경우입니까? 나는 이전에 비슷한 질문을 던졌지 만 정답을 제시 할 수 있었던 것 같아서 약간의 단순한 느낌을주고 중요한 것들만 포함시켰다.C- Ncurses, 윈도우가 표시되지 않거나 인쇄되지 않는다.

#include <ncurses.h> 
#include <stdio.h> 
#include <stdlib.h> 


int main() 
{ 
    initscr(); 
    WINDOW* win; 
    int height = 10; 
    int width = 40; 
    int srtheight = 1; 
    int srtwidth = 0; 
    win = newwin(height, width, srtheight ,srtwidth); 
    mvwprintw(win, height/2,width/2,"First line"); 
    wrefresh(win); 
    getch(); 
    delwin(win); 
    endwin(); 


    return 0; 
} 

답변

1

당신은 새로 고침 전화를 잊어 버렸습니다.

기본적으로 새로 작성한 창에서 새로 고침을 호출했지만 부모 창을 새로 고치는 것을 잊었으므로 다시 절대로 쓰지 않습니다.

#include <ncurses.h> 
#include <stdio.h> 
#include <stdlib.h> 

int main() 
{ 
    WINDOW* my_win; 
    int height = 10; 
    int width = 40; 
    int srtheight = 1; 
    int srtwidth = 1; 
    initscr(); 
    printw("first"); // added for relative positioning 
    refresh(); // need to draw the root window 
       // without this, apparently the children never draw 
    my_win = newwin(height, width, 5, 5); 
    box(my_win, 0, 0); // added for easy viewing 
    mvwprintw(my_win, height/2,width/2,"First line"); 
    wrefresh(my_win); 
    getch(); 
    delwin(my_win); 
    endwin(); 
    return 0; 
} 

은 예상대로 창을 제공합니다.

1

당신은 newwin()refresh()를 호출해야합니다

win = newwin(height, width, srtheight ,srtwidth); 
refresh(); // <<< 
mvwprintw(win, height/2,width/2,"First line"); 
+0

나는 그것이 (위해 initscr'후') (새로 고침 '호출 생각)'즉이다 핵심 부분이 아니라'newwin()'이후 ... –

+0

좋아, 그래서 당신이 나를 때려 (몇 분 정도); 하지만 적어도 한 번 루트 윈도우를 새로 고침()하면 하위의 wrefresh (...)가 부모를 새로 고침() 할 필요없이 작동하는 것으로 보입니다. –

1

getchstdscr을 새로 고쳐서 이전 줄의 win에 대해 수행 된 새로 고침을 덮어 ​​씁니다. 그 두 줄보다 wgetch(win)이라 불렀다면 효과가 있었을 것입니다. 이처럼

:

#include <ncurses.h> 
#include <stdio.h> 
#include <stdlib.h> 


int main() 
{ 
    initscr(); 
    WINDOW* win; 
    int height = 10; 
    int width = 40; 
    int srtheight = 1; 
    int srtwidth = 0; 
    win = newwin(height, width, srtheight ,srtwidth); 
    mvwprintw(win, height/2,width/2,"First line"); 
    /* wrefresh(win); */ 
    wgetch(win); 
    delwin(win); 
    endwin(); 


    return 0; 
} 

추가 읽기 :