首页 > 代码库 > temp111
temp111
#include <gtk/gtk.h>#include "request.h"#include "managerLogin.h"#include "call.h"int main(int argc,char *argv[]){ gtk_init(&argc,&argv); /*初始化GTK+工具库*/ //request(); //managerLogin("经理登录"); call(); return 0;}
#include <gtk/gtk.h> #include "vipLogin.h" #include "callinfo.h" void answer_user( GtkWidget *widget,gpointer data ) { callinfo(); } void answer_VIP( GtkWidget *widget,gpointer data ) { vipLogin( ); } int answer( ) { GtkWidget *window1; GtkWidget *button2; GtkWidget *button3; GtkWidget *label6; GtkWidget *label7; GtkWidget *table; window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window1), "VIP登陆"); gtk_window_set_default_size(GTK_WINDOW(window1), 500, 500); gtk_window_set_position(GTK_WINDOW(window1),GTK_WIN_POS_CENTER_ALWAYS ); gtk_container_set_border_width (GTK_CONTAINER (window1), 30); table = gtk_table_new (9, 9, TRUE); gtk_container_add (GTK_CONTAINER (window1), table); button2 = gtk_button_new_with_label ("普通用户叫号"); button3 = gtk_button_new_with_label ("VIP用户登陆叫号"); label6 = gtk_label_new ("预计等待时间"); label7 = gtk_label_new ("预计等待时间,已为您节省**"); gtk_table_attach_defaults (GTK_TABLE (table), button2, 0, 4, 2, 6); gtk_table_attach_defaults (GTK_TABLE (table), button3, 5, 9, 2, 6); gtk_table_attach_defaults (GTK_TABLE (table), label6, 0, 4, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), label7, 5, 9, 6, 7); g_signal_connect (G_OBJECT (button2), "clicked",G_CALLBACK (answer_user), (gpointer) window1); g_signal_connect (G_OBJECT (button3), "clicked",G_CALLBACK (answer_VIP), (gpointer) window1); gtk_widget_show_all(window1); gtk_main (); return 0; }
#include <gtk/gtk.h> #include "answer.h"void do_button3(GtkWidget *widget,gpointer data ) { GtkWidget* dialog ; dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO,GTK_BUTTONS_OK,"\n点击叫号按钮 "); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog);} void do_button4(GtkWidget *widget,gpointer data ) { answer(); } void call() { GtkWidget *window; GtkWidget *button1; GtkWidget *button2; GtkWidget *fixed = gtk_fixed_new(); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window),"叫号系统"); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); gtk_window_set_default_size(GTK_WINDOW(window),420,470); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); button1= gtk_button_new_with_label("说明"); gtk_widget_set_size_request(button1,250,50); button2= gtk_button_new_with_label("欢迎来到叫号系统"); gtk_widget_set_size_request(button2,250,305); g_signal_connect (G_OBJECT(button1),"clicked",G_CALLBACK(do_button3),(gpointer)window); g_signal_connect (G_OBJECT(button2),"clicked",G_CALLBACK(do_button4),(gpointer)window); gtk_fixed_put(GTK_FIXED(fixed),button1,85, 25); gtk_fixed_put(GTK_FIXED(fixed),button2,85, 110); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); }
#ifndef MANAGERLOGIN_H#define MANAGERLOGIN_Hvoid answer_user( GtkWidget *widget,gpointer data );void answer_VIP( GtkWidget *widget,gpointer data );int answer( );#endif
#ifndef CALL_H#define CALL_Hvoid do_button3(GtkWidget *widget,gpointer data );void do_button4(GtkWidget *widget,gpointer data );void call();#endif
#include <gtk/gtk.h> void callinfo(){ GtkWidget *dialog; //提示框 gchar* msg="\n\n叫号成功! \n\n您当前的号数是:0101\n\n您前面的普通用户人数是:26 \n\n您前面的VIP用户人数是:54 "; GtkMessageType type = GTK_MESSAGE_INFO; //信息消息 //GTK_DIALOG_MODAL 对话框模式 GTK_BUTTONS_OK 只有一个‘OK‘按钮 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog}
#ifndef CALLINFO_H#define CALLINFO_Hvoid callinfo();#endif
#include <stdio.h> #include <syspes.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <arpa/inet.h> char* sendMsg(char buf[BUFSIZ]) { int client_sockfd; int len; struct sockaddr_in remote_addr; //服务器端网络地址结构体 /ar buf[BUFSIZ]; //数据传送的缓冲区 memset(&remote_addr,0,sizeof(remote_addr)); //数据初始化--清零 remote_addr.sin_family=AF_INET; //设置为IP通信 remote_addr.sin_addr.s_addr=inet_addr("127.0.0.1");//服务器IP地址 remote_addr.sin_port=htons(8003); //服务器端口号 /*创建客户端套接字--IPv4协议,面向连接通信,TCP协议*/ if((client_sockfd=socket(PF_INET,SOCK_STREAM,0))<0) { perror("socket"); return NULL; } /*将套接字绑定到服务器的网络地址上*/ if(connect(client_sockfd,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr))<0) { perror("connect"); return NULL; } /*发送接收信息并打印接收信息--recv返回接收到的字节数,send返回发送的字节数*/ len=send(client_sockfd,buf,strlen(buf),0); len=recv(client_sockfd,buf,BUFSIZ,0); close(client_sockfd);//关闭套接字 return buf; }
#ifndef CLIENT_H#define CLIENT_Hchar* sendMsg(char buf[BUFSIZ]);#endif
#include <gtk/gtk.h> void do_button1(GtkWidget *widget,gpointer data ) { //const gchar*uname; //uname=(gchar*)malloc(sizeof(gchar)); //uname=gtk_entry_get_text(GTK_ENTRY(name)); /*获得录入构件正文*/ //g_print(“Name:%s/n”,uname); } void do_button2(GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); } int managerLogin(char* s) { GtkWidget *window; GtkWidget *name; GtkWidget *password; GtkWidget *label1; GtkWidget *label2; GtkWidget *button1; GtkWidget *button2; GtkWidget *fixed = gtk_fixed_new(); //新建任意布局 //GtkWidget *image = gtk_image_new_from_file("managerLogin.png"); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window),s); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); //窗体居中 gtk_window_set_default_size(GTK_WINDOW(window),370,250); label1=gtk_label_new("账 号"); gtk_widget_set_size_request(label1,66,33); name= gtk_entry_new(); gtk_widget_set_size_request(name,165,33); label2=gtk_label_new("密 码"); gtk_widget_set_size_request(label2,66,33); password= gtk_entry_new(); gtk_widget_set_size_request(password,165,33); gtk_entry_set_visibility(GTK_ENTRY(password),FALSE); //密码不可见 button1= gtk_button_new_with_label("登陆"); //登录 gtk_widget_set_size_request(button1,66,33); button2= gtk_button_new_with_label("取消"); //取消 gtk_widget_set_size_request(button2,66,33); g_signal_connect (G_OBJECT(button1),"clicked",G_CALLBACK(do_button1),(gpointer)window); g_signal_connect (G_OBJECT(button2),"clicked",G_CALLBACK(do_button2),(gpointer)window); //gtk_fixed_put(GTK_FIXED(fixed),image, 0, 0); //添加窗体背景图片 gtk_fixed_put(GTK_FIXED(fixed),label1, 54,41); gtk_fixed_put(GTK_FIXED(fixed),name,142,41); gtk_fixed_put(GTK_FIXED(fixed),label2,54,90); gtk_fixed_put(GTK_FIXED(fixed),password,142,90); gtk_fixed_put(GTK_FIXED(fixed),button1,85, 154); gtk_fixed_put(GTK_FIXED(fixed),button2,202, 154); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); return 0; }
#ifndef MANAGERLOGIN_H#define MANAGERLOGIN_Hvoid do_button1(GtkWidget *widget,gpointer data );void do_button2(GtkWidget *widget,gpointer data );int managerLogin(char* s);#endif
#include <gtk/gtk.h> #include "answer.h" void answers( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); answer(); } int request( ) { GtkWidget *window; GtkWidget *button; GtkWidget *label1; GtkWidget *label2; GtkWidget *label3; GtkWidget *label4; GtkWidget *label5; GtkWidget *button1; GtkWidget *table; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "叫号系统"); gtk_window_set_default_size(GTK_WINDOW(window), 500, 500); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); gtk_container_set_border_width (GTK_CONTAINER (window), 30); table = gtk_table_new (8, 3, TRUE); gtk_container_add (GTK_CONTAINER (window), table); label1 = gtk_label_new ("柜台1服务情况"); label2= gtk_label_new ("柜台2服务情况"); label3 = gtk_label_new ("柜台3服务情况"); label4 = gtk_label_new ("柜台4服务情况"); label5 = gtk_label_new ("目前排队人数"); /tton = gtk_button_new_with_label ("welcome!"); button1 = gtk_button_new_with_label ("叫号"); g_signal_connect (G_OBJECT (button1), "clicked",G_CALLBACK (answers), (gpointer) window); //gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 0, 4); gtk_table_attach_defaults (GTK_TABLE (table), label1, 0, 1, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), label2, 0, 1, 4, 5); gtk_table_attach_defaults (GTK_TABLE (table), label3, 0, 1, 5, 6); gtk_table_attach_defaults (GTK_TABLE (table), label4, 0, 1, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), button1, 1, 3, 1, 6); gtk_table_attach_defaults (GTK_TABLE (table), label5, 1, 3, 6, 7); gtk_widget_show_all(window); gtk_main (); return 0; }
#ifndef MANAGERLOGIN_H#define MANAGERLOGIN_Hvoid answers( GtkWidget *widget,gpointer data );int request( );#endif
#include <stdio.h> #include <syspes.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <arpa/inet.h> int user_num=0; //普通用户数量 int vip_num=0; //VIP用户数量 char* buf1; //哪种请求char* buf2; //字段1,如用户名char* buf3; //字段2,如密码int len; char buf[BUFSIZ]; //数据传送的缓冲区 int client_sockfd; //客户端套接字 void parseBuf(char buf[]);void doService(); int main(int argc, char *argv[]) { int server_sockfd; //服务器端套接字 struct sockaddr_in my_addr; //服务器网络地址结构体 struct sockaddr_in remote_addr; //客户端网络地址结构体 int sin_size; memset(&my_addr,0,sizeof(my_addr)); //数据初始化--清零 my_addr.sin_family=AF_INET; //设置为IP通信 my_addr.sin_addr.s_addr=INADDR_ANY;//服务器IP地址--允许连接到所有本地地址上 my_addr.sin_port=htons(8003); //服务器端口号 /*创建服务器端套接字--IPv4协议,面向连接通信,TCP协议*/ if((server_sockfd=socket(PF_INET,SOCK_STREAM,0))<0) { perror("socket"); return 1; } /*将套接字绑定到服务器的网络地址上*/ if (bind(server_sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))<0) { perror("bind"); return 1; } /*监听连接请求--监听队列长度为5*/ listen(server_sockfd,5); sin_size=sizeof(struct sockaddr_in); while(1) { /*等待客户端连接请求到达*/ if((client_sockfd=accept(server_sockfd,(struct sockaddr *)&remote_addr,&sin_size))<0) { perror("accept"); return 1; } //printf("\n\n\naccept client %s\n",inet_ntoa(remote_addr.sin_addr)); //len=send(client_sockfd,"Welcome to my server",21,0);//发送欢迎信息 /*接收客户端的数据并将其发送给客户端--recv返回接收到的字节数,send返回发送的字节数*/ while((len=recv(client_sockfd,buf,BUFSIZ,0))>0) { buf1=buf2=buf3=NULL; parseBuf(buf); doService(); } close(client_sockfd); } close(server_sockfd); return 0; } void parseBuf(char buf[]){ char delims[] = "#"; char *result = NULL; result = strtok(buf,delims); buf1=result; result = strtok( NULL, delims ); buf2=result; result = strtok( NULL, delims ); buf3=result; } void doService() { if(!strcmp(buf1,"vipLogin")) { char res[BUFSIZ]; if(strcmp(buf2,"lmx")&&strcmp(buf2,"lwc")) strcpy(res,"2"); else if(strcmp(buf3,"123")) strcpy(res,"3"); else strcpy(res,"1"); len=send(client_sockfd,res,BUFSIZ,0); } else { printf("\n%s\n",buf1); printf("\n%s\n",buf2); printf("\n%s\n",buf3); } }
#include <gtk/gtk.h> void do_button(GtkWidget *widget,gpointer data ) { } void show(gchar* text){ GtkWidget *window; GtkWidget *button; GtkWidget *entry; GtkWidget *fixed = gtk_fixed_new(); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window),"显示屏"); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); gtk_window_set_default_size(GTK_WINDOW(window),300,120); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); entry = gtk_entry_new (); gtk_widget_set_size_request(entry ,250,33); gtk_entry_set_text(entry,text); button= gtk_button_new_with_label("查询"); gtk_widget_set_size_request(button,66,33); g_signal_connect (G_OBJECT(button),"clicked",G_CALLBACK(do_button),(gpointer)window); gtk_fixed_put(GTK_FIXED(fixed),entry,25, 20); gtk_fixed_put(GTK_FIXED(fixed),button,120,80); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); }
#ifndef SHOW_H#define SHOW_Hvoid do_button(GtkWidget *widget,gpointer data );void show(gchar* text);#endif
#include <stdio.h>#include <string.h>#include "client.h"int main(){ char buf[BUFSIZ]; char* s="staffLogin#lmx#123"; strcpy(buf,s); strcpy(buf,sendMsg(buf)); if(buf[0]==‘1‘) printf("sucessful!\n"); else if(buf[0]==‘2‘) printf("wrong username !\n"); else if(buf[0]==‘3‘) printf("wrong code !\n"); else printf("other wrong !\n"); return 0;}
#include <gtk/gtk.h> #include <string.h>#include "request.h" #include "callinfo.h" #include "client.h"GtkWidget *name; GtkWidget *password;void do_button( GtkWidget *widget,gpointer data ) { char Buf[BUFSIZ]; char Buf1[100]; char Buf2[100]; strcpy(Buf1,(char*)gtk_entry_get_text(GTK_ENTRY(name))); strcpy(Buf2,(char*)gtk_entry_get_text(GTK_ENTRY(password))); strcat(Buf,"vipLogin#"); strcat(Buf,Buf1); strcat(Buf,"#"); strcat(Buf,Buf2); char res[BUFSIZ]; strcpy(res,sendMsg(Buf)); if(res[0]==‘1‘){ callinfo(); }else if(res[0]==‘2‘){ GtkWidget *dialog; //提示框 gchar* msg="\n\n用户名错误! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }else if(res[0]==‘3‘){ GtkWidget *dialog; //提示框 gchar* msg="\n\n密码错误! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }else{ GtkWidget *dialog; //提示框 gchar* msg="\n\n用户不存在! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog } } int vipLogin( ) { GtkWidget *window; GtkWidget *label1; GtkWidget *label2; GtkWidget *button1; GtkWidget *button2; GtkWidget *fixed = gtk_fixed_new(); //GtkWidget *image = gtk_image_new_from_file("managerLogin.png"); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window),"VIP登录"); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); //窗体居中 gtk_window_set_default_size(GTK_WINDOW(window),370,250); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); label1=gtk_label_new("VIP"); gtk_widget_set_size_request(label1,66,33); name= gtk_entry_new(); gtk_widget_set_size_request(name,165,33); label2=gtk_label_new("密 码"); gtk_widget_set_size_request(label2,66,33); password= gtk_entry_new(); gtk_widget_set_size_request(password,165,33); gtk_entry_set_visibility(GTK_ENTRY(password),FALSE); //密码不可见 button1= gtk_button_new_with_label("登陆"); //登录 gtk_widget_set_size_request(button1,66,33); button2= gtk_button_new_with_label("取消"); //取消 gtk_widget_set_size_request(button2,66,33); g_signal_connect (G_OBJECT(button1),"clicked",G_CALLBACK(do_button),(gpointer)window); g_signal_connect_swapped (G_OBJECT (button2), "clicked", G_CALLBACK (gtk_widget_destroy), window); //gtk_fixed_put(GTK_FIXED(fixed),image, 0, 0); //添加窗体背景图片 gtk_fixed_put(GTK_FIXED(fixed),label1, 54,41); gtk_fixed_put(GTK_FIXED(fixed),name,142,41); gtk_fixed_put(GTK_FIXED(fixed),label2,54,90); gtk_fixed_put(GTK_FIXED(fixed),password,142,90); gtk_fixed_put(GTK_FIXED(fixed),button1,85, 154); gtk_fixed_put(GTK_FIXED(fixed),button2,202, 154); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); return 0; }
#ifndef MANAGERLOGIN_H#define MANAGERLOGIN_Hvoid callback( GtkWidget *widget,gpointer data );gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data );void destroy( GtkWidget *widget,gpointer data );int vipLogin( );#endif
temp111
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。