ftk学习记(消息框篇)

来源:互联网 发布:淘宝商家的联系方式 编辑:程序博客网 时间:2024/06/05 19:56

【 声明:版权所有,欢迎转载,请勿用于商业用途。  联系信箱:feixiaoxing @163.com】


    上一篇说到了输入框。闲话不多说,首先看结果显示,




    大家看看效果是不是和我们之前说的一样。今天,我们谈一下消息狂。这种消息框其实应用得特别多,有警告用的,有提问的,有信息的,也有提示的。没关系,ftk这边也有demo代码,大家可以学习一下。

#include "ftk.h"static const char* buttons1[] = {"Yes", NULL};static const char* buttons2[] = {"Yes", "No", NULL};static const char* buttons3[] = {"Yes", "No", "Cancel", NULL};static Ret button_warning(void* ctx, void* obj){int ret = ftk_warning("Warning", "December 31, 2008: patchwork.kernel.org is now available for general use. It is currently only monitoring the Linux Kernel mailing-list, but should be useful to kernel developers in dealing with patches flying across the wire.", buttons1);ftk_logd("%s: ret = %d\n", __func__, ret);return RET_OK;}static Ret button_info(void* ctx, void* obj){int ret = ftk_infomation("Infomation", "September 19, 2008: mirrors.kernel.org has been flipped over to using our new GeoDNS based bind server (named-geodns). This means that, at the dns query level, our servers will attempt to direct you to the nearest / fastest kernel.org mirror for your request. This means that you no longer have to use mirrors.us.kernel.org or mirrors.eu.kernel.org to generally route you to the right place. This does mean a change to mirrors.kernel.org no longer explicitly pointing at mirrors.us.kernel.org. Additional information on named-geodns will be forth coming, check back here for an addendum soon.", buttons2);ftk_logd("%s: ret = %d\n", __func__, ret);return RET_OK;}static Ret button_question(void* ctx, void* obj){int ret = ftk_question("Question", "Are you sure to quit?", buttons3);ftk_logd("%s: ret = %d\n", __func__, ret);return RET_OK;}static Ret button_tips(void* ctx, void* obj){int ret = ftk_tips("The dialog will quit in 3 seconds.");ftk_logd("%s: ret = %d\n", __func__, ret);return RET_OK;}static Ret button_quit(void* ctx, void* obj){ftk_quit();return RET_OK;}int FTK_MAIN(int argc, char* argv[]){int y = 0;int width = 0;int height = 0;FtkWidget* win = NULL;FtkWidget* button = NULL;ftk_init(argc, argv);win = ftk_app_window_create();width = ftk_widget_width(win);height = ftk_widget_height(win);y = (height - 240)/2;y = y > 0 ? y : 0;button = ftk_button_create(win, 0, y, width/2, 50);ftk_widget_set_text(button, "question");ftk_button_set_clicked_listener(button, button_question, win);button = ftk_button_create(win, width/2, y, width/2, 50);ftk_widget_set_text(button, "warning");ftk_button_set_clicked_listener(button, button_warning, win);button = ftk_button_create(win, 0, y+60, width/2, 50);ftk_widget_set_text(button, "info");ftk_button_set_clicked_listener(button, button_info, win);button = ftk_button_create(win, width/2, y+60, width/2, 50);ftk_widget_set_text(button, "tips");ftk_button_set_clicked_listener(button, button_tips, win);button = ftk_button_create(win, width/4, y+120, width/2, 50);ftk_widget_set_text(button, "quit");ftk_button_set_clicked_listener(button, button_quit, win);ftk_widget_set_text(win, "message box demo");ftk_widget_show_all(win, 1);ftk_widget_set_attr(win, FTK_ATTR_QUIT_WHEN_CLOSE);ftk_run();return 0;}

    代码流程和之前的编写方法一样。从代码中看去,有5个button,每个button都有自己的回调函数。这5个函数分别是button_warning、button_info、button_question、button_tips、button_quit。那回调函数中做了什么呢?


    抛开button_quit,我们只要看其他4个button的回调函数。函数分别是ftk_warning、ftk_info、ftk_question、ftk_tips。除了最后一个ftk_tips,你会发现其他3个函数都是3个参数。参数1为标题,参数2为内容,参数3为button形式。这种消息框中button有多种形式,有两个button的,有三个button的,需要根据具体情况而定。


    欲看效果如何,只好等下一篇文章了。




1 1
原创粉丝点击