歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> LCUI庫:Hello World!程序的實現

LCUI庫:Hello World!程序的實現

日期:2017/3/1 10:38:07   编辑:Linux編程

如題,正在編寫自己的LCUI庫,新增了Lable部件,用它可以在LCUI程序的窗口中顯示文本,具體,如下代碼所示:

[cpp]
  1. #include "LCUI_Build.h"
  2. #include LCUI_MAIN_H /* 包含LCUI庫的必須頭文件 */
  3. #include LCUI_WIDGETS_H
  4. #include LCUI_FONTS_H
  5. #include "all.h"
  6. int main(int argc,char *argv[])
  7. {
  8. LCUI_App app; /* LCUI程序 */
  9. Pic_Data pic; /* 用於存儲圖片數據 */
  10. int win_a; /* 用於保存窗口識別代號 */
  11. Lable_Data lable; /* 用於保存文本標簽數據 */
  12. int width,height,temp;
  13. width = 240; /* 窗口的寬度 */
  14. height = 180; /* 窗口的高度 */
  15. temp = LCUI_Load_Image("egg.bmp",&pic); /* 載入圖片文件:egg.bmp */
  16. if(temp != 0) {
  17. return -1;
  18. }
  19. LCUI_Init(&app); /* 初始化LCUI */
  20. win_a = Create_Window(&app,width,height); /* 創建一個LCUI程序窗口 */
  21. Set_Background_Image(&app,win_a,&pic,STRETCH);
  22. /* 設定窗口背景圖為剛剛載入的圖片,STRETCH 表示將圖片拉伸並鋪滿整個背景 */
  23. Title_Text_Size(&app,win_a,12); /* 標題欄中的文本的字體大小為12 */
  24. /* 在標題欄中添加文本 */
  25. Set_Title_Text(&app,win_a,"測試程序 by liuchao35758600");
  26. Create_Lable(&app,win_a,&lable); /* 創建一個文本標簽,如果沒有指定位置,默認居中放置 */
  27. Lable_Text(&lable,"Hello World!"); /* 標簽內容為Hello World! */
  28. /* 字體大小為32,使用微軟雅黑字體,字體配色為缺省(默認為黑色) */
  29. Lable_Font(&lable,32,TTF_MSYH,NULL);
  30. Show_Window(&app,win_a);/* 顯示窗口 */
  31. Close_Window(&app,win_a); /* 關閉窗口 */
  32. return 0;
  33. }

代碼測試結果:

Copyright © Linux教程網 All Rights Reserved