tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / efl_thread_win32_1.c
1 //Compile with:
2 //gcc -o efl_thread_1 efl_thread_win32_1.c -g `pkg-config --cflags --libs elementary`
3 #include <Elementary.h>
4 #define WIN32_LEAN_AND_MEAN
5 #include <windows.h>
6
7 static Evas_Object *win = NULL;
8 static Evas_Object *rect = NULL;
9
10 static HANDLE thread;
11
12 // BEGIN - code running in my custom win32 thread instance
13 //
14 static DWORD WINAPI
15 my_thread_run(LPVOID arg)
16 {
17    double t = 0.0;
18
19    for (;;)
20      {
21         ecore_thread_main_loop_begin(); // begin critical
22           { // indented for illustration of "critical" block
23              Evas_Coord x, y;
24
25              x = 200 + (200 * sin(t));
26              y = 200 + (200 * cos(t));
27              evas_object_move(rect, x - 50, y - 50);
28           }
29         ecore_thread_main_loop_end(); // end critical
30         usleep(1000);
31         t += 0.02;
32      }
33    return 0;
34 }
35 //
36 // END - code running in my custom win32 thread instance
37
38 static void
39 my_thread_new(void)
40 {
41    thread = CreateThread(NULL, 0, my_thread_run, NULL, 0, NULL);
42    if (!thread)
43      {
44         char *str = evil_last_error_get();
45         if (str)
46           {
47              fprintf("thread creation failed: %s\n", str);
48              free(str);
49           }
50      }
51 }
52
53 EAPI_MAIN int
54 elm_main(int argc, char **argv)
55 {
56    Evas_Object *o;
57
58    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
59
60    win = elm_win_util_standard_add("efl-thread-1", "EFL Thread 1");
61    elm_win_autodel_set(win, EINA_TRUE);
62
63    o = evas_object_rectangle_add(evas_object_evas_get(win));
64    evas_object_color_set(o, 50, 80, 180, 255);
65    evas_object_resize(o, 100, 100);
66    evas_object_show(o);
67    rect = o;
68
69    // create custom thread to do some "work on the side"
70    my_thread_new();
71
72    evas_object_resize(win, 400, 400);
73    evas_object_show(win);
74
75    elm_run();
76
77    return 0;
78 }
79 ELM_MAIN()