• ftk学习记(消息框篇)


    【 声明:版权全部,欢迎转载,请勿用于商业用途。  联系信箱: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
    ", __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
    ", __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
    ", __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
    ", __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的,须要依据详细情况而定。


        欲看效果怎样,仅仅好等下一篇文章了。




  • 相关阅读:
    WCF学习2
    《Linux内核设计与实现》读书笔记(3) 进程调度
    《面向模式的软件体系结构3资源管理模式》读书笔记(7) Coordinator模式
    《Linux内核设计与实现》读书笔记(2) 进程管理
    《面向模式的软件体系结构3资源管理模式》读书笔记(10) Evictor模式
    《面向模式的软件体系结构4分布式计算的模式语言》读书笔记(1) 从混沌到结构(1)
    《Linux内核设计与实现》读书笔记(1) Linux内核开发的特点
    全国哀悼日,我们也把博客灰一下吧
    IE6上Gzip+Etag问题的解决方案
    信息无障碍的修复脚本
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4551356.html
Copyright © 2020-2023  润新知