- 论坛徽章:
- 3
|
在字符界面中动态显示时间(操作界面,不是监控界面)
# include <curses.h>;
# include <signal.h>;
# include <time.h>;
# include <term.h>;
void disp_curtime()
{
保存当前光标位置;
#ifdef M_TERMINFO
// set cursor off;
cur_term->;_cursorstate = 0;
setcurterm(cur_term);
#endif
得到当前日期和时间;
在屏幕的某一个位置显示日期和时间;
#ifdef M_TERMINFO
// set cursor on;
cur_term->;_cursorstate = 1;
setcurterm(cur_term);
#endif
恢复保存的光标位置;
}
int GetKey()
{
int rc;
while ( TRUE ) {
signal(SIGALRM, disp_curtime);
alarm(1);
rc = getch();
signal(SIGALRM, SIG_DFL);
alarm(0);
if ( rc >;= 0 ) break;
}
return(rc);
}
这样你在程序中,可以用GetKey()代替getch(), 程序运行时,等候操作过程中就会实时显示时间。 |
|