Lcui: Hello world! Program Implementation

Source: Internet
Author: User
Tags set set

In version 0.12.6, the C ++ class has changed. The following are the C and C ++ codes:

# Ifdef _ cplusplus // hello for C ++, world Program # include <lcui_build.h> # include partition # include lc_widget_h # include lc_graph_h # include lc_window_h # include lc_label_hint main (INT argc, char * argv []) {lcuiapp (argc, argv); lcuiwindow window; lcuilabel text; lcuigraph icon; load_graph_icon_lcui_18x18 (icon. getgraph (); window. settitletext ("test window"); window. resize (SIZE (320,240); window. settitleicon (icon); Window. addtoclientarea (Label); text. setalign (align_middle_center, pos (0, 0); text. settext ("<size = 24px> Hello, world! \ N "" <color = 100,155, 0> world </color> "" <color =, 0> world </color> "" <color =, 0>, </color> "" <color = 0,255, 0> You </color> "" <color = 0,100,155> good </color> "" <color = 255,>! </Color> \ n </size> ");/* display part */text. show (); window. show (); Return app. main () ;}# else // use lcui to implement hello, world Program # include <lcui_build.h> # include lc_lcui_h # include lc_widget_h # include lc_window_h # include lc_label_h # include lc_graph_h # include lc_res_h # include <unistd. h> int main (INT argc, char * argv []) {lcui_widget * window, * label; lcui_textstyle style; lcui_graph PIC; lcui_init (argc, argv ); /* initialize the struct */graph_in It (& pic); textstyle_init (& Style);/* displays the graph data in the warehouse. This graph is the 18x18 lcui icon */load_graph_icon_lcui_18x18 (& pic ); /* Create a widget */window = create_widget ("window"); label = create_widget ("label");/* set the text of the window title */set_window_title_text (window, "Test window");/* set the icon of the window title */set_window_title_icon (window, & pic);/* change the window size */window-> resize (window, size (320,240);/* Add the client area of the window as the container of the label component */window_client_area_add (window, Labe L);/* center display */label-> set_align (Label, align_middle_center, pos ();/** set the text displayed by the label component * <color = r, g, B> text </color> indicates that "text" uses a custom color * <size = 24px> text </size> to indicate: the displayed "text" in 24 pixels **/label_text (label, "<size = 24px> Hello, world! \ N "" <color = 100,155, 0> world </color> "" <color =, 0> world </color> "" <color =, 0>, </color> "" <color = 0,255, 0> You </color> "" <color = 0,100,155> good </color> "" <color = 255,>! </Color> \ n </size> ");/* display part */label-> show (Label); window-> show (window); Return lcui_main (); /* enter the main loop */} # endif

:

In version 0.12.5, C ++ classes are added to some functional modules. You can use the C ++ code. The following is the source code of the C ++ I Hello, world sample program:

// C ++ version of Hello, World Program # include <lcui_build.h> # include lc_lcui_h/* contains the lcui header file */# include lc_widget_h # include <unistd. h> int main (INT argc, char * argv []) {lcuiapp (argc, argv); lcuiwidgetwindow ("window"), label ("label"); lcuigraphicon; /* load the 18x18 icon of lcui */icon. load. icon. lcui_18x18 ();/* set the icon for the window */window. window. seticon (icon);/* change the size of the window */window. resize (SIZE (320,240);/* set the title text of the window */window. wi Ndow. settitle ("test window");/* Add the label part to the window customer area */window. window. addtoclientarea (Label);/* set the alignment of the label part */label. setalign (align_middle_center, pos ();/* set the text displayed for the label part */label. label. settext ("Hello, world! \ N "" <color = 100,155, 0> world </color> <color =, 0> world </color> "" <color =, 0>, </color> <color = 0,255, 0> You </color> "" <color = 0,100,155> good </color> <color = 255,>! </Color> \ n ");/* set the font size */label. label. setfont (24, null);/* display the two parts */label. show (); window. show ();/* enter the main loop */return app. main ();}

Source code of the hello World sample program for lcui of version 0.12.3:

# Include <lcui_build.h>/* header file containing lcui */# include <unistd. h> int main (INT argc, char * argv []) {lcui_init (argc, argv); lcui_widget * window, * label; lcui_graph PIC; /* initialize the struct */graph_init (& pic);/* upload the graph data in the warehouse. This graph is the 18x18 lcui icon */load_graph_icon_lcui_18x18 (& pic ); /* Create a widget */window = create_widget ("window"); label = create_widget ("label");/* set the text of the window title */set_window_title_text (window, "Test window");/* Set Set the icon */set_window_title_icon (window, & pic) of the window title;/* change the size of the window */resize_widget (window, size (320,240 )); /* Add the client area of the window as the container of the label component */window_client_area_add (window, label);/* center display */set_widget_align (Label, align_middle_center, 0, 0 ); /** set the text displayed for the label part. * <color = R, G, B> text </color> indicates: the "text" function uses the custom color * set_label_text, which is basically the same as the sprintf function. It supports the control operator **/set_label_text (label, "Hello world! \ N "" <color = 100,155, 0> world </color> "" <color = 0,255, 0> world </color> "" <color =, 0> You </color> "" <color = 0,100,155> good </color> "" <color = 255,>! </Color> \ n ");/** changes the font size of the label part, in pixel (pixels), not Pt (points) * The third parameter is the Custom font file. I set it to null, indicating that it is not used. **/Set_label_font (Label, 24, null);/* display part */show_widget (Label); show_widget (window); lcui_main (); /* enter the main loop */return 0 ;}

:

Lcui 0.12.1:

# Include ".. /include/lcui. H "Void exit_lcui (void * In) {lcui_window * win_p = (lcui_window *) in;/* convert data type */close_window (win_p ); /* call the close_window function to close the window */} int main (INT argc, char * argv [])/* main function, program entry */{lcui_app this; /* lcui Program */lcui_widget * label;/* Use Pointer to widget */lcui_window * main_window;/* Use Pointer to window */INT width, height; /* initialize lcui */lcui_init (& this);/* set the default font */set_default_font (" .. /Fonts/msyh. TTF ");/* Create an lcui program window */width = 180;/* The window width */Height = 110; /* window height * // * create a window and obtain the pointer to window data */main_window = create_window (& this, width, height); set_window_title_text (main_window, "Hello world! ");/* Create a label component in the window */label = create_widget (main_window, label);/* change the text content in the label component */set_label_text (label, "Hello world! \ N test! This is a Chinese word! \ Nabcdefghijklmnopqrstuvwxyz \ n1234567890 \ n! @ # $ % ^ & * () _ + {} |: \ "<>? "); Show_widget (Label);/* display part */show_window (main_window);/* display window * // * Associate the return key with the exit_lcui function. When the return key is pressed, exit the Program */lcui_key_event_connect (main_window, key_esc, exit_lcui, (void *) main_window); lcui_main (& this);/* enter the main loop */return 0 ;}

:

Earlier versions of helloworld:

# Include "lcui_build.h" # include lcui_main_h/* include the required header file of the lcui library */# include lcui_widgets_h # include lcui_fonts_h # include "all. H "int main (INT argc, char * argv []) {lcui_app app;/* lcui Program */pic_data PIC;/* used to store image data */INT win_a; /* used to save the window identification code */lable_data lable;/* used to save text tag data */INT width, height, temp; width = 240; /* window width */Height = 180;/* window height */temp = lcui_load_image ("egg.bmp", & pic);/* load image file: egg.bmp * /If (temp! = 0) {return-1;} lcui_init (& App);/* initialize lcui */win_a = create_window (& App, width, height ); /* Create an lcui program window */set_background_image (& App, win_a, & pic, stretch);/* set the background image of the window to the image just loaded, stretch indicates to stretch the image and fill the entire background */title_text_size (& App, win_a, 12 ); /* the font size of the text in the title bar is 12 * // * Add the text in the title bar */set_title_text (& App, win_a, "test program by liuchao35758600 "); create_lable (& App, win_a, & lable);/* create a text tag. If no position is specified, the default value is center */lable_text (& lable, "Hello world! ");/* The label content is Hello world! * // * The font size is 32, and the font color is default (black by default). */lable_font (& lable, 32, ttf_msyh, null ); show_window (& App, win_a);/* display window */close_window (& App, win_a);/* close the window */return 0 ;}

Code Test Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.