当前位置:   article > 正文

yfw_gtk2.0使用markup动态改变聊天对话字体

gtk2.0使用markup动态改变聊天对话字体

caogaoxiang.c:

  1. #include <gtk/gtk.h>
  2. #include <string.h>
  3. #include "main.h"
  4. GtkWidget *window_receive;
  5. //char * name = "jack@123.com";
  6. /* 用于list view */
  7. enum ListCols
  8. {
  9. LIST_CHECKED,
  10. LIST_RECEIVER,
  11. LIST_SUBJECT,
  12. LIST_TIME
  13. };
  14. void select_show_caogao(GtkTreeSelection* select, gpointer data) //获得账号和发送时间发送给数据库
  15. {
  16. GtkTreeIter iter;
  17. GtkTreeModel* model;
  18. gchar* receiver;
  19. gchar* time1;
  20. gchar* subject;
  21. char buf[100]={"hiierjhejkhjkdfh"};
  22. //gchar* info;
  23. char request[50];
  24. int len;
  25. int i;
  26. memset(request,' ',sizeof(request));
  27. if(gtk_tree_selection_get_selected(select, &model, &iter))
  28. {
  29. gtk_tree_model_get(model, &iter, LIST_RECEIVER, &receiver,LIST_TIME,&time1,LIST_SUBJECT,&subject,-1);
  30. printf("%s\n",time1);
  31. request[0]='2';
  32. request[1]='3';
  33. len=strlen(name);
  34. request[2]=(char)len;
  35. for(i=0;i<len;i++){
  36. request[i+3]=name[i];
  37. }
  38. request[15]=26;
  39. for(i=0;i<26;i++){
  40. request[i+16]=time1[i];
  41. }
  42. //连接数据库,获得装有邮件内容的buf
  43. /**************************/
  44. window_show_caogao(receiver,subject,name,buf);///弹出邮件阅读窗口,显示邮件
  45. printf("%s\n",request);
  46. g_free(receiver);
  47. g_free(time1);
  48. }
  49. }
  50. GtkWidget * create_list_caogao()//创建显示草稿箱信息的列表
  51. {
  52. GtkWidget* vbox ;
  53. GtkTreeView* list;
  54. GtkListStore* list_store;
  55. GtkTreeIter iter;
  56. GtkCellRenderer* renderer;
  57. GtkTreeViewColumn* column;
  58. GtkTreeSelection* select;
  59. vbox = gtk_vbox_new (FALSE, 2);
  60. /* 创建ListView */
  61. list = gtk_tree_view_new();
  62. /* 创建ListView的model, 添加数据 */
  63. list_store = gtk_list_store_new(4,G_TYPE_BOOLEAN,
  64. G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
  65. //连接数据库,获得邮件列表
  66. /**************************/
  67. gtk_list_store_append(list_store, &iter);
  68. gtk_list_store_set(list_store, &iter,
  69. LIST_CHECKED,FALSE,
  70. LIST_RECEIVER, "KENBER",
  71. LIST_SUBJECT, "HHHHHHHHHHH",
  72. LIST_TIME,"2014年02月03日13时34分26秒" , -1);
  73. gtk_list_store_append(list_store, &iter);
  74. gtk_list_store_set(list_store, &iter,
  75. LIST_CHECKED,FALSE,
  76. LIST_RECEIVER, "guosiyu",
  77. LIST_SUBJECT, "uuuuuuu",
  78. LIST_TIME,"2012年02月07日13时34分26秒" , -1);
  79. gtk_tree_view_set_model(list, list_store);
  80. //g_object_unref(list_store);
  81. /* 创建ListView的View */
  82. renderer = gtk_cell_renderer_toggle_new();
  83. column = gtk_tree_view_column_new_with_attributes("选择", renderer,
  84. "active", LIST_CHECKED, NULL);
  85. column = gtk_tree_view_append_column(list, column);
  86. renderer = gtk_cell_renderer_text_new();
  87. column = gtk_tree_view_column_new_with_attributes("收件人", renderer,
  88. "text", LIST_RECEIVER, NULL);
  89. column = gtk_tree_view_append_column(list, column);
  90. renderer = gtk_cell_renderer_text_new();
  91. column = gtk_tree_view_column_new_with_attributes("主题", renderer,
  92. "text", LIST_SUBJECT, NULL);
  93. column = gtk_tree_view_append_column(list, column);
  94. column = gtk_tree_view_column_new_with_attributes("日期", renderer,
  95. "text", LIST_TIME, NULL);
  96. column = gtk_tree_view_append_column(list, column);
  97. //设置点击列表触发事件
  98. select = gtk_tree_view_get_selection(list);
  99. gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
  100. g_signal_connect(G_OBJECT(select), "changed",
  101. G_CALLBACK(select_show_caogao), NULL);
  102. gtk_box_pack_start(vbox, list, TRUE, TRUE, 1);
  103. return vbox;
  104. }
  105. GtkWidget *make_caogaoxiang()
  106. {
  107. // GtkWidget *window;
  108. GtkWidget *total_vbox;
  109. GtkWidget *table1;
  110. GtkWidget *button6;
  111. GtkWidget *button7;
  112. GtkWidget *button8;
  113. GtkWidget *button9;
  114. GtkWidget *button10;
  115. GtkWidget *button11;
  116. GtkWidget *label3;
  117. GtkWidget *label4;
  118. GtkWidget *entry1;
  119. GtkWidget *image;
  120. GtkWidget *vbox1;
  121. GtkWidget *hdimage;
  122. GtkWidget *label5;
  123. GtkWidget *label6;
  124. GtkWidget *label7;
  125. GtkWidget *label8;
  126. GtkWidget *label9;
  127. GtkWidget *show_box;
  128. int indx;
  129. GtkWidget *vbox;
  130. GtkWidget *scrolled_window, *clist;
  131. /*gtk_init (&argc, &argv);
  132. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  133. gtk_window_set_title(GTK_WINDOW(window), "GtkScrolledWindow");
  134. gtk_window_set_default_size(GTK_WINDOW(window), 320, 200);
  135. g_signal_connect_swapped(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit), NULL);*/
  136. total_vbox= gtk_vbox_new(FALSE,0);
  137. window_receive = gtk_scrolled_window_new (NULL, NULL);
  138. gtk_container_add (GTK_CONTAINER (total_vbox), window_receive);
  139. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window_receive),GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
  140. table1 = gtk_table_new (15,8, TRUE);
  141. image=gtk_image_new_from_file("receive.png");
  142. label3 = gtk_label_new (g_locale_to_utf8("显示:", -1, NULL, NULL, NULL));
  143. label4 = gtk_label_new (g_locale_to_utf8("搜索:", -1, NULL, NULL, NULL));
  144. button6 = gtk_button_new_with_label(g_locale_to_utf8("回 复", -1, NULL, NULL, NULL));
  145. button7 = gtk_button_new_with_label(g_locale_to_utf8("转 发", -1, NULL, NULL, NULL));
  146. button8 = gtk_button_new_with_label(g_locale_to_utf8("删 除", -1, NULL, NULL, NULL));
  147. button9 = gtk_button_new_with_label(g_locale_to_utf8("标 记", -1, NULL, NULL, NULL));
  148. button10 = gtk_button_new_with_label(g_locale_to_utf8("全部信件", -1, NULL, NULL, NULL));
  149. button11 = gtk_button_new_with_label(g_locale_to_utf8("搜 索", -1, NULL, NULL, NULL));
  150. entry1 = gtk_entry_new ();
  151. //添加表格到窗口
  152. gtk_container_add(GTK_CONTAINER (window_receive), table1);
  153. //将元件分别添加到表格中
  154. //左半边
  155. gtk_table_attach (GTK_TABLE(table1), image, 4, 8, 9, 15,
  156. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  157. gtk_table_attach (GTK_TABLE(table1), label3, 0, 1, 1, 2,
  158. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  159. gtk_table_attach (GTK_TABLE(table1), label4, 0, 1, 2, 3,
  160. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  161. gtk_table_attach (GTK_TABLE(table1), button6, 0, 1, 0, 1,
  162. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  163. gtk_table_attach (GTK_TABLE(table1), button7, 1, 2, 0, 1,
  164. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  165. gtk_table_attach (GTK_TABLE(table1), button8, 2, 3, 0, 1,
  166. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  167. gtk_table_attach (GTK_TABLE(table1), button9, 3, 4, 0, 1,
  168. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  169. gtk_table_attach (GTK_TABLE(table1), button10,1, 2, 1, 2,
  170. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  171. gtk_table_attach (GTK_TABLE(table1), button11,3, 4, 2, 3,
  172. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  173. gtk_table_attach (GTK_TABLE(table1), entry1,1, 3, 2, 3,
  174. GTK_FILL, GTK_FILL, 0, 0);
  175. //右半边
  176. hdimage=gtk_image_new_from_file("HD.png");
  177. label5 = gtk_label_new (g_locale_to_utf8(" 用户名: lzr", -1, NULL, NULL, NULL));
  178. label6 = gtk_label_new (g_locale_to_utf8(" 等级组: 小学生", -1, NULL, NULL, NULL));
  179. label7 = gtk_label_new (g_locale_to_utf8("个性签名:瓦格你好帅!!", -1, NULL, NULL, NULL));
  180. label8 = gtk_label_new (g_locale_to_utf8(" QQ : 保密 ", -1, NULL, NULL, NULL));
  181. label9 = gtk_label_new (g_locale_to_utf8("联系电话 : 保密 ", -1, NULL, NULL, NULL));
  182. gtk_table_attach (GTK_TABLE(table1), hdimage,4, 6, 0, 4,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  183. gtk_table_attach (GTK_TABLE(table1), label5, 5, 7, 1, 2,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  184. gtk_table_attach (GTK_TABLE(table1), label6, 5, 7, 2, 3,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  185. gtk_table_attach (GTK_TABLE(table1), label7, 3, 8, 4, 5,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  186. gtk_table_attach (GTK_TABLE(table1), label8, 3, 8, 5, 6,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  187. gtk_table_attach (GTK_TABLE(table1), label9, 3, 8, 6, 7,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  188. //加入滚动列表框
  189. vbox=gtk_vbox_new(FALSE, 5);
  190. gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
  191. //gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
  192. gtk_table_attach (GTK_TABLE(table1), vbox,0, 4, 3, 15,
  193. GTK_FILL, GTK_FILL, 0, 0);
  194. scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  195. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
  196. gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
  197. gtk_widget_show (scrolled_window);
  198. show_box=gtk_vbox_new(FALSE, 5);
  199. show_box=create_list_caogao();
  200. gtk_container_add(GTK_CONTAINER(scrolled_window), show_box);
  201. /* gtk_signal_connect(GTK_OBJECT(clist), "select_row",
  202. GTK_SIGNAL_FUNC(selection_made),NULL
  203. );*/
  204. // gtk_widget_show_all (window);
  205. // gtk_main();
  206. return total_vbox;
  207. }

notebook.c:

  1. //#include <gdk/gdkkeysyms>
  2. #include "main.h"
  3. #include <gtk/gtk.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include<stdlib.h>
  7. #include<sys/socket.h>
  8. #include<netinet/in.h>
  9. #include<arpa/inet.h>
  10. #include<netdb.h>
  11. #define i 10
  12. #define q 7
  13. #define p 101
  14. #define m 35
  15. /*全局变量****************************************************************************************/
  16. char* host_name="127.0.0.1";//"192.168.100.1";
  17. int port=8888;
  18. GtkWidget *entry1;//收件人gg
  19. GtkWidget *entry11;//密送gg
  20. GtkWidget *entry2;//主题gg
  21. char *text;
  22. static GtkWidget *window_color;
  23. static GdkColor color;
  24. static GtkWidget *drawarea;
  25. GtkWidget *view;//编辑窗口
  26. char name[20]="hjlhsa";//邮件地址gggggggggggggggggg
  27. const char *nickname="guosiyu";
  28. const char *weidu_number="3";
  29. //char weidu_number[10];
  30. /*函数声明*****************************************************************************************/
  31. int change_color ( );//改变颜色
  32. void on_ok_clicked (GtkButton* button, gpointer data);//改变颜色
  33. void cleanup();//清空重新编辑
  34. int change_ziti();//改变字体
  35. void on_font_select_ok (GtkWidget *button,GtkFontSelectionDialog *fs);
  36. void on_button_clicked (GtkWidget *button,gpointer userdata);
  37. /*得到收件人内容**********************************************************************gg*/
  38. void get_recer(char* re_name)
  39. {
  40. strcpy(re_name,gtk_entry_get_text(GTK_ENTRY(entry1)));
  41. }
  42. /*得到密送内容************************************************************************gg*/
  43. void get_misong(char* misong_name)
  44. {
  45. char misong[100];
  46. int k;
  47. int j=0;
  48. strcpy(misong,gtk_entry_get_text(GTK_ENTRY(entry11)));
  49. for(k=0;misong[k]!='\0';k++)
  50. {
  51. if(misong[k]==';')
  52. {
  53. misong_name[j]='*';
  54. j++;
  55. misong_name[j]=';';
  56. j++;
  57. }
  58. else
  59. {
  60. misong_name[j]=misong[k];
  61. j++;
  62. }
  63. }
  64. misong_name[j]='\0';
  65. }
  66. /*得到信得主题************************************************************************gg*/
  67. void get_title(char* title)
  68. {
  69. strcpy(title,gtk_entry_get_text(GTK_ENTRY(entry2)));
  70. }
  71. /*得到信主题内容**********************************************************************gg*/
  72. void get_text()
  73. {
  74. GtkTextBuffer *pTextBuffer ;
  75. GtkTextIter iterStart;
  76. GtkTextIter iterEnd;
  77. pTextBuffer=gtk_text_view_get_buffer(view);
  78. gtk_text_buffer_get_start_iter(pTextBuffer,&iterStart);
  79. gtk_text_buffer_get_end_iter(pTextBuffer,&iterEnd);
  80. text=(gchar *)gtk_text_buffer_get_text(pTextBuffer,&iterStart,&iterEnd,FALSE);
  81. printf("aaaaaaa\n");
  82. printf("%s\n",text);
  83. }
  84. /*得到本地时间***********************************************************************gg*/
  85. void get_time(char* time)
  86. {
  87. time=" ";
  88. }
  89. /*发送写信页面发送所有内容********************************************************************gggggggggggggggggggggg*/
  90. int xiexin_cbd()
  91. {
  92. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  93. char buf[1024];
  94. memset(buf,0,sizeof(buf));
  95. /*传入数据库的各个字符串的拼接*********************************************************/
  96. char str[1024];//str表示拼接后的字符串
  97. memset(str,' ',sizeof(str));
  98. char time[10]="fdf";
  99. char re_name[100];
  100. char misong_name[100];
  101. char title[100];
  102. //char text[200];
  103. int count=0;
  104. int k,j;
  105. get_recer(re_name);
  106. get_misong(misong_name);
  107. get_title(title);
  108. get_text();
  109. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  110. printf("%s",text);
  111. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  112. // get_time(time);
  113. //printf("str0:%s\n",str);
  114. str[0]='s';
  115. str[1]='2';//赋值2表示在发送
  116. str[2]=(char)strlen(name);//放发件人
  117. //printf("char c:%c\n",str[2]);
  118. for(k=0;name[k]!='\0';k++)
  119. {
  120. str[k+3]=name[k];
  121. }
  122. //printf("str:%s\n",str);
  123. str[15]=(char)strlen(time);//放本地时间
  124. for(k=0;time[k]!='\0';k++)
  125. {
  126. str[k+16]=time[k];
  127. }
  128. //printf("str:%s\n",str);
  129. str[42]=(char)strlen(title);//放标题
  130. for(k=0;title[k]!='\0';k++)
  131. {
  132. str[k+43]=title[k];
  133. }
  134. printf("str:%s\n",text);
  135. str[123]=(char)strlen(text);//放信的内容
  136. for(k=0;text[k]!='\0';k++)
  137. {
  138. str[k+124]=text[k];
  139. }
  140. printf("str:%s\n",str);
  141. strcat(re_name,misong_name);
  142. for(k=0;re_name[k]!='\0';k++)
  143. {
  144. if(re_name[k]==';')count++;
  145. }
  146. str[624]=(char)count;//收件人和密送人的总个数
  147. for(k=0;re_name[k]!='\0';k++)
  148. {
  149. str[k+625]=re_name[k];
  150. }
  151. printf("str:%s\n",str);
  152. printf("%d",count);
  153. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  154. /*传入数据库的各个字符串的拼接结束*********************************************************/
  155. /*if(argc < 2)
  156. {
  157. printf("send default string.\n");
  158. }
  159. else
  160. {
  161. str=argv[1];
  162. }
  163. if((server_host_name=gethostbyname(host_name))==0)
  164. {
  165. herror("can not resoving localhost\n");
  166. exit(1);
  167. }*/
  168. int socket_descriptor;
  169. int temp_sock_descriptor;
  170. int size_of_addr;
  171. struct sockaddr_in sin;
  172. struct sockaddr_in pin;
  173. struct hostent * server_host_name;
  174. bzero(&pin, sizeof(pin));
  175. pin.sin_family=AF_INET;
  176. pin.sin_addr.s_addr = inet_addr("127.0.0.1");
  177. pin.sin_port=htons(port);
  178. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  179. if((socket_descriptor=socket(AF_INET, SOCK_STREAM, 0))==-1)
  180. {
  181. perror("error opening socket\n");
  182. exit(1);
  183. }
  184. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  185. if(connect(socket_descriptor, (void*)&pin, sizeof(pin))==-1)
  186. {
  187. perror("can not connecting to server\n");
  188. exit(1);
  189. }
  190. if(send(socket_descriptor, str, strlen(str), 0)==-1)
  191. {
  192. perror("can not send message\n");
  193. exit(1);
  194. }
  195. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  196. memset(buf, 0, 1024);
  197. if(recv(socket_descriptor, buf, sizeof(buf), 0)<0)//==-1)
  198. {
  199. perror("can not receive response\n");
  200. exit(1);
  201. }
  202. else{
  203. printf("message received from server:%s\n",buf);
  204. }
  205. close(socket_descriptor);
  206. return 0;
  207. }
  208. /*草稿箱************************************************************************************/
  209. int caogao_cbd()
  210. {
  211. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  212. char buf[1024];
  213. memset(buf,0,sizeof(buf));
  214. /*传入数据库的各个字符串的拼接*********************************************************/
  215. char str[1024];//str表示拼接后的字符串
  216. memset(str,' ',sizeof(str));
  217. char time[10]="fdf";
  218. char re_name[100];
  219. char misong_name[100];
  220. char title[100];
  221. //char text[200];
  222. int count=0;
  223. int k,j;
  224. get_recer(re_name);
  225. get_misong(misong_name);
  226. get_title(title);
  227. get_text();
  228. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  229. printf("%s",text);
  230. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  231. // get_time(time);
  232. //printf("str0:%s\n",str);
  233. str[0]='s';
  234. str[1]='1';//赋值1表示在草稿箱
  235. str[2]=(char)strlen(name);//放发件人
  236. //printf("char c:%c\n",str[2]);
  237. for(k=0;name[k]!='\0';k++)
  238. {
  239. str[k+3]=name[k];
  240. }
  241. //printf("str:%s\n",str);
  242. str[15]=(char)strlen(time);//放本地时间
  243. for(k=0;time[k]!='\0';k++)
  244. {
  245. str[k+16]=time[k];
  246. }
  247. //printf("str:%s\n",str);
  248. str[42]=(char)strlen(title);//放标题
  249. for(k=0;title[k]!='\0';k++)
  250. {
  251. str[k+43]=title[k];
  252. }
  253. printf("str:%s\n",text);
  254. str[123]=(char)strlen(text);//放信的内容
  255. for(k=0;text[k]!='\0';k++)
  256. {
  257. str[k+124]=text[k];
  258. }
  259. printf("str:%s\n",str);
  260. strcat(re_name,misong_name);
  261. for(k=0;re_name[k]!='\0';k++)
  262. {
  263. if(re_name[k]==';')count++;
  264. }
  265. str[624]=(char)count;//收件人和密送人的总个数
  266. for(k=0;re_name[k]!='\0';k++)
  267. {
  268. str[k+625]=re_name[k];
  269. }
  270. printf("str:%s\n",str);
  271. printf("%d",count);
  272. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  273. /*传入数据库的各个字符串的拼接结束*********************************************************/
  274. /*if(argc < 2)
  275. {
  276. printf("send default string.\n");
  277. }
  278. else
  279. {
  280. str=argv[1];
  281. }
  282. if((server_host_name=gethostbyname(host_name))==0)
  283. {
  284. herror("can not resoving localhost\n");
  285. exit(1);
  286. }*/
  287. int socket_descriptor;
  288. int temp_sock_descriptor;
  289. int size_of_addr;
  290. struct sockaddr_in sin;
  291. struct sockaddr_in pin;
  292. struct hostent * server_host_name;
  293. bzero(&pin, sizeof(pin));
  294. pin.sin_family=AF_INET;
  295. pin.sin_addr.s_addr = inet_addr("127.0.0.1");
  296. pin.sin_port=htons(port);
  297. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  298. if((socket_descriptor=socket(AF_INET, SOCK_STREAM, 0))==-1)
  299. {
  300. perror("error opening socket\n");
  301. exit(1);
  302. }
  303. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  304. if(connect(socket_descriptor, (void*)&pin, sizeof(pin))==-1)
  305. {
  306. perror("can not connecting to server\n");
  307. exit(1);
  308. }
  309. if(send(socket_descriptor, str, strlen(str), 0)==-1)
  310. {
  311. perror("can not send message\n");
  312. exit(1);
  313. }
  314. //printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  315. memset(buf, 0, 1024);
  316. if(recv(socket_descriptor, buf, sizeof(buf), 0)<0)//==-1)
  317. {
  318. perror("can not receive response\n");
  319. exit(1);
  320. }
  321. else{
  322. printf("message received from server:%s\n",buf);
  323. }
  324. close(socket_descriptor);
  325. return 0;
  326. }
  327. /*改变颜色*****************************************************************************/
  328. int change_color ( )
  329. {
  330. GtkWidget *vbox;
  331. GtkWidget *frame;
  332. GtkWidget *button;
  333. color.red = 0;
  334. color.blue = 65535;
  335. color.green = 0;
  336. window_color = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  337. g_signal_connect(G_OBJECT(window_color),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
  338. gtk_window_set_title(GTK_WINDOW(window_color),"选择颜色");
  339. gtk_window_set_position(GTK_WINDOW(window_color),GTK_WIN_POS_CENTER);
  340. gtk_container_set_border_width(GTK_CONTAINER(window_color),20);
  341. vbox = gtk_vbox_new(FALSE,0);
  342. gtk_container_add(GTK_CONTAINER(window_color),vbox);
  343. frame = gtk_frame_new(NULL);
  344. gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_IN);
  345. gtk_box_pack_start(GTK_BOX(vbox),frame,TRUE,TRUE,5);
  346. drawarea = gtk_drawing_area_new();
  347. gtk_widget_set_size_request(drawarea,200,200);//kongjian daxiao
  348. gtk_widget_modify_bg (drawarea, GTK_STATE_NORMAL,&color);//kongjian beijing
  349. gtk_container_add(GTK_CONTAINER(frame),drawarea);
  350. button = gtk_button_new_from_stock(GTK_STOCK_SELECT_COLOR);
  351. gtk_box_pack_start(GTK_BOX(vbox),button,FALSE,FALSE,5);
  352. g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(on_ok_clicked),NULL);
  353. gtk_widget_show_all(window_color);
  354. gtk_main();
  355. return FALSE;
  356. }
  357. void on_ok_clicked (GtkButton* button, gpointer data)
  358. {
  359. GtkWidget *dialog;
  360. GtkColorSelection *colorsel;
  361. gint response;
  362. dialog = gtk_color_selection_dialog_new("选择颜色");
  363. gtk_window_set_transient_for (GTK_WINDOW (dialog),GTK_WINDOW (window_color));//注意:转换颜色选择对话框的颜色选择子控件
  364. colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);
  365. gtk_color_selection_set_has_opacity_control(colorsel,TRUE);
  366. gtk_color_selection_set_has_palette(colorsel,TRUE);
  367. gtk_signal_connect(GTK_OBJECT(dialog),"destroy",GTK_SIGNAL_FUNC(gtk_widget_destroy),&dialog);
  368. gtk_color_selection_set_previous_color (colorsel, &color);
  369. gtk_color_selection_set_current_color (colorsel, &color);
  370. response = gtk_dialog_run(GTK_DIALOG(dialog));
  371. //注意:此处需要用戶判断对话框的运行结果,如果是确定按钮则改变颜色
  372. if(response == GTK_RESPONSE_OK)
  373. {
  374. gtk_color_selection_get_current_color (colorsel, &color);
  375. gtk_widget_modify_bg (drawarea, GTK_STATE_NORMAL, &color);
  376. GtkTextBuffer *pTextBuffer ;
  377. GtkTextIter iterStart;
  378. GtkTextIter iterEnd;
  379. pTextBuffer=gtk_text_view_get_buffer(view);
  380. gtk_text_buffer_get_start_iter(pTextBuffer,&iterStart);
  381. gtk_text_buffer_get_end_iter(pTextBuffer,&iterEnd);
  382. gtk_widget_modify_text(GTK_WIDGET(view),GTK_STATE_NORMAL,&color);//改变编辑框内文本颜色
  383. }
  384. gtk_widget_destroy(dialog);
  385. }
  386. /*****************************************************************************/
  387. /*改变字体******************************************************************************/
  388. void on_font_select_ok (GtkWidget *button,GtkFontSelectionDialog *fs)
  389. {
  390. PangoFontDescription *font_desc;///
  391. GtkWidget *dialog;
  392. gchar message[1024];
  393. gchar* ziti = gtk_font_selection_dialog_get_font_name(fs);
  394. font_desc = pango_font_description_from_string(ziti);
  395. sprintf(message,"你选择的字体是:%s \n",ziti);
  396. dialog = gtk_message_dialog_new(NULL,
  397. GTK_DIALOG_DESTROY_WITH_PARENT,
  398. GTK_MESSAGE_INFO,
  399. GTK_BUTTONS_OK,
  400. message,
  401. NULL);
  402. gtk_widget_destroy(GTK_WIDGET(fs));
  403. gtk_dialog_run(GTK_DIALOG(dialog));
  404. gtk_widget_destroy(dialog);
  405. GtkTextBuffer *pTextBuffer ;
  406. GtkTextIter iterStart;
  407. GtkTextIter iterEnd;
  408. pTextBuffer=gtk_text_view_get_buffer(view);
  409. gtk_text_buffer_get_start_iter(pTextBuffer,&iterStart);
  410. gtk_text_buffer_get_end_iter(pTextBuffer,&iterEnd);
  411. gtk_widget_modify_font(GTK_WIDGET(view), font_desc);/*/
  412. g_free(ziti);
  413. }
  414. void on_button_clicked (GtkWidget *button,gpointer userdata)
  415. {
  416. GtkWidget* dialog;
  417. dialog = gtk_font_selection_dialog_new("请选择一种字体:");
  418. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
  419. gtk_signal_connect(GTK_OBJECT(dialog),"destroy",GTK_SIGNAL_FUNC(gtk_widget_destroy),&dialog);
  420. gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(dialog)->ok_button),"clicked",
  421. GTK_SIGNAL_FUNC(on_font_select_ok),GTK_FONT_SELECTION_DIALOG(dialog));
  422. gtk_signal_connect_object(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(dialog)->cancel_button),"clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy),GTK_OBJECT(dialog));
  423. gtk_widget_show(dialog);
  424. }
  425. int change_ziti ( )
  426. {
  427. GtkWidget *window;
  428. GtkWidget *button;
  429. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  430. g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
  431. gtk_window_set_title(GTK_WINDOW(window),"字体选择功能实现");
  432. //gtk_window_set_default_size(GTK_WINDOW(window),500,100);
  433. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  434. gtk_container_set_border_width(GTK_CONTAINER(window),40);
  435. button = gtk_button_new_with_label("按下此按钮来选择字体");
  436. g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(on_button_clicked),NULL);
  437. gtk_container_add(GTK_CONTAINER(window),button);
  438. gtk_widget_show(button);
  439. gtk_widget_show(window);
  440. gtk_main();
  441. return FALSE;
  442. }
  443. /*****************************************************************************************/
  444. /*清除重新编辑****************************************************************************/
  445. void cleanup()//GtkWidget *widget, gpointer view1)
  446. {
  447. char *text;/传递到数据库时使用
  448. GtkTextBuffer *pTextBuffer ;
  449. GtkTextIter iterStart;
  450. GtkTextIter iterEnd;
  451. pTextBuffer=gtk_text_view_get_buffer(view);
  452. gtk_text_buffer_get_start_iter(pTextBuffer,&iterStart);
  453. gtk_text_buffer_get_end_iter(pTextBuffer,&iterEnd);
  454. /*text=(gchar *)gtk_text_buffer_get_text(pTextBuffer,&iterStart,&iterEnd,FALSE);
  455. printf("%s\n",text);*/
  456. gtk_text_buffer_set_text(pTextBuffer,"\0",-1);
  457. }
  458. /*发送,存草稿,关闭的横盒******************************************************************/
  459. GtkWidget *make_box1( gboolean homogeneous, //写信
  460. gint spacing,
  461. gboolean expand,
  462. gboolean fill,
  463. guint padding )
  464. {
  465. GtkWidget *box;
  466. GtkWidget *button;
  467. char padstr[80];
  468. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  469. box = gtk_hbox_new (homogeneous, spacing);
  470. /* 以合适的设置创建一系列的按钮 */
  471. button = gtk_button_new_with_label ("发送");
  472. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  473. gtk_widget_show (button);
  474. g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(xiexin_cbd),NULL);
  475. button = gtk_button_new_with_label ("存草稿");
  476. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  477. gtk_widget_show (button);
  478. g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(caogao_cbd),NULL);
  479. button = gtk_button_new_with_label ("关閉");
  480. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  481. gtk_widget_show (button);
  482. return box;
  483. }
  484. GtkWidget *make_box2( gboolean homogeneous, //已发送
  485. gint spacing,
  486. gboolean expand,
  487. gboolean fill,
  488. guint padding )
  489. {
  490. GtkWidget *box;
  491. GtkWidget *button;
  492. char padstr[80];
  493. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  494. box = gtk_hbox_new (homogeneous, spacing);
  495. /* 以合适的设置创建一系列的按钮 */
  496. button = gtk_button_new_with_label ("删除");
  497. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  498. gtk_widget_show (button);
  499. button = gtk_button_new_with_label ("彻底删除");
  500. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  501. gtk_widget_show (button);
  502. button = gtk_button_new_with_label ("转发");
  503. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  504. gtk_widget_show (button);
  505. button = gtk_button_new_with_label ("全部标记为已读");
  506. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  507. gtk_widget_show (button);
  508. return box;
  509. }
  510. GtkWidget *make_box3( gboolean homogeneous, //已删除
  511. gint spacing,
  512. gboolean expand,
  513. gboolean fill,
  514. guint padding )
  515. {
  516. GtkWidget *box;
  517. GtkWidget *button;
  518. char padstr[80];
  519. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  520. box = gtk_hbox_new (homogeneous, spacing);
  521. /* 以合适的设置创建一系列的按钮 */
  522. button = gtk_button_new_with_label ("彻底删除");
  523. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  524. gtk_widget_show (button);
  525. button = gtk_button_new_with_label ("转发");
  526. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  527. gtk_widget_show (button);
  528. button = gtk_button_new_with_label ("全部标记为已读");
  529. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  530. gtk_widget_show (button);
  531. return box;
  532. }
  533. /*GtkWidget *make_box4( gboolean homogeneous, //草稿箱
  534. gint spacing,
  535. gboolean expand,
  536. gboolean fill,
  537. guint padding )
  538. {
  539. GtkWidget *box;
  540. GtkWidget *button;
  541. char padstr[80];
  542. box = gtk_hbox_new (homogeneous, spacing);
  543. button = gtk_button_new_with_label ("删除草稿");
  544. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  545. gtk_widget_show (button);
  546. button = gtk_button_new_with_label ("转发");
  547. gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2);
  548. gtk_widget_show (button);
  549. return box;
  550. }*/
  551. /*notebook部分函数**********************************************************************/
  552. void tabsborder_book( GtkButton *button,
  553. GtkNotebook *notebook )
  554. {
  555. gint bval = FALSE;
  556. if (notebook->show_border == 0)
  557. bval = TRUE;
  558. gtk_notebook_set_show_border (notebook, bval);
  559. }
  560. void delete(GtkWidget *widget,GtkWidget *event,gpointer data)
  561. {
  562. gtk_main_quit();
  563. }
  564. /*工具栏的函数******************************************************************/
  565. /*static void onDestroy( GtkWidget *widget, gpointer user_data)
  566. {
  567. gtk_main_quit();
  568. }*/
  569. // tianjia kucun ID gongju anniu
  570. GtkWidget * addStockToolItem(GtkWidget *toolbar, const gchar *stockid, const gchar *tooltip)
  571. {
  572. GtkToolItem *toolitem;
  573. toolitem = gtk_tool_button_new_from_stock(stockid);
  574. gtk_tool_item_set_tooltip_text(toolitem,tooltip);
  575. //jiang gong ju xiang cha ru gongju lan wei bu
  576. gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolitem,-1);
  577. gtk_widget_show(GTK_WIDGET(toolitem));
  578. return GTK_WIDGET(toolitem);
  579. }
  580. //tian jia fen ge gong ju xiang
  581. GtkWidget *addSeparatorToolItem(GtkWidget* toolbar)
  582. {
  583. GtkToolItem *toolitem;
  584. //chuang jian fen ge gong ju xiang
  585. toolitem = gtk_separator_tool_item_new();
  586. gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolitem,-1);
  587. gtk_widget_show(GTK_WIDGET(toolitem));
  588. return GTK_WIDGET(toolitem);
  589. }
  590. //tian jia gong ju xiang
  591. GtkWidget * addToolItem(GtkWidget* toolbar, const gchar *pLabel, const gchar *tooltip, const gchar *pImageFile)
  592. {
  593. GtkWidget *image = NULL;
  594. GtkToolItem *toolitem = NULL;
  595. //chuang jian tu pian gou jian
  596. image = gtk_image_new_from_file(pImageFile);
  597. gtk_widget_show(image);
  598. //chuang jian gong ju an niu
  599. toolitem = gtk_tool_button_new(image,pLabel);
  600. gtk_tool_item_set_tooltip_text(toolitem,tooltip);
  601. gtk_toolbar_insert(GTK_TOOLBAR(toolbar),toolitem,-1);
  602. gtk_widget_show(GTK_WIDGET(toolitem));
  603. return GTK_WIDGET(toolitem);
  604. }
  605. int main(int argc, char*argv[])
  606. {
  607. GtkWidget *window;
  608. GtkWidget *button;
  609. GtkWidget *notebook;
  610. GtkWidget *label;
  611. GtkWidget *checkbutton;
  612. char bufferf[32];
  613. char bufferl[32];
  614. GtkWidget *vbox0;//整个窗口纵盒
  615. GtkWidget *vbox;//整个窗口纵盒
  616. GtkWidget *vbox2;//整个窗口纵盒
  617. GtkWidget *vbox3;//整个窗口纵盒
  618. GtkWidget *vbox4;//整个窗口纵盒
  619. GtkWidget *vbox5;//整个窗口纵盒
  620. GtkWidget *vbox6;//整个窗口纵盒
  621. GtkWidget *vbox7;//整个窗口纵盒
  622. GtkWidget *bbox1;//收件人横盒
  623. GtkWidget *bbox11;//密送横盒
  624. GtkWidget *bbox2;//主题横盒
  625. GtkWidget *bbox3;//正文标签横盒
  626. GtkWidget *label1;
  627. GtkWidget *label11;//密送
  628. GtkWidget *label2;
  629. GtkWidget *label3;
  630. GtkWidget *box1;//发送,存草稿,关闭的横盒
  631. // GtkWidget *entry1;//收件人
  632. // GtkWidget *entry11;//密送
  633. // GtkWidget *entry2;//主题
  634. GtkWidget *toolbar;
  635. GtkWidget *toolitem;
  636. GtkWidget *handlebox;
  637. GtkWidget *frame;
  638. GtkWidget *tvbox;/
  639. GtkWidget *shouyehbox1;
  640. GtkWidget *shouyehbox2;
  641. GtkWidget *nullbox1;
  642. GtkWidget *nullbox2;
  643. GtkWidget *nullbox3;
  644. GtkWidget *boxx1;
  645. GtkWidget *labell;
  646. GtkWidget *boxxx1;
  647. GtkWidget *labelll;
  648. //GtkWidget *boxxxx1;
  649. GtkWidget *labellll;
  650. GtkWidget *weidu_eventbox;
  651. GtkWidget *shouye_label1;//标签晚上好
  652. GtkWidget *shouye_label2;//标签昵称
  653. GtkWidget *shouye_label3;//标签您有
  654. GtkWidget *shouye_label4;//标签未读邮件个数
  655. GtkWidget *shouye_label5;//封未读邮件
  656. //char greeting1[50];
  657. //char greeting2[50];
  658. char *greeting1=" 晚上好,";
  659. char *greeting2=" 您有";
  660. char* greeting3="封未读邮件";
  661. // strcpy(greeting1,"晚上好,");
  662. //strcpy(greeting2,"晚上好,");
  663. gtk_init(&argc, &argv);
  664. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  665. gtk_widget_set_size_request(GTK_WIDGET(window),550,500);
  666. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  667. g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
  668. gtk_window_set_title(GTK_WINDOW(window),"写信");
  669. vbox0 = gtk_vbox_new(FALSE,0);
  670. vbox = gtk_vbox_new(FALSE,0);
  671. vbox2 = gtk_vbox_new(FALSE,0);
  672. vbox3 = gtk_vbox_new(FALSE,0);
  673. //vbox4= gtk_vbox_new(FALSE,0);
  674. //vbox5 = gtk_vbox_new(FALSE,0);
  675. vbox6 = gtk_vbox_new(FALSE,0);
  676. vbox7 = gtk_vbox_new(FALSE,0);
  677. box1 = make_box1(FALSE,0,FALSE,FALSE,3); //写信
  678. boxx1 = make_box2(FALSE,0,FALSE,FALSE,3); //已发送
  679. boxxx1 = make_box3(FALSE,0,FALSE,FALSE,3); // 已删除
  680. //boxxxx1 = make_box4(FALSE,0,FALSE,FALSE,3); //草稿
  681. gtk_box_pack_start(GTK_BOX(vbox),box1,FALSE,FALSE,2);
  682. bbox1 = gtk_hbox_new(FALSE,0);
  683. bbox11 = gtk_hbox_new(FALSE,0);
  684. bbox2 = gtk_hbox_new(FALSE,0);
  685. bbox3 = gtk_hbox_new(FALSE,0);
  686. label1 = gtk_label_new("收件人");
  687. //gtk_misc_set_alignment(GTK_MISC(label1),0,0);/?????
  688. label11 = gtk_label_new("密送 ");
  689. label2 = gtk_label_new("主题 ");
  690. entry1 = gtk_entry_new();
  691. entry11 = gtk_entry_new();
  692. entry2 = gtk_entry_new();
  693. shouyehbox1=gtk_hbox_new(FALSE,0);
  694. shouyehbox2=gtk_hbox_new(FALSE,0);
  695. nullbox1=gtk_hbox_new(FALSE,10);
  696. nullbox2=gtk_hbox_new(FALSE,10);
  697. nullbox3=gtk_hbox_new(FALSE,10);
  698. weidu_eventbox= gtk_event_box_new();
  699. //sprintf(greeting1,nickname);
  700. //strcat(nickname,greeting1);
  701. //sprintf(greeting2,weidu_number);
  702. view = gtk_text_view_new();//涉及全局变量和环境变量
  703. gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view),GTK_WRAP_WORD_CHAR);
  704. /*首页盒子的排列************************************************************************************************/
  705. PangoFontDescription *font_desc = pango_font_description_from_string ("Serif 20");
  706. shouye_label1= gtk_label_new(greeting1);
  707. gtk_widget_modify_font(GTK_WIDGET(shouye_label1),font_desc );
  708. //gtk_label_set_markup(GTK_LABEL(shouye_label1),"<span foreground='black'font_desc='59'>(&greeting1) </span>");///
  709. shouye_label2= gtk_label_new(nickname);
  710. gtk_widget_modify_font(GTK_WIDGET(shouye_label2),font_desc );
  711. shouye_label3= gtk_label_new(greeting2);
  712. gtk_widget_modify_font(GTK_WIDGET(shouye_label3),font_desc );
  713. shouye_label4= gtk_label_new(weidu_number);
  714. gtk_widget_modify_font(GTK_WIDGET(shouye_label4),font_desc );
  715. shouye_label5= gtk_label_new(greeting3);
  716. gtk_widget_modify_font(GTK_WIDGET(shouye_label5),font_desc );
  717. /****************************************************************************************************************/
  718. gtk_container_add (GTK_CONTAINER (weidu_eventbox), shouye_label4);
  719. gtk_widget_set_events (weidu_eventbox, GDK_BUTTON_PRESS_MASK);
  720. //g_signal_connect(G_OBJECT (weidu_eventbox), "button_press_event",
  721. // G_CALLBACK (), vbox0 ); ///
  722. //gtk_widget_realize (weidu_eventbox);
  723. gdk_window_set_cursor (weidu_eventbox->window, gdk_cursor_new (GDK_HAND1));
  724. sprintf(bufferl,"已发送(共%d封)",q);
  725. labell = gtk_label_new(bufferl);
  726. gtk_label_set_justify(GTK_LABEL(labell),GTK_JUSTIFY_LEFT);
  727. gtk_box_pack_start(GTK_BOX(vbox6),labell,FALSE,FALSE,2);
  728. gtk_box_pack_start(GTK_BOX(vbox6),boxx1,FALSE,FALSE,2);
  729. sprintf(bufferl,"已删除(共%d封)",p);
  730. labelll = gtk_label_new(bufferl);
  731. gtk_label_set_justify(GTK_LABEL(labelll),GTK_JUSTIFY_LEFT);
  732. gtk_box_pack_start(GTK_BOX(vbox7),labelll,FALSE,FALSE,2);
  733. gtk_box_pack_start(GTK_BOX(vbox7),boxxx1,FALSE,FALSE,2);
  734. ///原草稿箱中的按钮
  735. /* sprintf(bufferl,"草稿箱(共%d封)",m);
  736. labellll = gtk_label_new(bufferl);
  737. gtk_label_set_justify(GTK_LABEL(labell),GTK_JUSTIFY_LEFT);
  738. gtk_box_pack_start(GTK_BOX(vbox5),labellll,FALSE,FALSE,2);
  739. gtk_box_pack_start(GTK_BOX(vbox5),boxxxx1,FALSE,FALSE,2);*/
  740. gtk_box_pack_start(GTK_BOX(bbox1),label1,FALSE,FALSE,0);//2
  741. gtk_box_pack_start(GTK_BOX(bbox1),entry1,TRUE,TRUE,0);
  742. gtk_box_pack_start(GTK_BOX(bbox11),label11,FALSE,FALSE,2);//3
  743. gtk_box_pack_start(GTK_BOX(bbox11),entry11,TRUE,TRUE,2);
  744. gtk_box_pack_start(GTK_BOX(vbox),bbox1,FALSE,FALSE,2);//2fangru zonghe
  745. gtk_box_pack_start(GTK_BOX(vbox),bbox11,FALSE,FALSE,2);//3fangru zonghe
  746. gtk_box_pack_start(GTK_BOX(bbox2),label2,FALSE,FALSE,2);//4
  747. gtk_box_pack_start(GTK_BOX(bbox2),entry2,TRUE,TRUE,2);
  748. gtk_box_pack_start(GTK_BOX(vbox),bbox2,FALSE,FALSE,2);//4fangru zonghe
  749. /*首页盒子的排列************************************************************************************************/
  750. gtk_box_pack_start(GTK_BOX(shouyehbox1),shouye_label1,FALSE,FALSE,2);//晚上好 昵称放横盒
  751. gtk_box_pack_start(GTK_BOX(shouyehbox1),shouye_label2,FALSE,FALSE,2);
  752. gtk_box_pack_start(GTK_BOX(shouyehbox2),shouye_label3,FALSE,FALSE,2);//您有n封未读邮件放横盒
  753. gtk_box_pack_start(GTK_BOX(shouyehbox2),weidu_eventbox,FALSE,FALSE,2);//数字n放事件盒
  754. gtk_box_pack_start(GTK_BOX(shouyehbox2),shouye_label5,FALSE,FALSE,2);
  755. gtk_box_pack_start(GTK_BOX(vbox0),nullbox1,FALSE,FALSE,10);
  756. gtk_box_pack_start(GTK_BOX(vbox0),nullbox2,FALSE,FALSE,10);
  757. gtk_box_pack_start(GTK_BOX(vbox0),nullbox3,FALSE,FALSE,10);
  758. gtk_box_pack_start(GTK_BOX(vbox0),shouyehbox1,FALSE,FALSE,2);//两个横盒放纵盒
  759. gtk_box_pack_start(GTK_BOX(vbox0),shouyehbox2,FALSE,FALSE,2);
  760. /***********************************************************************************************************/
  761. toolbar = gtk_toolbar_new();
  762. //shezhi gongju lan feng ge
  763. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),GTK_TOOLBAR_ICONS);
  764. //shezhi gongjulan tubiao daxiao
  765. gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),GTK_ICON_SIZE_SMALL_TOOLBAR);
  766. handlebox = gtk_handle_box_new();
  767. gtk_container_add(GTK_CONTAINER(handlebox),toolbar);
  768. toolitem = addToolItem(toolbar, "font","清空重新编辑","xinjian.bmp");
  769. g_signal_connect(toolitem,"clicked",G_CALLBACK(cleanup),NULL);
  770. toolitem = addToolItem(toolbar, "font","附件","fujian.bmp");
  771. // g_signal_connect(toolitem,"clicked",G_CALLBACK(onCommand),(gpointer)CMD_OPEN);
  772. toolitem = addToolItem(toolbar, "font","字体","ziti.bmp");
  773. g_signal_connect(toolitem,"clicked",G_CALLBACK(on_button_clicked),NULL);
  774. toolitem = addToolItem(toolbar, "color","顏色","yanse.bmp");
  775. g_signal_connect(toolitem,"clicked",G_CALLBACK(on_ok_clicked),NULL);
  776. toolitem = addToolItem(toolbar, "paper","信纸","xinzhi.bmp");
  777. // g_signal_connect(toolitem,"clicked",G_CALLBACK(onCommand),(gpointer)CMD_QUIT);
  778. // GtkWidget *vbox;//整个窗口纵盒
  779. frame = gtk_frame_new("正文");
  780. gtk_widget_set_size_request(frame,50,500);
  781. tvbox = gtk_vbox_new(FALSE,0);
  782. gtk_box_pack_start(GTK_BOX(vbox),handlebox,FALSE,FALSE,0);
  783. gtk_box_pack_start(GTK_BOX(vbox),frame,TRUE,TRUE,0);
  784. gtk_container_add(GTK_CONTAINER(frame),view);
  785. gtk_box_pack_start(GTK_BOX(vbox),tvbox,FALSE,FALSE,2);// gongjulan fang zonghe999999
  786. gtk_box_pack_start(GTK_BOX(vbox),bbox3,TRUE,TRUE,2);//zhengwen henghe fang zonghe
  787. //gtk_container_add(GTK_CONTAINER(window),vbox);
  788. //gtk_widget_show_all(vbox);
  789. //初始化GTK
  790. gtk_init(&argc,&argv);
  791. //创建最上层主窗口
  792. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  793. //连接信号"delete_event",使得窗口关闭时发生
  794. g_signal_connect(G_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(delete),NULL);
  795. //设置窗口标题
  796. gtk_window_set_title(GTK_WINDOW(window),"wingmail");
  797. //设定窗口的默认宽高
  798. gtk_window_set_default_size(GTK_WINDOW(window),800,400);
  799. //设定窗口的位置,让窗口总在最前端
  800. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  801. //设定容器边框的宽度
  802. gtk_container_set_border_width(GTK_CONTAINER(window),15);
  803. notebook = gtk_notebook_new();
  804. gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_LEFT);
  805. gtk_container_add(GTK_CONTAINER(window),notebook);
  806. gtk_widget_show(notebook);
  807. sprintf(bufferl,"已删除");
  808. label = gtk_label_new(bufferl);
  809. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox7,label);
  810. sprintf(bufferl,"已发送");
  811. label = gtk_label_new(bufferl);
  812. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox6,label);
  813. //草稿箱vbox5制作
  814. vbox5=make_caogaoxiang();
  815. sprintf(bufferl,"草稿箱(%d)",i);
  816. label = gtk_label_new(bufferl);
  817. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox5,label);
  818. 收件箱vbox4制作
  819. vbox4=make_receive_all();
  820. sprintf(bufferl,"收件箱(%d)",i);
  821. label = gtk_label_new(bufferl);
  822. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox4,label);
  823. sprintf(bufferl,"通讯录");
  824. label = gtk_label_new(bufferl);
  825. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox3,label);
  826. sprintf(bufferl,"收信");
  827. label = gtk_label_new(bufferl);
  828. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox2,label);
  829. sprintf(bufferl,"写信");
  830. label = gtk_label_new(bufferl);
  831. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  832. sprintf(bufferl,"首页");
  833. label = gtk_label_new(bufferl);
  834. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox0,label);
  835. gtk_notebook_set_page(GTK_NOTEBOOK(notebook),0);
  836. gtk_widget_show(notebook);
  837. gtk_widget_show_all(window);
  838. gtk_main();
  839. return FALSE;
  840. }

receive_all.c:

  1. #include <gtk/gtk.h>
  2. #include <string.h>
  3. #include "main.h"
  4. GtkWidget *window_receive;
  5. //char name[20]="hjlhsa";//邮件地址gggggggggggggggggg
  6. /* 用于list view */
  7. enum ListCols
  8. {
  9. LIST_CHECKED,
  10. LIST_SENDER,
  11. LIST_SUBJECT,
  12. LIST_TIME
  13. };
  14. void select_show_letter(GtkTreeSelection* select, gpointer data) //获得sender和发送时间发送给数据库
  15. {
  16. GtkTreeIter iter;
  17. GtkTreeModel* model;
  18. gchar* sender;
  19. gchar* time1;
  20. gchar* subject;
  21. char buf[100]={"hiierjhejkhjkdfh"};
  22. //gchar* info;
  23. char request[50];
  24. int len;
  25. int i;
  26. memset(request,' ',sizeof(request));
  27. if(gtk_tree_selection_get_selected(select, &model, &iter))
  28. {
  29. gtk_tree_model_get(model, &iter, LIST_SENDER, &sender,LIST_TIME,&time1,LIST_SUBJECT,&subject,-1);
  30. printf("%s\n",time1);
  31. request[0]='2';
  32. request[1]='2';
  33. len=strlen(sender);
  34. request[2]=(char)len;
  35. for(i=0;i<len;i++){
  36. request[i+3]=sender[i];
  37. }
  38. request[15]=26;
  39. for(i=0;i<26;i++){
  40. request[i+16]=time1[i];
  41. }
  42. //连接数据库,获得装有邮件内容的buf
  43. /**************************/
  44. window_show_letter(sender,subject,time1,name,buf);///弹出邮件阅读窗口,显示邮件
  45. printf("%s\n",request);
  46. g_free(sender);
  47. g_free(time1);
  48. }
  49. }
  50. GtkWidget * create_list()//创建显示邮件信息的列表
  51. {
  52. GtkWidget* vbox ;
  53. GtkTreeView* list;
  54. GtkListStore* list_store;
  55. GtkTreeIter iter;
  56. GtkCellRenderer* renderer;
  57. GtkTreeViewColumn* column;
  58. GtkTreeSelection* select;
  59. vbox = gtk_vbox_new (FALSE, 2);
  60. /* 创建ListView */
  61. list = gtk_tree_view_new();
  62. /* 创建ListView的model, 添加数据 */
  63. list_store = gtk_list_store_new(4,G_TYPE_BOOLEAN,
  64. G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
  65. //连接数据库,获得邮件列表
  66. /**************************/
  67. gtk_list_store_append(list_store, &iter);
  68. gtk_list_store_set(list_store, &iter,
  69. LIST_CHECKED,FALSE,
  70. LIST_SENDER, "KENBER",
  71. LIST_SUBJECT, "HHHHHHHHHHH",
  72. LIST_TIME,"2014年02月03日13时34分26秒" , -1);
  73. gtk_list_store_append(list_store, &iter);
  74. gtk_list_store_set(list_store, &iter,
  75. LIST_CHECKED,FALSE,
  76. LIST_SENDER, "guosiyu",
  77. LIST_SUBJECT, "uuuuuuu",
  78. LIST_TIME,"2012年02月07日13时34分26秒" , -1);
  79. gtk_tree_view_set_model(list, list_store);
  80. //g_object_unref(list_store);
  81. /* 创建ListView的View */
  82. renderer = gtk_cell_renderer_toggle_new();
  83. column = gtk_tree_view_column_new_with_attributes("选择", renderer,
  84. "active", LIST_CHECKED, NULL);
  85. column = gtk_tree_view_append_column(list, column);
  86. renderer = gtk_cell_renderer_text_new();
  87. column = gtk_tree_view_column_new_with_attributes("发件人", renderer,
  88. "text", LIST_SENDER, NULL);
  89. column = gtk_tree_view_append_column(list, column);
  90. renderer = gtk_cell_renderer_text_new();
  91. column = gtk_tree_view_column_new_with_attributes("主题", renderer,
  92. "text", LIST_SUBJECT, NULL);
  93. column = gtk_tree_view_append_column(list, column);
  94. column = gtk_tree_view_column_new_with_attributes("日期", renderer,
  95. "text", LIST_TIME, NULL);
  96. column = gtk_tree_view_append_column(list, column);
  97. //设置点击列表触发事件
  98. select = gtk_tree_view_get_selection(list);
  99. gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
  100. g_signal_connect(G_OBJECT(select), "changed",
  101. G_CALLBACK(select_show_letter), NULL);
  102. gtk_box_pack_start(vbox, list, TRUE, TRUE, 1);
  103. return vbox;
  104. }
  105. GtkWidget *make_receive_all()
  106. {
  107. // GtkWidget *window;
  108. GtkWidget *total_vbox;
  109. GtkWidget *table1;
  110. GtkWidget *button6;
  111. GtkWidget *button7;
  112. GtkWidget *button8;
  113. GtkWidget *button9;
  114. GtkWidget *button10;
  115. GtkWidget *button11;
  116. GtkWidget *label3;
  117. GtkWidget *label4;
  118. GtkWidget *entry1;
  119. GtkWidget *image;
  120. GtkWidget *vbox1;
  121. GtkWidget *hdimage;
  122. GtkWidget *label5;
  123. GtkWidget *label6;
  124. GtkWidget *label7;
  125. GtkWidget *label8;
  126. GtkWidget *label9;
  127. GtkWidget *show_box;
  128. int indx;
  129. GtkWidget *vbox;
  130. GtkWidget *scrolled_window, *clist;
  131. /*gtk_init (&argc, &argv);
  132. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  133. gtk_window_set_title(GTK_WINDOW(window), "GtkScrolledWindow");
  134. gtk_window_set_default_size(GTK_WINDOW(window), 320, 200);
  135. g_signal_connect_swapped(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit), NULL);*/
  136. total_vbox= gtk_vbox_new(FALSE,0);
  137. window_receive = gtk_scrolled_window_new (NULL, NULL);
  138. gtk_container_add (GTK_CONTAINER (total_vbox), window_receive);
  139. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window_receive),GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
  140. table1 = gtk_table_new (15,8, TRUE);
  141. image=gtk_image_new_from_file("receive.png");
  142. label3 = gtk_label_new (g_locale_to_utf8("显示:", -1, NULL, NULL, NULL));
  143. label4 = gtk_label_new (g_locale_to_utf8("搜索:", -1, NULL, NULL, NULL));
  144. button6 = gtk_button_new_with_label(g_locale_to_utf8("回 复", -1, NULL, NULL, NULL));
  145. button7 = gtk_button_new_with_label(g_locale_to_utf8("转 发", -1, NULL, NULL, NULL));
  146. button8 = gtk_button_new_with_label(g_locale_to_utf8("删 除", -1, NULL, NULL, NULL));
  147. button9 = gtk_button_new_with_label(g_locale_to_utf8("标 记", -1, NULL, NULL, NULL));
  148. button10 = gtk_button_new_with_label(g_locale_to_utf8("全部信件", -1, NULL, NULL, NULL));
  149. button11 = gtk_button_new_with_label(g_locale_to_utf8("搜 索", -1, NULL, NULL, NULL));
  150. entry1 = gtk_entry_new ();
  151. //添加表格到窗口
  152. gtk_container_add(GTK_CONTAINER (window_receive), table1);
  153. //将元件分别添加到表格中
  154. //左半边
  155. gtk_table_attach (GTK_TABLE(table1), image, 4, 8, 9, 15,
  156. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  157. gtk_table_attach (GTK_TABLE(table1), label3, 0, 1, 1, 2,
  158. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  159. gtk_table_attach (GTK_TABLE(table1), label4, 0, 1, 2, 3,
  160. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  161. gtk_table_attach (GTK_TABLE(table1), button6, 0, 1, 0, 1,
  162. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  163. gtk_table_attach (GTK_TABLE(table1), button7, 1, 2, 0, 1,
  164. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  165. gtk_table_attach (GTK_TABLE(table1), button8, 2, 3, 0, 1,
  166. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  167. gtk_table_attach (GTK_TABLE(table1), button9, 3, 4, 0, 1,
  168. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  169. gtk_table_attach (GTK_TABLE(table1), button10,1, 2, 1, 2,
  170. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  171. gtk_table_attach (GTK_TABLE(table1), button11,3, 4, 2, 3,
  172. (GtkAttachOptions)(0), (GtkAttachOptions)(0), 0, 0);
  173. gtk_table_attach (GTK_TABLE(table1), entry1,1, 3, 2, 3,
  174. GTK_FILL, GTK_FILL, 0, 0);
  175. //右半边
  176. hdimage=gtk_image_new_from_file("HD.png");
  177. label5 = gtk_label_new (g_locale_to_utf8(" 用户名: lzr", -1, NULL, NULL, NULL));
  178. label6 = gtk_label_new (g_locale_to_utf8(" 等级组: 小学生", -1, NULL, NULL, NULL));
  179. label7 = gtk_label_new (g_locale_to_utf8("个性签名:瓦格你好帅!!", -1, NULL, NULL, NULL));
  180. label8 = gtk_label_new (g_locale_to_utf8(" QQ : 保密 ", -1, NULL, NULL, NULL));
  181. label9 = gtk_label_new (g_locale_to_utf8("联系电话 : 保密 ", -1, NULL, NULL, NULL));
  182. gtk_table_attach (GTK_TABLE(table1), hdimage,4, 6, 0, 4,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  183. gtk_table_attach (GTK_TABLE(table1), label5, 5, 7, 1, 2,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  184. gtk_table_attach (GTK_TABLE(table1), label6, 5, 7, 2, 3,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  185. gtk_table_attach (GTK_TABLE(table1), label7, 3, 8, 4, 5,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  186. gtk_table_attach (GTK_TABLE(table1), label8, 3, 8, 5, 6,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  187. gtk_table_attach (GTK_TABLE(table1), label9, 3, 8, 6, 7,(GtkAttachOptions)(0), (GtkAttachOptions)(0), 5, 5);
  188. //加入滚动列表框
  189. vbox=gtk_vbox_new(FALSE, 5);
  190. gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
  191. //gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
  192. gtk_table_attach (GTK_TABLE(table1), vbox,0, 4, 3, 15,
  193. GTK_FILL, GTK_FILL, 0, 0);
  194. scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  195. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
  196. gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
  197. gtk_widget_show (scrolled_window);
  198. show_box=gtk_vbox_new(FALSE, 5);
  199. show_box=create_list();
  200. gtk_container_add(GTK_CONTAINER(scrolled_window), show_box);
  201. /* gtk_signal_connect(GTK_OBJECT(clist), "select_row",
  202. GTK_SIGNAL_FUNC(selection_made),NULL
  203. );*/
  204. // gtk_widget_show_all (window);
  205. // gtk_main();
  206. return total_vbox;
  207. }

show letter.c:

  1. #include "main.h"
  2. GtkWidget *make_box11( gboolean homogeneous,
  3. gint spacing,
  4. gboolean expand,
  5. gboolean fill,
  6. guint padding )
  7. {
  8. GtkWidget *box;
  9. GtkWidget *button;
  10. char padstr[80];
  11. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  12. box = gtk_hbox_new (homogeneous, spacing);
  13. /* 以合适的设置创建一系列的按钮 */
  14. button = gtk_button_new_with_label ("关閉");
  15. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  16. gtk_widget_show (button);
  17. button = gtk_button_new_with_label ("回复");
  18. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  19. gtk_widget_show (button);
  20. button = gtk_button_new_with_label ("转发");
  21. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  22. gtk_widget_show (button);
  23. button = gtk_button_new_with_label ("删除");
  24. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  25. gtk_widget_show (button);
  26. button = gtk_button_new_with_label ("彻底删除");
  27. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  28. gtk_widget_show (button);
  29. return box;
  30. }
  31. GtkWidget *make_box12( gboolean homogeneous,
  32. gint spacing,
  33. gboolean expand,
  34. gboolean fill,
  35. guint padding )
  36. {
  37. GtkWidget *box;
  38. GtkWidget *button;
  39. char padstr[80];
  40. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  41. box = gtk_hbox_new (homogeneous, spacing);
  42. /* 以合适的设置创建一系列的按钮 */
  43. button = gtk_button_new_with_label ("关閉");
  44. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  45. gtk_widget_show (button);
  46. button = gtk_button_new_with_label ("发送");
  47. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  48. gtk_widget_show (button);
  49. /*button = gtk_button_new_with_label ("转发");
  50. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  51. gtk_widget_show (button);*/
  52. button = gtk_button_new_with_label ("删除");
  53. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  54. gtk_widget_show (button);
  55. button = gtk_button_new_with_label ("彻底删除");
  56. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  57. gtk_widget_show (button);
  58. return box;
  59. }
  60. void window_show_letter(gchar *sender,gchar *subject,gchar* time1,char *receiver,char *buf)///弹出邮件阅读窗口,显示邮件
  61. {
  62. GtkWidget *window;
  63. GtkWidget *vbox;
  64. GtkWidget *bbox1;
  65. GtkWidget *box1;
  66. GtkWidget *bbox2;
  67. GtkWidget *bbox3;
  68. GtkWidget *bbox4;
  69. GtkWidget *label1;
  70. GtkWidget *label2;
  71. GtkWidget *label3;
  72. GtkWidget *label4;
  73. GtkWidget *label5;
  74. GtkWidget *label6;
  75. GtkWidget *label7;
  76. GtkWidget *label8;
  77. //gtk_init(&argc, &argv);
  78. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  79. gtk_widget_set_size_request(GTK_WIDGET(window),550,500);
  80. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  81. //g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
  82. gtk_window_set_title(GTK_WINDOW(window),"邮件内容");
  83. vbox = gtk_vbox_new(FALSE,0);
  84. box1 = make_box11(FALSE,0,FALSE,FALSE,3);
  85. gtk_box_pack_start(GTK_BOX(vbox),box1,FALSE,FALSE,2);
  86. bbox1 = gtk_hbox_new(FALSE,0);
  87. bbox2 = gtk_hbox_new(FALSE,0);
  88. bbox3 = gtk_hbox_new(FALSE,0);
  89. bbox4 = gtk_hbox_new(FALSE,0);
  90. label1 = gtk_label_new("主题: ");
  91. gtk_misc_set_alignment(GTK_MISC(label1),0,0);
  92. label2 = gtk_label_new("发件人:");
  93. label3 = gtk_label_new("时间: ");
  94. label4 = gtk_label_new("收件人:");
  95. label5 = gtk_label_new(subject);
  96. label6 = gtk_label_new(sender);
  97. label7 = gtk_label_new(time1);
  98. label8 = gtk_label_new(receiver);
  99. gtk_box_pack_start(GTK_BOX(bbox1),label1,FALSE,FALSE,0);
  100. gtk_box_pack_start(GTK_BOX(bbox1),label5,FALSE,FALSE,0);
  101. gtk_box_pack_start(GTK_BOX(vbox),bbox1,FALSE,FALSE,2);
  102. gtk_box_pack_start(GTK_BOX(bbox2),label2,FALSE,FALSE,2);
  103. gtk_box_pack_start(GTK_BOX(bbox2),label6,FALSE,FALSE,2);
  104. gtk_box_pack_start(GTK_BOX(vbox),bbox2,FALSE,FALSE,2);
  105. gtk_box_pack_start(GTK_BOX(bbox3),label3,FALSE,FALSE,2);
  106. gtk_box_pack_start(GTK_BOX(bbox3),label7,FALSE,FALSE,2);
  107. gtk_box_pack_start(GTK_BOX(vbox),bbox3,FALSE,FALSE,2);
  108. gtk_box_pack_start(GTK_BOX(bbox4),label4,FALSE,FALSE,2);
  109. gtk_box_pack_start(GTK_BOX(bbox4),label8,FALSE,FALSE,2);
  110. gtk_box_pack_start(GTK_BOX(vbox),bbox4,FALSE,FALSE,2);
  111. gtk_container_add(GTK_CONTAINER(window),vbox);
  112. gtk_widget_show_all(vbox);
  113. gtk_widget_show_all(window);
  114. //gtk_main();
  115. return 0;
  116. }
  117. void window_show_caogao(gchar *sender,gchar *subject,char *receiver,char *buf)///弹出邮件阅读窗口,显示邮件
  118. {
  119. GtkWidget *window;
  120. GtkWidget *vbox;
  121. GtkWidget *bbox1;
  122. GtkWidget *box1;
  123. GtkWidget *bbox2;
  124. GtkWidget *bbox3;
  125. GtkWidget *bbox4;
  126. GtkWidget *label1;
  127. GtkWidget *label2;
  128. //GtkWidget *label3;
  129. GtkWidget *label4;
  130. GtkWidget *label5;
  131. GtkWidget *label6;
  132. //GtkWidget *label7;
  133. GtkWidget *label8;
  134. //gtk_init(&argc, &argv);
  135. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  136. gtk_widget_set_size_request(GTK_WIDGET(window),550,500);
  137. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  138. //g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
  139. gtk_window_set_title(GTK_WINDOW(window),"邮件内容");
  140. vbox = gtk_vbox_new(FALSE,0);
  141. box1 = make_box12(FALSE,0,FALSE,FALSE,3);
  142. gtk_box_pack_start(GTK_BOX(vbox),box1,FALSE,FALSE,2);
  143. bbox1 = gtk_hbox_new(FALSE,0);
  144. bbox2 = gtk_hbox_new(FALSE,0);
  145. bbox3 = gtk_hbox_new(FALSE,0);
  146. bbox4 = gtk_hbox_new(FALSE,0);
  147. label1 = gtk_label_new("主题: ");
  148. gtk_misc_set_alignment(GTK_MISC(label1),0,0);
  149. label2 = gtk_label_new("发件人:");
  150. //label3 = gtk_label_new("时间: ");
  151. label4 = gtk_label_new("收件人:");
  152. label5 = gtk_label_new(subject);
  153. label6 = gtk_label_new(sender);
  154. //label7 = gtk_label_new(time1);
  155. label8 = gtk_label_new(receiver);
  156. gtk_box_pack_start(GTK_BOX(bbox1),label1,FALSE,FALSE,0);
  157. gtk_box_pack_start(GTK_BOX(bbox1),label5,FALSE,FALSE,0);
  158. gtk_box_pack_start(GTK_BOX(vbox),bbox1,FALSE,FALSE,2);
  159. gtk_box_pack_start(GTK_BOX(bbox2),label2,FALSE,FALSE,2);
  160. gtk_box_pack_start(GTK_BOX(bbox2),label6,FALSE,FALSE,2);
  161. gtk_box_pack_start(GTK_BOX(vbox),bbox2,FALSE,FALSE,2);
  162. //gtk_box_pack_start(GTK_BOX(bbox3),label3,FALSE,FALSE,2);
  163. //gtk_box_pack_start(GTK_BOX(bbox3),label7,FALSE,FALSE,2);
  164. gtk_box_pack_start(GTK_BOX(vbox),bbox3,FALSE,FALSE,2);
  165. gtk_box_pack_start(GTK_BOX(bbox4),label4,FALSE,FALSE,2);
  166. gtk_box_pack_start(GTK_BOX(bbox4),label8,FALSE,FALSE,2);
  167. gtk_box_pack_start(GTK_BOX(vbox),bbox4,FALSE,FALSE,2);
  168. gtk_container_add(GTK_CONTAINER(window),vbox);
  169. gtk_widget_show_all(vbox);
  170. gtk_widget_show_all(window);
  171. //gtk_main();
  172. return 0;
  173. }
main.h:

  1. #ifndef _ADD_H_
  2. #define _ADD_H_
  3. #include <gtk/gtk.h>
  4. #include <string.h>
  5. char name[20];
  6. void select_show_letter(GtkTreeSelection* select, gpointer data); //获得sender和发送时间发送给数据库
  7. GtkWidget * create_list();//创建显示邮件信息的列表
  8. void window_show_letter(gchar *sender,gchar *subject,gchar* time1,char *receiver,char *buf);///弹出邮件阅读窗口,显示邮件
  9. GtkWidget *make_box1( gboolean homogeneous,
  10. gint spacing,
  11. gboolean expand,
  12. gboolean fill,
  13. guint padding ) ;
  14. //nootbook中的函数
  15. int change_color ( );//改变颜色
  16. void on_ok_clicked (GtkButton* button, gpointer data);//改变颜色
  17. void cleanup();//清空重新编辑
  18. int change_ziti();//改变字体
  19. void on_font_select_ok (GtkWidget *button,GtkFontSelectionDialog *fs);
  20. void on_button_clicked (GtkWidget *button,gpointer userdata);
  21. void get_recer(char* re_name);
  22. void get_misong(char* misong_name);
  23. void get_title(char* title);
  24. void get_text();
  25. void get_time(char* time);
  26. /*发送写信页面发送所有内容********************************************************************gggggggggggggggggggggg*/
  27. int xiexin_cbd();
  28. /*草稿箱************************************************************************************/
  29. int caogao_cbd();
  30. int change_color ( );
  31. void on_ok_clicked (GtkButton* button, gpointer data);
  32. /*改变字体******************************************************************************/
  33. void on_font_select_ok (GtkWidget *button,GtkFontSelectionDialog *fs);
  34. void on_button_clicked (GtkWidget *button,gpointer userdata);
  35. GtkWidget *make_box1( gboolean homogeneous, //写信
  36. gint spacing,
  37. gboolean expand,
  38. gboolean fill,
  39. guint padding );
  40. GtkWidget *make_box2( gboolean homogeneous, //已发送
  41. gint spacing,
  42. gboolean expand,
  43. gboolean fill,
  44. guint padding );
  45. GtkWidget *make_box3( gboolean homogeneous, //已删除
  46. gint spacing,
  47. gboolean expand,
  48. gboolean fill,
  49. guint padding );
  50. /*GtkWidget *make_box4( gboolean homogeneous, //草稿箱
  51. gint spacing,
  52. gboolean expand,
  53. gboolean fill,
  54. guint padding );*/
  55. /*notebook部分函数**********************************************************************/
  56. void tabsborder_book( GtkButton *button,
  57. GtkNotebook *notebook );
  58. void delete(GtkWidget *widget,GtkWidget *event,gpointer data);
  59. // tianjia kucun ID gongju anniu
  60. GtkWidget * addStockToolItem(GtkWidget *toolbar, const gchar *stockid, const gchar *tooltip);
  61. //tian jia fen ge gong ju xiang
  62. GtkWidget *addSeparatorToolItem(GtkWidget* toolbar);
  63. //tian jia gong ju xiang
  64. GtkWidget * addToolItem(GtkWidget* toolbar, const gchar *pLabel, const gchar *tooltip, const gchar *pImageFile);
  65. ///
  66. GtkWidget *make_receive_all();//制作收件箱包含在笔记本中的vbox
  67. GtkWidget *make_caogaoxiang();//制作草稿箱包含在笔记本中的vbox
  68. void select_show_caogao(GtkTreeSelection* select, gpointer data); //获得账号和发送时间发送给数据库
  69. void window_show_caogao(gchar *sender,gchar *subject,char *receiver,char *buf);///弹出草稿阅读窗口,显示邮件
  70. GtkWidget * create_list_caogao();//创建显示草稿箱信息的列表
  71. #endif

makefile:

CC=gcc
INCLUDIR = ./include

all:
#	gcc register.c -o register `pkg-config --cflags --libs gtk+-2.0`
	gcc ./src/*.c -o login -I./include `pkg-config --cflags --libs gtk+-2.0` 
#	gcc main.c -o main `pkg-config --cflags --libs gtk+-2.0`
#	gcc new.c -o new `pkg-config --cflags --libs gtk+-2.0` 

zhuce.c:

  1. #include<gtk/gtk.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<sys/socket.h>
  6. #include<netinet/in.h>
  7. #include<arpa/inet.h>
  8. #include<netdb.h>
  9. char* host_name="127.0.0.1";//"192.168.100.1";
  10. int port=8888;
  11. char name[20],nicheng[20],pass[20],pass1[20],tel[20];
  12. GtkWidget *entry_name;//邮件地址
  13. GtkWidget *entry_nicheng;//昵称
  14. GtkWidget *entry_pass;//密码
  15. GtkWidget *entry_pass1;//确认密码
  16. GtkWidget *entry_tel;//手机号
  17. /*调用连接数据库的函数**********************************************************************/
  18. int zhuce_cdb()
  19. {
  20. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  21. char buf[1024];
  22. memset(buf,0,sizeof(buf));
  23. /*传入数据库的各个字符串的拼接*********************************************************/
  24. char str[1024];//str表示拼接后的字符串
  25. memset(str,' ',sizeof(str));
  26. printf("str0:%s\n",str);
  27. int i,j,a=11;
  28. str[0]='u';
  29. str[1]='0';
  30. str[2]=(char)strlen(name);
  31. printf("char c:%c\n",str[2]);
  32. for(i=0;name[i]!='\0';i++)
  33. {
  34. str[i+3]=name[i];
  35. }
  36. printf("str:%s\n",str);
  37. str[15]=(char)strlen(pass);
  38. for(i=0;pass[i]!='\0';i++)
  39. {
  40. str[i+16]=pass[i];
  41. }
  42. printf("str:%s\n",str);
  43. str[32]=(char)strlen(nicheng);
  44. for(i=0;nicheng[i]!='\0';i++)
  45. {
  46. str[i+33]=nicheng[i];
  47. }
  48. printf("str:%s\n",str);
  49. str[53]=(char)a;
  50. for(i=0;tel[i]!='\0';i++)
  51. {
  52. str[i+54]=tel[i];
  53. }
  54. printf("str:%s\n",str);
  55. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  56. /*传入数据库的各个字符串的拼接结束*********************************************************/
  57. /*if(argc < 2)
  58. {
  59. printf("send default string.\n");
  60. }
  61. else
  62. {
  63. str=argv[1];
  64. }
  65. if((server_host_name=gethostbyname(host_name))==0)
  66. {
  67. herror("can not resoving localhost\n");
  68. exit(1);
  69. }*/
  70. int socket_descriptor;
  71. int temp_sock_descriptor;
  72. int size_of_addr;
  73. struct sockaddr_in sin;
  74. struct sockaddr_in pin;
  75. struct hostent * server_host_name;
  76. bzero(&pin, sizeof(pin));
  77. pin.sin_family=AF_INET;
  78. pin.sin_addr.s_addr = inet_addr("127.0.0.1");
  79. pin.sin_port=htons(port);
  80. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  81. if((socket_descriptor=socket(AF_INET, SOCK_STREAM, 0))==-1)
  82. {
  83. perror("error opening socket\n");
  84. exit(1);
  85. }
  86. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  87. if(connect(socket_descriptor, (void*)&pin, sizeof(pin))==-1)
  88. {
  89. perror("can not connecting to server\n");
  90. exit(1);
  91. }
  92. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  93. printf("%c,%c,%c,%c\n",str[3],str[16],str[33],str[54]);
  94. if(send(socket_descriptor, str, strlen(str), 0)==-1)
  95. {
  96. perror("can not send message\n");
  97. exit(1);
  98. }
  99. printf("%c,%c,%c,%c\n",str[3],str[16],str[33],str[54]);
  100. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  101. memset(buf, 0, 1024);
  102. if(recv(socket_descriptor, buf, sizeof(buf), 0)<0)//==-1)
  103. {
  104. perror("can not receive response\n");
  105. exit(1);
  106. }
  107. else{
  108. printf("message received from server:%s\n",buf);
  109. }
  110. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  111. close(socket_descriptor);
  112. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  113. return 0;
  114. }
  115. /*显示错误信息并跳出警告对话框*************************************************/
  116. void warning(char *warn)
  117. {
  118. GtkWidget *window;
  119. GtkWidget *button;
  120. GtkWidget *label; //错误信息的label
  121. GtkWidget *box;
  122. window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  123. gtk_window_set_title(GTK_WINDOW(window),"警告");
  124. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  125. gtk_container_set_border_width (GTK_CONTAINER (window),100);
  126. label=gtk_label_new (warn);
  127. //gtk_label_set_markup(GTK_LABEL(label),"<span foreground='black'font_desc='16'>收信 </span>");
  128. //gtk_label_set_markup(GTK_LABEL(recive_label),"<span foreground='black'font_desc='16'>收信 </span>");
  129. button=gtk_button_new_with_label ("确定");
  130. box=gtk_vbox_new (FALSE, 0);
  131. gtk_box_pack_start(GTK_BOX(box),label,FALSE,FALSE,3);
  132. gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,3);
  133. gtk_container_add (GTK_CONTAINER (window), box);
  134. gtk_widget_show_all(box);
  135. gtk_widget_show_all(window);
  136. g_signal_connect_swapped(G_OBJECT (button), "clicked",
  137. G_CALLBACK (gtk_widget_destroy), window);
  138. //return FALSE;
  139. }
  140. /*返回值是1时提示注册成功*************************************************/
  141. int success()
  142. {
  143. GtkWidget *window;
  144. GtkWidget *button;
  145. GtkWidget *label; //成功的label
  146. GtkWidget *box;
  147. window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  148. gtk_window_set_title(GTK_WINDOW(window),NULL);
  149. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  150. gtk_container_set_border_width (GTK_CONTAINER (window),100);
  151. label=gtk_label_new ("恭喜,注册成功!");
  152. //gtk_label_set_markup(GTK_LABEL(rlabel),"<span foreground='black'font_desc='16'>恭喜,注册成功! </span>");
  153. button=gtk_button_new_with_label ("确定");
  154. box=gtk_vbox_new (FALSE, 0);
  155. gtk_box_pack_start(GTK_BOX(box),label,FALSE,FALSE,3);
  156. gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,3);
  157. gtk_container_add (GTK_CONTAINER (window), box);
  158. gtk_widget_show_all(box);
  159. gtk_widget_show_all(window);
  160. g_signal_connect_swapped(G_OBJECT (button), "clicked",
  161. G_CALLBACK (gtk_main_quit), window);
  162. return FALSE;
  163. }
  164. /*返回值是0时提示邮件地址重复*************************************************/
  165. int fail()
  166. {
  167. GtkWidget *window;
  168. GtkWidget *button;
  169. GtkWidget *label; //用户名重复的label
  170. GtkWidget *box;
  171. window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  172. gtk_window_set_title(GTK_WINDOW(window),NULL);
  173. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  174. gtk_container_set_border_width (GTK_CONTAINER (window),100);
  175. label=gtk_label_new ("对不起,邮件地址已存在,请更换新的邮件地址");
  176. //gtk_label_set_markup(GTK_LABEL(label),"<span foreground='black'font_desc='16'>对不起,邮件地址已存在,请更换新的邮件地址</span>");
  177. button=gtk_button_new_with_label ("确定");
  178. box=gtk_vbox_new (FALSE, 0);
  179. gtk_box_pack_start(GTK_BOX(box),label,FALSE,FALSE,3);
  180. gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,3);
  181. gtk_container_add (GTK_CONTAINER (window), box);
  182. gtk_widget_show_all(box);
  183. gtk_widget_show_all(window);
  184. g_signal_connect_swapped(G_OBJECT (button), "clicked",
  185. G_CALLBACK (gtk_widget_destroy), window);
  186. return FALSE;
  187. }
  188. /*点击重置按钮后重置*******************************************************/
  189. void chongzhi(GtkWidget *widget)
  190. {
  191. gtk_entry_set_text(GTK_ENTRY(entry_name),"");
  192. gtk_entry_set_text(GTK_ENTRY(entry_nicheng),"");
  193. gtk_entry_set_text(GTK_ENTRY(entry_pass),"");
  194. gtk_entry_set_text(GTK_ENTRY(entry_pass1),"");
  195. gtk_entry_set_text(GTK_ENTRY(entry_tel),"");
  196. }
  197. /*点击提交按钮,判断无误后提交,调用传给数据库的函数*************************/
  198. int tijiao(GtkWidget *widget)
  199. {
  200. int i,l;
  201. char* warn=NULL;
  202. strcpy(name,gtk_entry_get_text(GTK_ENTRY(entry_name)));
  203. strcpy(nicheng,gtk_entry_get_text(GTK_ENTRY(entry_nicheng)));
  204. strcpy(pass,gtk_entry_get_text(GTK_ENTRY(entry_pass)));
  205. strcpy(pass1,gtk_entry_get_text(GTK_ENTRY(entry_pass1)));
  206. strcpy(tel,gtk_entry_get_text(GTK_ENTRY(entry_tel)));
  207. /*判断各个entry是否为空*******************/
  208. if(strlen(name)==0)
  209. {
  210. warn="邮件地址不能为空";
  211. warning(warn);
  212. return 0;
  213. }
  214. else if(strlen(nicheng)==0)
  215. {
  216. warn="昵称不能为空";
  217. warning(warn);
  218. return 0;
  219. }
  220. else if(strlen(pass)==0)
  221. {
  222. warn="密码不能为空";
  223. warning(warn);
  224. return 0;
  225. }
  226. else if(strlen(pass1)==0)
  227. {
  228. warn="确认密码不能为空";
  229. warning(warn);
  230. return 0;
  231. }
  232. else if(strlen(tel)==0)
  233. {
  234. warn="手机号不能为空";
  235. warning(warn);
  236. return 0;
  237. }
  238. else //当内容都不为空时,开始检验输入是否合法
  239. {
  240. for(i=0;i<strlen(name);)//判断name内容是否符合要求
  241. {
  242. if(strlen(name)<6||strlen(name)>12){warn="邮件地址输入不符合要求";warning(warn);return 0;}
  243. else if((name[i]>='A'&&name[i]<='Z')||(name[i]>='a'&&name[i]<='z')||(name[i]>='0'&&name[i]<='9')||name[i]=='_')
  244. {
  245. i++;
  246. }
  247. else
  248. {
  249. warn="邮件地址输入不符合要求";
  250. warning(warn);
  251. return 0;
  252. }
  253. }
  254. for(i=0;i<strlen(nicheng);)//判断nicheng内容是否符合要求
  255. {
  256. if(strlen(nicheng)<3||strlen(nicheng)>10){warn="昵称输入不符合要求";warning(warn);return 0;}
  257. else if((nicheng[i]>='A'&&nicheng[i]<='Z')||(nicheng[i]>='a'&&nicheng[i]<='z')||(nicheng[i]>='0'&&nicheng[i]<='9')||nicheng[i]=='_')
  258. {
  259. i++;
  260. }
  261. else
  262. {
  263. warn="昵称输入不符合要求";
  264. warning(warn);
  265. return 0;
  266. }
  267. }
  268. for(i=0;i<strlen(pass);)//判断pass内容是否符合要求
  269. {
  270. if(strlen(pass)<6||strlen(pass)>16){warn="密码输入不符合要求";warning(warn);return 0;}
  271. else if((pass[i]>='A'&&pass[i]<='Z')||(pass[i]>='a'&&pass[i]<='z')||(pass[i]>='0'&&pass[i]<='9')||pass[i]=='_')
  272. {
  273. i++;
  274. }
  275. else
  276. {
  277. warn="密码输入不符合要求";
  278. warning(warn);
  279. return 0;
  280. }
  281. }
  282. for(i=0;i<strlen(pass);)//判断pass1内容是否符合与pass一致
  283. {
  284. if(pass1[i]==pass[i])
  285. {
  286. i++;
  287. }
  288. else
  289. {
  290. warn="两次输入密码不一致";
  291. warning(warn);
  292. return 0;
  293. }
  294. }
  295. for(i=0;i<strlen(tel);)//判断tel内容是否符合要求
  296. {
  297. if(strlen(tel)==11&&tel[i]>='0'&&tel[i]<='9')
  298. {
  299. i++;
  300. }
  301. else
  302. {
  303. warn="手机号输入不符合要求";
  304. warning(warn);
  305. return 0;
  306. }
  307. }
  308. }//当内容都不为空时,开始检验输入是否合法
  309. /*调用连接数据库的函数****************************/
  310. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  311. zhuce_cdb();
  312. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  313. }
  314. int main(int argc ,char *argv[])//此函数中1,2,3,4,5分别代表5行
  315. {
  316. GtkWidget *window;
  317. GtkWidget *totalbox;
  318. GtkWidget *hbox1;
  319. GtkWidget *hbox2;
  320. GtkWidget *hbox3;
  321. GtkWidget *hbox4;
  322. GtkWidget *hbox5;
  323. GtkWidget *hbox6;
  324. GtkWidget *ybutton;//提交按钮
  325. GtkWidget *nbutton;//重置
  326. GtkWidget *label11;
  327. GtkWidget *label12;
  328. GtkWidget *label21;
  329. GtkWidget *label22;
  330. GtkWidget *label31;
  331. GtkWidget *label32;
  332. GtkWidget *label41;
  333. GtkWidget *label42;
  334. GtkWidget *label51;
  335. GtkWidget *label52;
  336. GtkWidget *name_entry;
  337. GtkWidget *nicheng_entry;
  338. GtkWidget *pass_entry;
  339. GtkWidget *pass1_entry;
  340. GtkWidget *tel_entry;
  341. gtk_init(&argc,&argv);
  342. window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  343. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  344. gtk_container_set_border_width (GTK_CONTAINER (window),150);
  345. g_signal_connect(G_OBJECT(window),"delete_event",
  346. G_CALLBACK(gtk_main_quit),NULL);
  347. gtk_window_set_title(GTK_WINDOW(window),"用戶注冊");
  348. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  349. /* 设置窗口边框的宽度。*/
  350. gtk_container_set_border_width (GTK_CONTAINER (window),90);
  351. /* 整个盒为一个纵盒,將纵盒装入窗口*/
  352. totalbox=gtk_vbox_new (FALSE, 0);
  353. gtk_container_add (GTK_CONTAINER (window), totalbox);
  354. hbox1=gtk_hbox_new (FALSE, 0);
  355. hbox2=gtk_hbox_new (FALSE, 6);
  356. hbox3=gtk_hbox_new (FALSE, 6);
  357. hbox4=gtk_hbox_new (FALSE, 0);
  358. hbox5=gtk_hbox_new (FALSE, 1);
  359. hbox6=gtk_hbox_new (FALSE, 80);
  360. label11=gtk_label_new("*邮件地址");
  361. label12=gtk_label_new("6~12个数字字母下划线组成");
  362. label21=gtk_label_new("*呢称 ");
  363. label22=gtk_label_new("3~10个数字字母下划线组成");
  364. label31=gtk_label_new("*密码 ");
  365. label32=gtk_label_new("6~16个數字字母下划线组成");
  366. label41=gtk_label_new("*确认密码");
  367. label42=gtk_label_new("再次输入以确认密码");
  368. label51=gtk_label_new("*手机号 ");
  369. label52=gtk_label_new("以便找回时使用");
  370. entry_name=name_entry=gtk_entry_new();
  371. //gtk_entry_set_text(GTK_ENTRY(name_entry),FALSE);
  372. entry_nicheng=nicheng_entry=gtk_entry_new();
  373. //gtk_entry_set_text(GTK_ENTRY(nicheng_entry),FALSE);
  374. entry_pass=pass_entry=gtk_entry_new();
  375. gtk_entry_set_visibility(GTK_ENTRY(pass_entry),FALSE);
  376. entry_pass1=pass1_entry=gtk_entry_new();
  377. gtk_entry_set_visibility(GTK_ENTRY(pass1_entry),FALSE);
  378. entry_tel=tel_entry=gtk_entry_new();
  379. //gtk_entry_set_text(GTK_ENTRY(tel_entry),FALSE);
  380. ybutton = gtk_button_new_with_label ("提交");
  381. nbutton = gtk_button_new_with_label ("重置");
  382. gtk_box_pack_start(GTK_BOX(hbox1),label11,FALSE,FALSE,5);
  383. gtk_box_pack_start(GTK_BOX(hbox1),entry_name,FALSE,FALSE,5);
  384. gtk_box_pack_start(GTK_BOX(hbox1),label12,FALSE,FALSE,10);
  385. gtk_box_pack_start(GTK_BOX(hbox2),label21,FALSE,FALSE,5);
  386. gtk_box_pack_start(GTK_BOX(hbox2),entry_nicheng,FALSE,FALSE,5);
  387. gtk_box_pack_start(GTK_BOX(hbox2),label22,FALSE,FALSE,5);
  388. gtk_box_pack_start(GTK_BOX(hbox3),label31,FALSE,FALSE,5);
  389. gtk_box_pack_start(GTK_BOX(hbox3),entry_pass,FALSE,FALSE,5);
  390. gtk_box_pack_start(GTK_BOX(hbox3),label32,FALSE,FALSE,5);
  391. gtk_box_pack_start(GTK_BOX(hbox4),label41,FALSE,FALSE,5);
  392. gtk_box_pack_start(GTK_BOX(hbox4),entry_pass1,FALSE,FALSE,5);
  393. gtk_box_pack_start(GTK_BOX(hbox4),label42,FALSE,FALSE,9);
  394. gtk_box_pack_start(GTK_BOX(hbox5),label51,FALSE,FALSE,5);
  395. gtk_box_pack_start(GTK_BOX(hbox5),entry_tel,FALSE,FALSE,5);
  396. gtk_box_pack_start(GTK_BOX(hbox5),label52,FALSE,FALSE,9);
  397. gtk_box_pack_start(GTK_BOX(hbox6),ybutton,FALSE,FALSE,90);
  398. gtk_box_pack_start(GTK_BOX(hbox6),nbutton,FALSE,FALSE,5);
  399. gtk_box_pack_start(GTK_BOX(totalbox),hbox1,FALSE,FALSE,5);
  400. gtk_box_pack_start(GTK_BOX(totalbox),hbox2,FALSE,FALSE,5);
  401. gtk_box_pack_start(GTK_BOX(totalbox),hbox3,FALSE,FALSE,5);
  402. gtk_box_pack_start(GTK_BOX(totalbox),hbox4,FALSE,FALSE,5);
  403. gtk_box_pack_start(GTK_BOX(totalbox),hbox5,FALSE,FALSE,5);
  404. gtk_box_pack_start(GTK_BOX(totalbox),hbox6,FALSE,FALSE,50);
  405. g_signal_connect(G_OBJECT(nbutton), "clicked",G_CALLBACK(chongzhi), NULL);
  406. g_signal_connect(G_OBJECT(ybutton), "clicked",G_CALLBACK(tijiao), NULL);
  407. gtk_widget_show_all(window);
  408. gtk_main();
  409. return FALSE;
  410. }

login.c:

  1. #include <gtk/gtk.h>
  2. #include <string.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<sys/socket.h>
  6. #include<netinet/in.h>
  7. #include<arpa/inet.h>
  8. #include<netdb.h>
  9. //int sign=1;
  10. /*typedef struct
  11. {
  12. char name[20];
  13. char pass[20];
  14. }info;
  15. info *information;*/
  16. GtkWidget *entry_name;
  17. GtkWidget *entry_pass;
  18. GtkWidget *window_all;
  19. char* host_name="127.0.0.1";//"192.168.100.1";
  20. int port=9999;
  21. GtkWidget *make_box1( gboolean homogeneous,
  22. gint spacing,
  23. gboolean expand,
  24. gboolean fill,
  25. guint padding )
  26. {
  27. GtkWidget *box;
  28. GtkWidget *button;
  29. char padstr[80];
  30. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  31. box = gtk_hbox_new (homogeneous, spacing);
  32. /* 以合适的设置创建一系列的按钮 */
  33. button = gtk_button_new_with_label ("发送");
  34. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  35. gtk_widget_show (button);
  36. button = gtk_button_new_with_label ("存草稿");
  37. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  38. gtk_widget_show (button);
  39. button = gtk_button_new_with_label ("关閉");
  40. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  41. gtk_widget_show (button);
  42. return box;
  43. }
  44. GtkWidget *make_box2( gboolean homogeneous,
  45. gint spacing,
  46. gboolean expand,
  47. gboolean fill,
  48. guint padding )
  49. {
  50. GtkWidget *box;
  51. GtkWidget *button;
  52. char padstr[80];
  53. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  54. box = gtk_hbox_new (homogeneous, spacing);
  55. /* 以合适的设置创建一系列的按钮 */
  56. button = gtk_button_new_with_label ("添加抄送");
  57. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  58. gtk_widget_show (button);
  59. button = gtk_button_new_with_label ("添加密送");
  60. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  61. gtk_widget_show (button);
  62. return box;
  63. }
  64. GtkWidget *make_box3( gboolean homogeneous,
  65. gint spacing,
  66. gboolean expand,
  67. gboolean fill,
  68. guint padding )
  69. {
  70. GtkWidget *box;
  71. GtkWidget *button;
  72. char padstr[80];
  73. /* 以合适的 homogeneous 和 spacing 设置创建一个新的横向盒 */
  74. box = gtk_hbox_new (homogeneous, spacing);
  75. /* 以合适的设置创建一系列的按钮 */
  76. button = gtk_button_new_with_label ("添加附件");
  77. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  78. gtk_widget_show (button);
  79. button = gtk_button_new_with_label ("格式");
  80. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  81. gtk_widget_show (button);
  82. button = gtk_button_new_with_label ("信纸");
  83. gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
  84. gtk_widget_show (button);
  85. return box;
  86. }
  87. void tabsborder_book( GtkButton *button,
  88. GtkNotebook *notebook )
  89. {
  90. gint bval = FALSE;
  91. if (notebook->show_border == 0)
  92. bval = TRUE;
  93. gtk_notebook_set_show_border (notebook, bval);
  94. }
  95. void delete(GtkWidget *widget,GtkWidget *event,gpointer data)
  96. {
  97. gtk_main_quit();
  98. }
  99. void quit( GtkWidget *widget, gpointer data )
  100. {
  101. g_print ("Hello World\n");
  102. }
  103. int compare(char *name,char *pass)//將用戶名和密码与数据库中的相对比,合法返回1,不合法返回0
  104. {
  105. int sign=0;
  106. printf("name:%s\n",name);
  107. printf("pass:%s\n",pass);
  108. char buf[8192];
  109. char str[1024];//str表示拼接后的字符串
  110. memset(str,' ',sizeof(str));
  111. memset(buf,0,sizeof(buf));
  112. int socket_descriptor;
  113. int temp_sock_descriptor;
  114. int size_of_addr;
  115. struct sockaddr_in sin;
  116. struct sockaddr_in pin;
  117. struct hostent * server_host_name;
  118. bzero(&pin, sizeof(pin));
  119. pin.sin_family=AF_INET;
  120. pin.sin_addr.s_addr = inet_addr("127.0.0.1");
  121. pin.sin_port=htons(port);
  122. str[0]='u';
  123. str[1]='1';
  124. int i=0,l=0;
  125. l=strlen(name);
  126. printf("len_name:%d\nname:",l);
  127. str[2]=(char)l;
  128. for(i=3;i<l+3;i++){
  129. str[i]=name[i-3];
  130. printf("%c",str[i]);
  131. }
  132. printf("\n");
  133. l=strlen(pass);
  134. printf("len_pass:%d\npassword:",l);
  135. str[15]=(char)l;
  136. for(i=16;i<l+16;i++){
  137. str[i]=pass[i-16];
  138. printf("%c",str[i]);
  139. }
  140. printf("\n");
  141. printf("str:%s\n",str);
  142. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  143. if((socket_descriptor=socket(AF_INET, SOCK_STREAM, 0))==-1)
  144. {
  145. perror("error opening socket\n");
  146. exit(1);
  147. }
  148. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  149. if(connect(socket_descriptor, (void*)&pin, sizeof(pin))==-1)
  150. {
  151. perror("can not connecting to server\n");
  152. exit(1);
  153. }
  154. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  155. if(send(socket_descriptor, str, strlen(str), 0)==-1)
  156. {
  157. perror("can not send message\n");
  158. exit(1);
  159. }
  160. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  161. memset(buf, 0, 8192);
  162. if(recv(socket_descriptor, buf, sizeof(buf), 0)<0)//==-1)
  163. {
  164. perror("can not receive response\n");
  165. exit(1);
  166. }
  167. else{
  168. printf("message received from server:%s\n",buf);
  169. if(strcmp(buf,"login_success")==0){
  170. sign=1;
  171. }
  172. else{
  173. sign=0;
  174. }
  175. }
  176. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  177. close(socket_descriptor);
  178. printf("[%s, %s, %d]\n", __FILE__, __FUNCTION__, __LINE__);
  179. return sign;
  180. }
  181. void log_in( GtkWidget *widget,gpointer data )
  182. {
  183. char name[20];
  184. char pass[20];
  185. int sign=0;
  186. strcpy(name,gtk_entry_get_text(GTK_ENTRY(entry_name)));
  187. strcpy(pass,gtk_entry_get_text(GTK_ENTRY(entry_pass)));
  188. sign=compare(name,pass);
  189. if(sign)//登入主界面
  190. {
  191. /*.......*/
  192. GtkWidget *window;
  193. GtkWidget *table;
  194. GtkWidget *logo;
  195. GtkWidget *name_label;
  196. GtkWidget *out_event_box;
  197. GtkWidget *out_label;
  198. GtkWidget *temp_label;
  199. GtkWidget *settings_label;
  200. GtkWidget *settings_event_box;
  201. GtkWidget *change_event_box;
  202. GtkWidget *change_label;
  203. GtkWidget *write_image;
  204. GtkWidget *write_label;
  205. GtkWidget *write_event_box;
  206. GtkWidget *recive_label;
  207. GtkWidget *recive_image;
  208. GtkWidget *recive_event_box;
  209. GtkWidget *contactor_image;
  210. GtkWidget *contactor_label;
  211. GtkWidget *contactor_event_box;
  212. window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  213. gtk_window_set_title(GTK_WINDOW(window),"主界面");
  214. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  215. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  216. gtk_container_set_border_width (GTK_CONTAINER (window),100);
  217. //添一个表控件
  218. table = gtk_table_new (12, 14, FALSE);
  219. gtk_container_add (GTK_CONTAINER (window), table);
  220. //添loge
  221. logo = gtk_image_new_from_file ("logo.png");
  222. gtk_table_attach_defaults (GTK_TABLE (table), logo, 0, 2, 0, 2);
  223. //用户名
  224. name_label=gtk_label_new ("用户名<");
  225. gtk_table_attach_defaults (GTK_TABLE (table), name_label, 5, 6, 0, 1);
  226. name_label=gtk_label_new (name);
  227. gtk_table_attach_defaults (GTK_TABLE (table), name_label, 6, 8, 0, 1);
  228. name_label=gtk_label_new (">");
  229. gtk_table_attach_defaults (GTK_TABLE (table), name_label, 9, 10, 0, 1);
  230. //时间
  231. /*........*/
  232. //退出
  233. out_event_box= gtk_event_box_new ();
  234. gtk_table_attach_defaults (GTK_TABLE (table), out_event_box, 13, 14, 0, 1);
  235. out_label=gtk_label_new_with_mnemonic("_退出");
  236. gtk_label_set_pattern (GTK_LABEL (out_label), "___");
  237. gtk_container_add (GTK_CONTAINER (out_event_box), out_label);
  238. gtk_widget_set_events (out_event_box, GDK_BUTTON_PRESS_MASK);
  239. g_signal_connect (G_OBJECT (out_event_box), "button_press_event",
  240. G_CALLBACK (quit), NULL);
  241. //gtk_widget_realize (out_event_box);
  242. gdk_window_set_cursor (out_event_box->window, gdk_cursor_new (GDK_HAND1));
  243. //邮箱首页
  244. //邮件搜索
  245. //设置
  246. settings_event_box= gtk_event_box_new ();
  247. gtk_table_attach_defaults (GTK_TABLE (table), settings_event_box, 5, 6, 1, 2);
  248. settings_label=gtk_label_new_with_mnemonic("_设置");
  249. gtk_label_set_pattern (GTK_LABEL (settings_label), "___");
  250. gtk_container_add (GTK_CONTAINER (settings_event_box), settings_label);
  251. gtk_widget_set_events (settings_event_box, GDK_BUTTON_PRESS_MASK);
  252. g_signal_connect (G_OBJECT (settings_event_box), "button_press_event",
  253. G_CALLBACK (quit), NULL);
  254. //gtk_widget_realize (settings_event_box); //failed
  255. gdk_window_set_cursor (settings_event_box->window, gdk_cursor_new (GDK_HAND1));
  256. //换肤
  257. change_event_box= gtk_event_box_new ();
  258. gtk_table_attach_defaults (GTK_TABLE (table), change_event_box, 6, 7, 1, 2);
  259. change_label=gtk_label_new_with_mnemonic("_换肤");
  260. gtk_label_set_pattern (GTK_LABEL (change_label), "___");
  261. gtk_container_add (GTK_CONTAINER (change_event_box), change_label);
  262. gtk_widget_set_events (change_event_box, GDK_BUTTON_PRESS_MASK);
  263. g_signal_connect (G_OBJECT (change_event_box), "button_press_event",
  264. G_CALLBACK (quit), NULL);
  265. //gtk_widget_realize (change_event_box); //failed
  266. gdk_window_set_cursor (change_event_box->window, gdk_cursor_new (GDK_HAND1));
  267. //写信
  268. /* write_image = gtk_image_new_from_file ("w_m.bmp");
  269. gtk_table_attach_defaults (GTK_TABLE (table), write_image, 0, 1, 2, 3);
  270. write_event_box= gtk_event_box_new ();
  271. gtk_table_attach_defaults (GTK_TABLE (table), write_event_box, 1, 2, 2, 3);
  272. write_label=gtk_label_new_with_mnemonic("_写信");
  273. gtk_label_set_pattern (GTK_LABEL (write_label), "___");
  274. gtk_container_add (GTK_CONTAINER (write_event_box), write_label);
  275. gtk_widget_set_events (write_event_box, GDK_BUTTON_PRESS_MASK);
  276. g_signal_connect (G_OBJECT (write_event_box), "button_press_event",
  277. G_CALLBACK (quit), NULL);
  278. // gtk_widget_realize (write_event_box); //failed
  279. gdk_window_set_cursor (write_event_box->window, gdk_cursor_new (GDK_HAND1));
  280. //收信
  281. recive_image = gtk_image_new_from_file ("r_m.bmp");
  282. gtk_table_attach_defaults (GTK_TABLE (table), recive_image, 0, 1, 3, 4);
  283. recive_event_box= gtk_event_box_new ();
  284. gtk_table_attach_defaults (GTK_TABLE (table), recive_event_box, 1, 2, 3, 4);
  285. recive_label=gtk_label_new_with_mnemonic("收信");
  286. //gtk_label_set_pattern (GTK_LABEL (recive_label), "___");
  287. gtk_label_set_markup(GTK_LABEL(recive_label),"<span foreground='black'font_desc='16'>收信 </span>");//调整字体颜色大小
  288. gtk_container_add (GTK_CONTAINER (recive_event_box), recive_label);
  289. gtk_widget_set_events (recive_event_box, GDK_BUTTON_PRESS_MASK);
  290. g_signal_connect (G_OBJECT (recive_event_box), "button_press_event",
  291. G_CALLBACK (quit), NULL);
  292. // gtk_widget_realize (write_event_box); //failed
  293. gdk_window_set_cursor (recive_event_box->window, gdk_cursor_new (GDK_HAND1));
  294. //通讯录
  295. contactor_image = gtk_image_new_from_file ("c_p.bmp");
  296. gtk_table_attach_defaults (GTK_TABLE (table), contactor_image, 0, 1, 5, 6);
  297. contactor_event_box= gtk_event_box_new ();
  298. gtk_table_attach_defaults (GTK_TABLE (table), contactor_event_box, 1, 2, 5, 6);
  299. contactor_label=gtk_label_new_with_mnemonic("通讯录");
  300. gtk_label_set_pattern (GTK_LABEL (contactor_label), "___");
  301. gtk_container_add (GTK_CONTAINER (contactor_event_box), contactor_label);
  302. gtk_widget_set_events (contactor_event_box, GDK_BUTTON_PRESS_MASK);
  303. g_signal_connect (G_OBJECT (contactor_event_box), "button_press_event",
  304. G_CALLBACK (quit), NULL);
  305. // gtk_widget_realize (write_event_box); //failed
  306. gdk_window_set_cursor (contactor_event_box->window, gdk_cursor_new (GDK_HAND1)); */
  307. //插入notebook
  308. {
  309. int i=10;
  310. GtkWidget *window;
  311. GtkWidget *button;
  312. GtkWidget *notebook;
  313. GtkWidget *label;
  314. GtkWidget *checkbutton;
  315. char bufferf[32];
  316. char bufferl[32];
  317. GtkWidget *vbox;
  318. GtkWidget *bbox1;
  319. GtkWidget *bbox2;
  320. GtkWidget *bbox3;
  321. GtkWidget *label1;
  322. GtkWidget *label2;
  323. GtkWidget *label3;
  324. GtkWidget *box1;
  325. GtkWidget *box2;
  326. GtkWidget *box3;
  327. GtkWidget *entry1;
  328. GtkWidget *entry2;
  329. //gtk_init(&argc, &argv);
  330. //window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  331. //gtk_widget_set_size_request(GTK_WIDGET(window),550,500);
  332. //gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  333. //g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
  334. //gtk_window_set_title(GTK_WINDOW(window),"写信");
  335. vbox = gtk_vbox_new(FALSE,0);
  336. box1 = make_box1(FALSE,0,FALSE,FALSE,3);
  337. gtk_box_pack_start(GTK_BOX(vbox),box1,FALSE,FALSE,2);
  338. box2 = make_box2(FALSE,0,FALSE,FALSE,3);
  339. box3 = make_box3(FALSE,0,FALSE,FALSE,3);
  340. bbox1 = gtk_hbox_new(FALSE,0);
  341. bbox2 = gtk_hbox_new(FALSE,0);
  342. bbox3 = gtk_hbox_new(FALSE,0);
  343. label1 = gtk_label_new("收件人");
  344. gtk_misc_set_alignment(GTK_MISC(label1),0,0);
  345. label2 = gtk_label_new("主题");
  346. label3 = gtk_label_new("正文");
  347. entry1 = gtk_entry_new();
  348. entry2 = gtk_entry_new();
  349. gtk_box_pack_start(GTK_BOX(bbox1),label1,FALSE,FALSE,0);
  350. gtk_box_pack_start(GTK_BOX(bbox1),entry1,FALSE,FALSE,0);
  351. gtk_box_pack_start(GTK_BOX(vbox),bbox1,FALSE,FALSE,2);
  352. gtk_box_pack_start(GTK_BOX(vbox),box2,FALSE,FALSE,2);
  353. gtk_box_pack_start(GTK_BOX(bbox2),label2,FALSE,FALSE,2);
  354. gtk_box_pack_start(GTK_BOX(bbox2),entry2,FALSE,FALSE,2);
  355. gtk_box_pack_start(GTK_BOX(vbox),bbox2,FALSE,FALSE,2);
  356. gtk_box_pack_start(GTK_BOX(vbox),box3,FALSE,FALSE,2);
  357. gtk_box_pack_start(GTK_BOX(bbox3),label3,FALSE,FALSE,2);
  358. gtk_box_pack_start(GTK_BOX(vbox),bbox3,FALSE,FALSE,2);
  359. //gtk_container_add(GTK_CONTAINER(window),vbox);
  360. //gtk_widget_show_all(vbox);
  361. //初始化GTK
  362. //gtk_init(&argc,&argv);
  363. //创建最上层主窗口
  364. //window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  365. //连接信号"delete_event",使得窗口关闭时发生
  366. //g_signal_connect(G_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(delete),NULL);
  367. //设置窗口标题
  368. //gtk_window_set_title(GTK_WINDOW(window),"wingmail");
  369. //设定窗口的默认宽高
  370. //gtk_window_set_default_size(GTK_WINDOW(window),800,700);
  371. //设定窗口的位置,让窗口总在最前端
  372. //gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  373. //设定容器边框的宽度
  374. //gtk_container_set_border_width(GTK_CONTAINER(window),15);
  375. notebook = gtk_notebook_new();
  376. gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_LEFT);
  377. //gtk_container_add(GTK_CONTAINER(window),notebook);
  378. gtk_widget_show(notebook);
  379. sprintf(bufferl,"已删除");
  380. label = gtk_label_new(bufferl);
  381. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  382. sprintf(bufferl,"已发送");
  383. label = gtk_label_new(bufferl);
  384. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  385. sprintf(bufferl,"草稿箱(%d)",i);
  386. label = gtk_label_new(bufferl);
  387. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  388. sprintf(bufferl,"收件箱(%d)",i);
  389. label = gtk_label_new(bufferl);
  390. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  391. sprintf(bufferl,"通讯录");
  392. label = gtk_label_new(bufferl);
  393. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  394. sprintf(bufferl,"收信");
  395. label = gtk_label_new(bufferl);
  396. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  397. sprintf(bufferl,"写信");
  398. label = gtk_label_new(bufferl);
  399. gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook),vbox,label);
  400. gtk_notebook_set_page(GTK_NOTEBOOK(notebook),0);
  401. gtk_widget_show(notebook);
  402. //gtk_widget_show_all(window);
  403. //gtk_main();
  404. //return FALSE;
  405. gtk_table_attach_defaults (GTK_TABLE (table), notebook, 0, 14, 2, 12);
  406. }
  407. //插入notebook
  408. gtk_widget_show_all(window);
  409. //gtk_widget_destroy(window_all);
  410. }
  411. else//警告界面
  412. {
  413. /*......*/
  414. GtkWidget *window;
  415. GtkWidget *y_button;
  416. GtkWidget *warning;
  417. GtkWidget *total_box;
  418. window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  419. gtk_window_set_title(GTK_WINDOW(window),"警告");
  420. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  421. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  422. gtk_container_set_border_width (GTK_CONTAINER (window),50);
  423. total_box=gtk_vbox_new (FALSE, 0);
  424. gtk_container_add (GTK_CONTAINER (window), total_box);
  425. warning = gtk_label_new ("用戶名或密码不正确,登录矢败\n");
  426. gtk_box_pack_start(GTK_BOX(total_box),warning,FALSE,FALSE,3);
  427. gtk_widget_show (warning);
  428. y_button = gtk_button_new_with_label ("确定");
  429. gtk_box_pack_start(GTK_BOX(total_box),y_button,FALSE,FALSE,3);
  430. g_signal_connect_swapped(G_OBJECT (y_button), "clicked",
  431. G_CALLBACK (gtk_widget_destroy),
  432. window);
  433. gtk_widget_show_all(window);
  434. }
  435. //g_print ("Hello World\n");
  436. g_print("%s\n",name);
  437. g_print("%s\n",pass);
  438. }
  439. gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
  440. {
  441. /* 如果你的 "delete_event" 信号处理函数返回 FALSE,GTK 会发出 "destroy" 信号。
  442. * 返回 TRUE,你不希望关闭窗口。
  443. * 当你想弹出“你确定要退出吗?”对话框时它很有用。*/
  444. g_print ("delete event occurred\n");
  445. GtkWidget *window;
  446. GtkWidget *y_button;
  447. GtkWidget *n_button;
  448. GtkWidget *warning;
  449. //GtkWidget *warning_box;
  450. GtkWidget *button_box;
  451. GtkWidget *total_box;
  452. window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  453. gtk_window_set_title(GTK_WINDOW(window),"warning");
  454. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  455. gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  456. gtk_container_set_border_width (GTK_CONTAINER (window),50);
  457. //竖框裝所有控件
  458. total_box=gtk_vbox_new (FALSE, 0);
  459. gtk_container_add (GTK_CONTAINER (window), total_box);
  460. //提示语句
  461. warning = gtk_label_new ("确定要退出吗?\n");
  462. gtk_box_pack_start(GTK_BOX(total_box),warning,FALSE,FALSE,3);
  463. gtk_widget_show (warning);
  464. //横框装两个按钮
  465. button_box = gtk_hbox_new (FALSE, 0);
  466. y_button = gtk_button_new_with_label ("确定");
  467. n_button = gtk_button_new_with_label ("取消");
  468. //將按钮装入横框
  469. gtk_box_pack_start(GTK_BOX(button_box),y_button,FALSE,FALSE,3);
  470. gtk_box_pack_start(GTK_BOX(button_box),n_button,FALSE,FALSE,3);
  471. gtk_widget_show (y_button);
  472. gtk_widget_show (n_button);
  473. //將横框装入竖框
  474. gtk_box_pack_start(GTK_BOX(total_box),button_box,FALSE,FALSE,3);
  475. gtk_widget_show(total_box);
  476. gtk_widget_show(button_box);
  477. gtk_widget_show(window);
  478. g_signal_connect_swapped(G_OBJECT (y_button), "clicked",
  479. G_CALLBACK (gtk_main_quit), window);
  480. g_signal_connect_swapped(G_OBJECT (n_button), "clicked",
  481. G_CALLBACK (gtk_widget_destroy),
  482. window);
  483. /* 改 TRUE 为 FALSE 程序会关闭。*/
  484. return TRUE;
  485. }
  486. void destroy( GtkWidget *widget, gpointer data )
  487. {
  488. gtk_main_quit ();
  489. }
  490. int main( int argc, char *argv[] )
  491. {
  492. GtkWidget *window;
  493. GtkWidget *button;
  494. GtkWidget *total_box;
  495. GtkWidget *image;
  496. GtkWidget *name_box;
  497. GtkWidget *pass_box;
  498. GtkWidget *check_box;
  499. GtkWidget *end_box;
  500. GtkWidget *name_entry;
  501. GtkWidget *pass_entry;
  502. GtkWidget *rem_check;
  503. GtkWidget *auto_check;
  504. GtkWidget *r_event_box;
  505. GtkWidget *f_event_box;
  506. GtkWidget *reg_label;
  507. GtkWidget *forg_label;
  508. gtk_init (&argc, &argv);
  509. window_all=window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  510. gtk_window_set_title(GTK_WINDOW(window),"用戶登录");
  511. gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
  512. /* 当窗口收到 "delete_event" 信号 (这个信号由窗口管理器发出,通常是“关闭”
  513. * 选项或是标题栏上的关闭按钮发出的),我们让它调用在前面定义的 delete_event() 函数。
  514. * 传给回调函数的 data 参数值是 NULL,它会被回调函数忽略。*/
  515. g_signal_connect (G_OBJECT (window), "delete_event",
  516. G_CALLBACK (delete_event), NULL);
  517. /* 在这里我们连接 "destroy" 事件到一个信号处理函数。
  518. * 对这个窗口调用 gtk_widget_destroy() 函数或在 "delete_event" 回调函数中返回 FALSE 值
  519. * 都会触发这个事件。*/
  520. g_signal_connect (G_OBJECT (window), "destroy",
  521. G_CALLBACK (destroy), NULL);
  522. /* 设置窗口边框的宽度。*/
  523. gtk_container_set_border_width (GTK_CONTAINER (window),100);
  524. total_box=gtk_vbox_new (FALSE, 0);
  525. gtk_container_add (GTK_CONTAINER (window), total_box);
  526. //插入图片
  527. image = gtk_image_new_from_file ("hh.jpg");
  528. gtk_box_pack_start(GTK_BOX(total_box),image,FALSE,FALSE,1);
  529. //插入横hbox
  530. name_box=gtk_hbox_new (FALSE, 0);
  531. gtk_box_pack_start(GTK_BOX(total_box),name_box,FALSE,FALSE,3);
  532. //插入用戶名
  533. entry_name=name_entry=gtk_entry_new();
  534. gtk_entry_set_text(GTK_ENTRY(name_entry),"用戶名");
  535. gtk_box_pack_start(GTK_BOX(name_box),name_entry,FALSE,FALSE,3);
  536. //strcpy(information->name,gtk_entry_get_text(GTK_ENTRY(name_entry)));
  537. //插入横hbox
  538. pass_box=gtk_vbox_new (FALSE, 0);
  539. gtk_box_pack_start(GTK_BOX(total_box),pass_box,FALSE,FALSE,3);
  540. //输入密码
  541. entry_pass=pass_entry=gtk_entry_new();
  542. gtk_entry_set_text(GTK_ENTRY(pass_entry),"密码");
  543. gtk_entry_set_visibility(GTK_ENTRY(pass_entry),FALSE);
  544. gtk_box_pack_start(GTK_BOX(pass_box),pass_entry,FALSE,FALSE,3);
  545. //strcpy(information->pass,gtk_entry_get_text(GTK_ENTRY(pass_entry)));
  546. //插入横hbox
  547. check_box=gtk_hbox_new (FALSE, 0);
  548. gtk_box_pack_start(GTK_BOX(total_box),check_box,FALSE,FALSE,3);
  549. //插入记密码和自动登录
  550. rem_check = gtk_check_button_new_with_label ("记住密码");
  551. gtk_box_pack_start (GTK_BOX (check_box), rem_check, TRUE, TRUE, 0);
  552. //g_signal_connect (G_OBJECT (check), "toggled",
  553. // G_CALLBACK (entry_toggle_editable), entry);
  554. gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rem_check), TRUE); ///
  555. gtk_widget_show (rem_check);
  556. auto_check = gtk_check_button_new_with_label ("自动登录");
  557. gtk_box_pack_start (GTK_BOX (check_box), auto_check, TRUE, TRUE, 0);
  558. //g_signal_connect (G_OBJECT (check), "toggled",
  559. // G_CALLBACK (entry_toggle_editable), entry);
  560. gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (auto_check), TRUE);
  561. gtk_widget_show (auto_check);
  562. //插入按扭
  563. button = gtk_button_new_with_label ("登录");
  564. gtk_box_pack_start(GTK_BOX(total_box),button,FALSE,FALSE,3);
  565. g_signal_connect (G_OBJECT (button), "clicked",
  566. G_CALLBACK (log_in), NULL);
  567. /* 当点击按钮时,会通过调用 gtk_widget_destroy(window) 来关闭窗口。
  568. * "destroy" 信号会从这里或从窗口管理器发出。*/
  569. /*g_signal_connect_swapped(G_OBJECT (button), "clicked",
  570. G_CALLBACK (gtk_widget_destroy),
  571. window); */
  572. end_box=gtk_hbox_new (FALSE, 0);
  573. gtk_box_pack_start(GTK_BOX(total_box),end_box,FALSE,FALSE,20);
  574. //注冊事件盒
  575. r_event_box = gtk_event_box_new ();
  576. gtk_box_pack_start(GTK_BOX(end_box),r_event_box,FALSE,FALSE,3);
  577. gtk_widget_show (r_event_box);
  578. reg_label = gtk_label_new ("注冊新用戶\n");
  579. gtk_container_add (GTK_CONTAINER (r_event_box), reg_label);
  580. gtk_widget_show (reg_label);
  581. gtk_widget_set_events (r_event_box, GDK_BUTTON_PRESS_MASK);
  582. g_signal_connect (G_OBJECT (r_event_box), "button_press_event",
  583. G_CALLBACK (quit), NULL);
  584. gtk_widget_realize (r_event_box);
  585. gdk_window_set_cursor (r_event_box->window, gdk_cursor_new (GDK_HAND1));
  586. //忘记密码
  587. f_event_box = gtk_event_box_new ();
  588. gtk_box_pack_end(GTK_BOX(end_box),f_event_box,FALSE,FALSE,3);
  589. gtk_widget_show (f_event_box);
  590. forg_label = gtk_label_new ("忘记密码\n");
  591. gtk_container_add (GTK_CONTAINER (f_event_box), forg_label);
  592. gtk_widget_show (forg_label);
  593. gtk_widget_set_events (f_event_box, GDK_BUTTON_PRESS_MASK);
  594. g_signal_connect (G_OBJECT (f_event_box), "button_press_event",
  595. G_CALLBACK (quit), NULL);
  596. gtk_widget_realize (f_event_box);
  597. gdk_window_set_cursor (f_event_box->window, gdk_cursor_new (GDK_HAND1));
  598. /* 最后一步是显示新创建的按钮和窗口 */
  599. gtk_widget_show (total_box);
  600. gtk_widget_show (name_box);
  601. gtk_widget_show (pass_box);
  602. gtk_widget_show (check_box);
  603. gtk_widget_show (end_box);
  604. gtk_widget_show (name_entry);
  605. gtk_widget_show (pass_entry);
  606. gtk_widget_show (image);
  607. gtk_widget_show (button);
  608. gtk_widget_show (window);
  609. /*所有的 GTK 程序必须有一个 gtk_main() 函数。程序运行停在这里
  610. * 等待事件 (如键盘事件或鼠标事件) 的发生。*/
  611. gtk_main ();
  612. return 0;
  613. }


本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号