demo_gui_image.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * 程序清单:DC上显示图像演示
  3. *
  4. * 这个例子会在创建出的view上显示图像
  5. */
  6. #include "demo_view.h"
  7. #include <rtgui/widgets/button.h>
  8. #include <rtgui/widgets/filelist_view.h>
  9. #include <string.h>
  10. #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
  11. /* 打开按钮的回调函数 */
  12. static void open_btn_onbutton(PVOID wdt, rtgui_event_t* event)
  13. {
  14. }
  15. /* 演示视图的事件处理函数 */
  16. static rt_bool_t demo_view_event_handler(PVOID wdt, rtgui_event_t *event)
  17. {
  18. rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
  19. rt_bool_t result;
  20. /* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */
  21. result = rtgui_view_event_handler(widget, event);
  22. if (event->type == RTGUI_EVENT_PAINT)
  23. {
  24. rtgui_dc_t* dc;
  25. /* 获得控件所属的DC */
  26. dc = rtgui_dc_begin_drawing(widget);
  27. if (dc == RT_NULL) return RT_FALSE;
  28. /* 绘图完成 */
  29. rtgui_dc_end_drawing(dc);
  30. }
  31. return result;
  32. }
  33. /* 创建用于显示图像的演示视图 */
  34. rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view)
  35. {
  36. rtgui_button_t* open_btn;
  37. rtgui_view_t *view;
  38. rtgui_filelist_view_t *fview;
  39. /* 先创建一个演示视图 */
  40. view = demo_view_create(parent_view, "图像演示");
  41. #ifdef _WIN32
  42. fview = rtgui_filelist_view_create(view, "d:\\", "*.*", 5, 65, 200, 180);
  43. #else
  44. fview = rtgui_filelist_view_create(view, "/", "*.*", 5, 65, 200, 180);
  45. #endif
  46. if (view != RT_NULL)
  47. /* 设置默认的事件处理函数到demo_view_event_handler函数 */
  48. rtgui_widget_set_event_handler(view, demo_view_event_handler);
  49. /* 添加一个按钮 */
  50. open_btn = rtgui_button_create(view, "打开图像文件", 10, 40, 120, 22);
  51. rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
  52. return view;
  53. }
  54. #endif