zoukankan      html  css  js  c++  java
  • 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的,须要依据详细情况而定。


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




  • 相关阅读:
    dpkg安装deb缺少依赖包的解决方法
    一个linux命令之grep---1
    win10快捷键
    Windows Server 2008 R2遗忘管理员密码后的解决方案
    手工释放linux内存
    oracle数据库用户加锁和解锁
    完全卸载Oracle数据库软件
    Linux上VNC 启动和关闭常见问题
    Linux 开启VNCSERVER
    RedHat 简易配置 VNC Server 与VNC View详细说明
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4551356.html
Copyright © 2011-2022 走看看