mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
更新进度条测试程序
This commit is contained in:
+36
-27
@@ -1,10 +1,10 @@
|
||||
|
||||
//测试进度条部件的示例程序
|
||||
#include <LCUI_Build.h>
|
||||
#include LC_LCUI_H
|
||||
#include LC_WIDGET_H
|
||||
#include LC_WINDOW_H
|
||||
#include LC_GRAPHICS_H
|
||||
#include LC_LABEL_H
|
||||
#include LC_RES_H
|
||||
#include LC_WORK_H
|
||||
#include LC_MISC_H
|
||||
@@ -14,47 +14,56 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
void *change_progress(void *arg)
|
||||
/* 功能:动态改变label部件的文本内容 */
|
||||
|
||||
void *change_progress_1(void *arg)
|
||||
/* 功能:动态改变进度条部件的数据 */
|
||||
{
|
||||
int i, max;
|
||||
max = 100;
|
||||
int i, max = 100;
|
||||
LCUI_Widget *label;
|
||||
LCUI_Widget *widget = (LCUI_Widget *)arg; /* 转换类型 */
|
||||
|
||||
label = Create_Widget("label");
|
||||
Widget_Container_Add(widget, label);
|
||||
label->set_align(label, ALIGN_MIDDLE_CENTER, Pos(0,0));
|
||||
label->show(label);
|
||||
Set_ProgressBar_Max_Value(widget, max); /* 最大值 */
|
||||
srand(time(NULL));
|
||||
for(i=0; i<max; i+=rand()%5)
|
||||
{
|
||||
Set_ProgressBar_Value(widget, i);/* 当前值 */
|
||||
Set_Label_Text(label, "%d%%", (int)(i*100.0/max));
|
||||
usleep(100000);/* 暂停0.1秒 */
|
||||
}
|
||||
Set_ProgressBar_Value(widget, max);
|
||||
Set_Label_Text(label, "100%%");
|
||||
LCUI_Thread_Exit(NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char*argv[])
|
||||
void *change_progress_2(void *arg)
|
||||
{
|
||||
LCUI_Graph graph;
|
||||
LCUI_Widget *window, *pb;
|
||||
int i, max = 100;
|
||||
LCUI_Widget *label;
|
||||
LCUI_Widget *widget = (LCUI_Widget *)arg;
|
||||
|
||||
Graph_Init(&graph);
|
||||
LCUI_Init(argc, argv);
|
||||
window = Create_Widget("window");
|
||||
pb = Create_Widget("picture_box");
|
||||
Set_Window_Title_Text(window, "测试进度条部件");
|
||||
Resize_Widget(window, Size(320, 240));
|
||||
Resize_Widget(pb, Size(318, 215));
|
||||
Load_Graph_ProgressBar_Img(&graph);
|
||||
Set_PictureBox_Size_Mode(pb, SIZE_MODE_ZOOM);
|
||||
Set_PictureBox_Image_From_Graph(pb, &graph);
|
||||
Window_Client_Area_Add(window, pb);
|
||||
Set_Widget_Align(pb, ALIGN_MIDDLE_CENTER, Pos(0, 0));
|
||||
Show_Widget(pb);
|
||||
Show_Widget(window);
|
||||
return LCUI_Main(); /* 进入主循环 */
|
||||
label = Create_Widget("label");
|
||||
Widget_Container_Add(widget, label);
|
||||
label->set_align(label, ALIGN_MIDDLE_CENTER, Pos(0,0));
|
||||
label->show(label);
|
||||
Set_ProgressBar_Max_Value(widget, max);
|
||||
srand(time(NULL));
|
||||
for(i=0; i<max; i+=rand()%5)
|
||||
{
|
||||
Set_ProgressBar_Value(widget, i);
|
||||
Set_Label_Text(label, "%d/%d", i, max);
|
||||
usleep(100000);
|
||||
}
|
||||
Set_ProgressBar_Value(widget, max);
|
||||
Set_Label_Text(label, "%d/%d", max, max);
|
||||
LCUI_Thread_Exit(NULL);
|
||||
}
|
||||
|
||||
|
||||
int tttmain(int argc, char*argv[])
|
||||
/* 主函数,程序的入口 */
|
||||
int main(int argc, char*argv[])
|
||||
{
|
||||
pthread_t t[2];
|
||||
LCUI_Init(argc, argv);
|
||||
@@ -81,8 +90,8 @@ int tttmain(int argc, char*argv[])
|
||||
Resize_Widget(pb_a, Size(300, 25));
|
||||
Resize_Widget(pb_b, Size(300, 25));
|
||||
/* 创建线程,此函数和pthread_create函数用法一样 */
|
||||
LCUI_Thread_Create(&t[0], NULL, change_progress, (void*)pb_a);
|
||||
LCUI_Thread_Create(&t[1], NULL, change_progress, (void*)pb_b);
|
||||
LCUI_Thread_Create(&t[0], NULL, change_progress_1, (void*)pb_a);
|
||||
LCUI_Thread_Create(&t[1], NULL, change_progress_2, (void*)pb_b);
|
||||
/* 显示部件 */
|
||||
Show_Widget(pb_a);
|
||||
Show_Widget(pb_b);
|
||||
|
||||
Reference in New Issue
Block a user