当前位置: 技术问答>linux和unix
unix下的c做图形界面。。。。。。。。
来源: 互联网 发布时间:2015-01-23
本文导语: 各位大狭,我想了解一下在unix平台下面,用c语言怎么做图形界面? 在dos下,c 有各种各样这样的库函数可以用。在unix下是不是也有啊? 另外,在unix下的c语言编程,一般用那种编译器? 幼稚问题,还是望赐教 ...
各位大狭,我想了解一下在unix平台下面,用c语言怎么做图形界面?
在dos下,c 有各种各样这样的库函数可以用。在unix下是不是也有啊?
另外,在unix下的c语言编程,一般用那种编译器?
幼稚问题,还是望赐教
在dos下,c 有各种各样这样的库函数可以用。在unix下是不是也有啊?
另外,在unix下的c语言编程,一般用那种编译器?
幼稚问题,还是望赐教
|
UNIX一般使用X Window窗口系统,最初由MIT开发。
Linux有免费的XFree86
X Windows提供API,即Xlib,可以用来写窗口程序。
但用Xlib写X Window程序就象用Win32 API写Windows程序一样麻烦。
所以很多人用XToolkit或Motif。
这是传统的UNIX窗口应用程序。
Linux有免费的XFree86
X Windows提供API,即Xlib,可以用来写窗口程序。
但用Xlib写X Window程序就象用Win32 API写Windows程序一样麻烦。
所以很多人用XToolkit或Motif。
这是传统的UNIX窗口应用程序。
|
#include /* 引进 curses.h , 并自动引进stdio.h */
#define StartX 1 /* 决定游标初始位置 */
#define StartY 1
void initial();
void main(void)
{
int x=StartX; /* 宣告 x,y 并设定其初值 */
int y=StartY;
int ch; /* 宣告 ch 为整数,配合 getch()使用 */
initial(); /* 呼叫 initial(), 启动 curses 模式, */
/* 并完成其它设定 */
box(stdscr,'|','-'); /* 画方框 */
attron(A_REVERSE); /* 开启反白模式 */
mvaddstr(0,20,"Curses Program"); /* 在 (20,0) 处输出反白字元 */
attroff(A_REVERSE); /* 关闭反白模式 */
move(x,y); /* 将游标移至初始位置 */
do { /* 以无限回圈不断等待输入 */
ch=getch(); /* 等待自键盘输入字元*/
switch(ch) { /* 判断输入字元为何 */
case KEY_UP: --y; /* 判断是否"↑"键被按下
*/
break;
case KEY_DOWN: ++y; /* 判断是否"↓"键被按下
*/
break;
case KEY_RIGHT: ++x; /* 判断是否"→"键被按下
*/
break;
case KEY_LEFT: --x; /* 判断是否"←"键被按下
*/
break;
case 'r': /* 判断是否 ENTER 键被按下
*/
++y;
x=0;
break;
case 't': /* 判断是否 TAB 键被按下
*/
x+=7;
break;
case 127: /* 判断是否 BACKSPACE 键被按下
*/
mvaddch(y,--x,' ');/* delete 一个字元
*/
break;
case 27: endwin(); /* 判断是否[ESC]键被按下
*/
exit(1); /* 结束 curses 模式
*/
/* 结束此程式
*/
default:
addch(ch); /* 如果不是特殊字元, 将此字元印
出 */
x++;
break;
}
move(y,x); /* 移动游标至现在位置
*/
} while (1);
}
void initial() /* 自定开启 curses 函式
*/
{
initscr();
cbreak();
nonl();
noecho();
intrflush(stdscr,FALSE);
keypad(stdscr,TRUE);
refresh();
}
建议你用www.google.com
收索一把 : unix 图形编程”,
#define StartX 1 /* 决定游标初始位置 */
#define StartY 1
void initial();
void main(void)
{
int x=StartX; /* 宣告 x,y 并设定其初值 */
int y=StartY;
int ch; /* 宣告 ch 为整数,配合 getch()使用 */
initial(); /* 呼叫 initial(), 启动 curses 模式, */
/* 并完成其它设定 */
box(stdscr,'|','-'); /* 画方框 */
attron(A_REVERSE); /* 开启反白模式 */
mvaddstr(0,20,"Curses Program"); /* 在 (20,0) 处输出反白字元 */
attroff(A_REVERSE); /* 关闭反白模式 */
move(x,y); /* 将游标移至初始位置 */
do { /* 以无限回圈不断等待输入 */
ch=getch(); /* 等待自键盘输入字元*/
switch(ch) { /* 判断输入字元为何 */
case KEY_UP: --y; /* 判断是否"↑"键被按下
*/
break;
case KEY_DOWN: ++y; /* 判断是否"↓"键被按下
*/
break;
case KEY_RIGHT: ++x; /* 判断是否"→"键被按下
*/
break;
case KEY_LEFT: --x; /* 判断是否"←"键被按下
*/
break;
case 'r': /* 判断是否 ENTER 键被按下
*/
++y;
x=0;
break;
case 't': /* 判断是否 TAB 键被按下
*/
x+=7;
break;
case 127: /* 判断是否 BACKSPACE 键被按下
*/
mvaddch(y,--x,' ');/* delete 一个字元
*/
break;
case 27: endwin(); /* 判断是否[ESC]键被按下
*/
exit(1); /* 结束 curses 模式
*/
/* 结束此程式
*/
default:
addch(ch); /* 如果不是特殊字元, 将此字元印
出 */
x++;
break;
}
move(y,x); /* 移动游标至现在位置
*/
} while (1);
}
void initial() /* 自定开启 curses 函式
*/
{
initscr();
cbreak();
nonl();
noecho();
intrflush(stdscr,FALSE);
keypad(stdscr,TRUE);
refresh();
}
建议你用www.google.com
收索一把 : unix 图形编程”,
|
以下是我很久前编写的
很多细节都忘记了
它运行于X-WINDOW上
$ cc $1.c -lXm -lXt -lX11 -lsocket -o$1
#include
#include
#include
#include
#include
#include
#include
#include
#include"datebase.h"
#include"function.h"
#include"space.h"
#include"input.h"
#include"query.h"
#include"chang.h"
#include"help.h"
void down_pro(Widget w,XtPointer client,XtPointer call){
exit(0);
}
int main(int argc,char *argv){
XtSetLanguageProc(NULL,NULL,NULL);
toplevel=XtVaAppInitialize(&theApp,"Main",NULL,0,&argc,argv,NULL,NULL);
one=XtVaCreateManagedWidget("One",xmBulletinBoardWidgetClass,
toplevel,
XmNallowOverlap,False,
XmNwidth, 750,
XmNheight, 510,
NULL);
/* MENU area 0 menubar--------------------------------------------*/
shell=XtVaCreateManagedWidget("X",
xmRowColumnWidgetClass,
one,
NULL);
menubar=XmCreateMenuBar(shell,"menuBar",NULL,0);
XtManageChild(menubar);
filepane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("File");
Filebutton=XtVaCreateManagedWidget("File",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,filepane,
XmNlabelString,xmstr,
XmNmnemonic,'F',
NULL);
Filebutton1=XtVaCreateManagedWidget("Open",
xmPushButtonWidgetClass,
filepane,
NULL);
xmstr=XmStringCreateSimple("F10");
Filebutton2=XtVaCreateManagedWidget("Close",
xmPushButtonWidgetClass,
filepane,
XmNaccelerator,"F10",
XmNacceleratorText,xmstr,
NULL);
XtAddCallback(Filebutton2,XmNactivateCallback,down_pro,NULL);
/*FilesaveAsPane=XmCreatePulldownMenu(filepane,"save_as",NULL,0);
Filebutton3=XtVaCreateManagedWidget("Save As",
xmCascadeButtonWidgetClass,
filepane,
XmNsubMenuId,FilesaveAsPane,
NULL);
Filebutton4=XtVaCreateManagedWidget("MS Word",
xmPushButtonWidgetClass,
FilesaveAsPane,
NULL);
Filebutton5=XtVaCreateManagedWidget("LaTeX",
xmPushButtonWidgetClass,FilesaveAsPane,
NULL);
*/
querypane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Query");
Querybutton=XtVaCreateManagedWidget("query",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,querypane,
XmNlabelString,xmstr,
XmNmnemonic,'Q',
NULL);
Queryname=XtVaCreateManagedWidget("Name",
xmPushButtonWidgetClass,
querypane,
NULL);
XtAddCallback(Queryname,XmNactivateCallback,mainquery,NULL);
Queryno=XtVaCreateManagedWidget("Number",
xmPushButtonWidgetClass,
querypane,
NULL);
inputpane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Input");
Inputbutton=XtVaCreateManagedWidget("Input",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,inputpane,
XmNlabelString,xmstr,
XmNmnemonic,'I',
NULL);
Inputbutton1=XtVaCreateManagedWidget("Insert",
xmPushButtonWidgetClass,
inputpane,
NULL);
changpane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Chang");
changbutton=XtVaCreateManagedWidget("Chang",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,changpane,
XmNlabelString,xmstr,
XmNmnemonic,'C',
NULL);
Changbutton1=XtVaCreateManagedWidget("Chang",
xmPushButtonWidgetClass,
changpane,
NULL);
XtAddCallback(Changbutton1,XmNactivateCallback,mainchang,NULL);
setuppane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Setup");
Setupbutton=XtVaCreateManagedWidget("Setup",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,setuppane,
XmNlabelString,xmstr,
XmNmnemonic,'S',
NULL);
Setuppasswd=XtVaCreateManagedWidget("Password",
xmPushButtonWidgetClass,
setuppane,
NULL);
helppane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Help");
Helpbutton=XtVaCreateManagedWidget("Help",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,helppane,
XmNlabelString,xmstr,
XmNmnemonic,'H',
NULL);
Helptext=XtVaCreateManagedWidget("Help Text",
xmPushButtonWidgetClass,
helppane,
NULL);
XtAddCallback(Helptext,XmNactivateCallback,mainhelp,NULL);
Helpsystem=XtVaCreateManagedWidget("Help System",
xmPushButtonWidgetClass,
helppane,
NULL);
XtAddCallback(Inputbutton1,XmNactivateCallback,maininput,NULL);
/* FIRST area 1 list----------------------------------------------*/
/* SECOND area 2 input---------------------------------------------*/
inputx=10; inputy=5; inputlen=40;
inputmx=150; inputmy=50;
XtRealizeWidget(toplevel);
XtAppMainLoop(theApp);
exit(0);
}
很多细节都忘记了
它运行于X-WINDOW上
$ cc $1.c -lXm -lXt -lX11 -lsocket -o$1
#include
#include
#include
#include
#include
#include
#include
#include
#include"datebase.h"
#include"function.h"
#include"space.h"
#include"input.h"
#include"query.h"
#include"chang.h"
#include"help.h"
void down_pro(Widget w,XtPointer client,XtPointer call){
exit(0);
}
int main(int argc,char *argv){
XtSetLanguageProc(NULL,NULL,NULL);
toplevel=XtVaAppInitialize(&theApp,"Main",NULL,0,&argc,argv,NULL,NULL);
one=XtVaCreateManagedWidget("One",xmBulletinBoardWidgetClass,
toplevel,
XmNallowOverlap,False,
XmNwidth, 750,
XmNheight, 510,
NULL);
/* MENU area 0 menubar--------------------------------------------*/
shell=XtVaCreateManagedWidget("X",
xmRowColumnWidgetClass,
one,
NULL);
menubar=XmCreateMenuBar(shell,"menuBar",NULL,0);
XtManageChild(menubar);
filepane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("File");
Filebutton=XtVaCreateManagedWidget("File",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,filepane,
XmNlabelString,xmstr,
XmNmnemonic,'F',
NULL);
Filebutton1=XtVaCreateManagedWidget("Open",
xmPushButtonWidgetClass,
filepane,
NULL);
xmstr=XmStringCreateSimple("F10");
Filebutton2=XtVaCreateManagedWidget("Close",
xmPushButtonWidgetClass,
filepane,
XmNaccelerator,"F10",
XmNacceleratorText,xmstr,
NULL);
XtAddCallback(Filebutton2,XmNactivateCallback,down_pro,NULL);
/*FilesaveAsPane=XmCreatePulldownMenu(filepane,"save_as",NULL,0);
Filebutton3=XtVaCreateManagedWidget("Save As",
xmCascadeButtonWidgetClass,
filepane,
XmNsubMenuId,FilesaveAsPane,
NULL);
Filebutton4=XtVaCreateManagedWidget("MS Word",
xmPushButtonWidgetClass,
FilesaveAsPane,
NULL);
Filebutton5=XtVaCreateManagedWidget("LaTeX",
xmPushButtonWidgetClass,FilesaveAsPane,
NULL);
*/
querypane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Query");
Querybutton=XtVaCreateManagedWidget("query",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,querypane,
XmNlabelString,xmstr,
XmNmnemonic,'Q',
NULL);
Queryname=XtVaCreateManagedWidget("Name",
xmPushButtonWidgetClass,
querypane,
NULL);
XtAddCallback(Queryname,XmNactivateCallback,mainquery,NULL);
Queryno=XtVaCreateManagedWidget("Number",
xmPushButtonWidgetClass,
querypane,
NULL);
inputpane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Input");
Inputbutton=XtVaCreateManagedWidget("Input",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,inputpane,
XmNlabelString,xmstr,
XmNmnemonic,'I',
NULL);
Inputbutton1=XtVaCreateManagedWidget("Insert",
xmPushButtonWidgetClass,
inputpane,
NULL);
changpane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Chang");
changbutton=XtVaCreateManagedWidget("Chang",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,changpane,
XmNlabelString,xmstr,
XmNmnemonic,'C',
NULL);
Changbutton1=XtVaCreateManagedWidget("Chang",
xmPushButtonWidgetClass,
changpane,
NULL);
XtAddCallback(Changbutton1,XmNactivateCallback,mainchang,NULL);
setuppane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Setup");
Setupbutton=XtVaCreateManagedWidget("Setup",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,setuppane,
XmNlabelString,xmstr,
XmNmnemonic,'S',
NULL);
Setuppasswd=XtVaCreateManagedWidget("Password",
xmPushButtonWidgetClass,
setuppane,
NULL);
helppane=XmCreatePulldownMenu(menubar,"pane",NULL,0);
xmstr=XmStringCreateSimple("Help");
Helpbutton=XtVaCreateManagedWidget("Help",
xmCascadeButtonWidgetClass,
menubar,
XmNsubMenuId,helppane,
XmNlabelString,xmstr,
XmNmnemonic,'H',
NULL);
Helptext=XtVaCreateManagedWidget("Help Text",
xmPushButtonWidgetClass,
helppane,
NULL);
XtAddCallback(Helptext,XmNactivateCallback,mainhelp,NULL);
Helpsystem=XtVaCreateManagedWidget("Help System",
xmPushButtonWidgetClass,
helppane,
NULL);
XtAddCallback(Inputbutton1,XmNactivateCallback,maininput,NULL);
/* FIRST area 1 list----------------------------------------------*/
/* SECOND area 2 input---------------------------------------------*/
inputx=10; inputy=5; inputlen=40;
inputmx=150; inputmy=50;
XtRealizeWidget(toplevel);
XtAppMainLoop(theApp);
exit(0);
}
|
兄弟,你想的和我一样,告诉你,其实就用curses库就可以编写字符模拟界面的。
man S curses
man S curses