【声明:版权全部,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】
上一篇文章谈到了多窗体,还是依照约定看一下效果是什么样的。
假设大家细心一点。就会发现窗体中的label显示为window01,这事实上是由于我们已经添加了一个窗体,有兴趣的朋友能够尝试编译一下。如题所看到的,今天讨论的是combox。所谓的combox,事实上就是从给出的若干个选择挑选出一个就可以。
闲话少说,还是看代码。
#include "ftk.h" #define IDC_TEST_BUTTON 1000 static Ret button_quit_clicked(void* ctx, void* obj) { ftk_quit(); return RET_OK; } int FTK_MAIN(int argc, char* argv[]) { int width = 0; int height = 0; FtkWidget* win = NULL; FtkWidget* button = NULL; FtkWidget* combo_box = NULL; ftk_init(argc, argv); win = ftk_app_window_create(); width = ftk_widget_width(win); height = ftk_widget_height(win); width = width/2 - 10; combo_box = ftk_combo_box_create(win, 0, height/4, width, 50); ftk_combo_box_set_text(combo_box, "1 second"); ftk_combo_box_append(combo_box, NULL, "1 second"); ftk_combo_box_append(combo_box, NULL, "2 seconds"); ftk_combo_box_append(combo_box, NULL, "3 seconds"); combo_box = ftk_combo_box_create(win, width + 10, height/4, width, 50); ftk_combo_box_set_text(combo_box, "1 second"); ftk_combo_box_append(combo_box, NULL, "1 second"); ftk_combo_box_append(combo_box, NULL, "2 seconds"); ftk_combo_box_append(combo_box, NULL, "3 seconds"); ftk_combo_box_append(combo_box, NULL, "4 seconds"); ftk_combo_box_append(combo_box, NULL, "5 seconds"); ftk_combo_box_append(combo_box, NULL, "6 seconds"); ftk_combo_box_append(combo_box, NULL, "7 seconds"); ftk_combo_box_append(combo_box, NULL, "8 seconds"); ftk_combo_box_append(combo_box, NULL, "9 seconds"); ftk_combo_box_append(combo_box, NULL, "0 seconds"); ftk_combo_box_append(combo_box, NULL, "0 seconds"); button = ftk_button_create(win, width/2, height/2, width, 60); ftk_widget_set_text(button, "quit"); ftk_button_set_clicked_listener(button, button_quit_clicked, win); ftk_window_set_focus(win, button); combo_box = ftk_combo_box_create(win, 0, 3*height/4+5, width, 50); ftk_combo_box_set_text(combo_box, "1 second"); ftk_combo_box_append(combo_box, NULL, "1 second"); ftk_combo_box_append(combo_box, NULL, "2 seconds"); ftk_combo_box_append(combo_box, NULL, "3 seconds"); combo_box = ftk_combo_box_create(win, width + 10, 3*height/4+5, width, 50); ftk_combo_box_set_text(combo_box, "1 second"); ftk_combo_box_append(combo_box, NULL, "1 second"); ftk_combo_box_append(combo_box, NULL, "2 seconds"); ftk_combo_box_append(combo_box, NULL, "3 seconds"); ftk_combo_box_append(combo_box, NULL, "4 seconds"); ftk_combo_box_append(combo_box, NULL, "5 seconds"); ftk_combo_box_append(combo_box, NULL, "6 seconds"); ftk_combo_box_append(combo_box, NULL, "7 seconds"); ftk_combo_box_append(combo_box, NULL, "8 seconds"); ftk_combo_box_append(combo_box, NULL, "9 seconds"); ftk_combo_box_append(combo_box, NULL, "0 seconds"); ftk_combo_box_append(combo_box, NULL, "0 seconds"); ftk_widget_set_text(win, "ComboBox Demo"); ftk_widget_show_all(win, 1); ftk_widget_set_attr(win, FTK_ATTR_QUIT_WHEN_CLOSE); ftk_run(); return 0; }
相信大家看了上面的代码就不操心了。假设想创建combox,直接调用函数ftk_combo_box_create就可以;假设须要加入条目,调用函数ftk_combo_box_append就可以;假设须要设定默认选项,调用ftk_combo_box_set_text函数就可以。就是这么简单。
下次看效果图。
时间: 2024-10-13 05:42:06