我用whline(dialogwin,'-',38);画就不连续,用whline(dialogwin,196,38);画出现中文字(哪哪哪哪哪哪哪哪哪哪哪哪),我的系统装有东方龙马,但scoadm的显示十分正常。
---------------------------------------------------------------
转贴自http://www.chinaunix.net/bbsjh/4/7707.html
有人说切换到龙马的西文制表符识别模式下(按Ctrl+Alt+Shift+ESC)
我现在没办法验证
unix中的菜单程序
作者:lcc 发表时间:2002/08/22 03:58pm
[这个贴子最后由lcc在 2002/08/22 04:11pm 编辑]
#include
1<curses.h>
2#include <stdlib.h>
3
4#define ENTER 10
5#define ESCAPE 27
6void init_curses()
7{
8initscr();
9start_color();
10init_pair(1,COLOR_WHITE,COLOR_BLUE);
11init_pair(2,COLOR_BLUE,COLOR_WHITE);
12init_pair(3,COLOR_RED,COLOR_WHITE);
13curs_set(0);
14noecho();
15keypad(stdscr,TRUE);
16}
17void draw_menubar(WINDOW *menubar)
18{
19wbkgd(menubar,COLOR_PAIR(2));
20waddstr(menubar,"Menu1");
21wattron(menubar,COLOR_PAIR(3));
22waddstr(menubar,"(F1)");
23wattroff(menubar,COLOR_PAIR(3));
24wmove(menubar,0,20);
25waddstr(menubar,"Menu2");
26wattron(menubar,COLOR_PAIR(3));
27waddstr(menubar,"(F2)");
28wattroff(menubar,COLOR_PAIR(3));
29}
30WINDOW **draw_menu(int start_col)
31{
32int i;
33WINDOW **items;
34items=(WINDOW **)malloc(9*sizeof(WINDOW *));
35
36items[0]=newwin(10,19,1,start_col);
37wbkgd(items[0],COLOR_PAIR(2));
38box(items[0],ACS_VLINE,ACS_HLINE);
39items[1]=subwin(items[0],1,17,2,start_col+1);
40items[2]=subwin(items[0],1,17,3,start_col+1);
41items[3]=subwin(items[0],1,17,4,start_col+1);
42items[4]=subwin(items[0],1,17,5,start_col+1);
43items[5]=subwin(items[0],1,17,6,start_col+1);
44items[6]=subwin(items[0],1,17,7,start_col+1);
45items[7]=subwin(items[0],1,17,8,start_col+1);
46items[8]=subwin(items[0],1,17,9,start_col+1);
47for (i=1;i<9;i++)
48wprintw(items[i],"Item%d",i);
49wbkgd(items[1],COLOR_PAIR(1));
50wrefresh(items[0]);
51return items;
52}
53void delete_menu(WINDOW **items,int count)
54{
55int i;
56for (i=0;i<count;i++)
57delwin(items[i]);
58free(items);
59}
60int scroll_menu(WINDOW **items,int count,int menu_start_col)
61{
62int key;
63int selected=0;
64while (1) {
65key=getch();
66if (key==KEY_DOWN ¦ ¦ key==KEY_UP) {
67wbkgd(items[selected+1],COLOR_PAIR(2));
68wnoutrefresh(items[selected+1]);
69if (key==KEY_DOWN) {
70selected=(selected+1) % count;
71} else {
72selected=(selected+count-1) % count;
73}
74wbkgd(items[selected+1],COLOR_PAIR(1));
75wnoutrefresh(items[selected+1]);
76doupdate();
77} else if (key==KEY_LEFT ¦ ¦ key==KEY_RIGHT) {
78delete_menu(items,count+1);
79touchwin(stdscr);
80refresh();
81items=draw_menu(20-menu_start_col);
82return scroll_menu(items,8,20-menu_start_col);
83} else if (key==ESCAPE) {
84return -1;
85} else if (key==ENTER) {
86return selected;
87}
88}
89}
90int main()
91{
92int key;
93WINDOW *menubar,*messagebar;
94
95init_curses();
96
97bkgd(COLOR_PAIR(1));
98menubar=subwin(stdscr,1,80,0,0);
99messagebar=subwin(stdscr,1,79,23,1);
100draw_menubar(menubar);
101move(2,1);
102printw("Press F1 or F2 to open the menus. ");
103printw("ESC quits.");
104refresh();
105
106do {
107int selected_item;
108WINDOW **menu_items;
109key=getch();
110werase(messagebar);
111wrefresh(messagebar);
112if (key==KEY_F(1)) {
113menu_items=draw_menu(0);
114selected_item=scroll_menu(menu_items,8,0);
115delete_menu(menu_items,9);
116if (selected_item<0)
117wprintw(messagebar,"You haven't selected any item.");
118else
119wprintw(messagebar,
120"You have selected menu item %d.",selected_item+1);
121touchwin(stdscr);
122refresh();
123} else if (key==KEY_F(2)) {
124menu_items=draw_menu(20);
125selected_item=scroll_menu(menu_items,8,20);
126delete_menu(menu_items,9);
127if (selected_item<0)
128wprintw(messagebar,"You haven't selected any item.");
129else
130wprintw(messagebar,
131"You have selected menu item %d.",selected_item+1);
132touchwin(stdscr);
133refresh();
134}
135} while (key!=ESCAPE);
136
137delwin(menubar);
138delwin(messagebar);
139endwin();
140return 0;
141}
142
143\---------------------------------------------------------------
144
145用ACS字符集就可以,好长时间没搞了,宏名忘掉了
146grep ACS_ /usr/include/*.h
147记得好象有ACS_ULTREE,代表左上字符</stdlib.h></curses.h>