完整Demo,lvgl,lvgl_drivers相关资料下载
链接:https://pan.baidu.com/s/1DNJeHdoaPyfe1BsLb9wjRg
提取码:wov7
其它资料下载
链接:https://pan.baidu.com/s/1nV9jojPEPWSWZdYhaCZWTA
提取码:91j8
下载资料后解压文件及安装VS2022 ,选择通用windows平台开发及Visual Studio进行安装,安装步骤略
打开VS2022,点击创建新项目
选择Windows Console Application (C++/WinRT),点击下一步
输入名程lvgl_v9_sim,选择目录,勾选将解决方案和项目放在同一目录中,点击创建,再点击确定
在工程目录中新建一个文件夹并命名为lvgl_folder
将下载的lv_drivers,lvgl两个文件夹复制到lvgl_folder文件中
将lv_drivers中的lv_drv_conf_template.h和lvgl中的lv_conf_template.h的文件复制到lvgl_folder目录下,并分别命名为lv_drv_conf.h和lv_conf.h
在工程中分别创建lvgl,lvgl_drivers两个筛选器
将lvgl_folder文件夹中的文件分别加入到工程
点击显示所有文件,包含添加的文件在项目中
将lv_drv_conf.h文件中的条件编译总开关打开
- #if 0改成#if 1
#if 1 /*Set it to "1" to enable the content*/
- 将USE_WIN32DRV宏设为1
/*----------------------------
* Native Windows (win32drv)
*---------------------------*/
#ifndef USE_WIN32DRV
# define USE_WIN32DRV 1
#endif
#if USE_WIN32DRV
/* Scale window by this factor (useful when simulating small screens) */
# define WIN32DRV_MONITOR_ZOOM 1
#endif
将lv_conf.h中的文件配置如下
- 编译总开关由#if 0改成#if 1
#if 1 /*Set it to "1" to enable content*/
- LV_MEM_SIZE宏定义为(1024U * 1024U)
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#define LV_MEM_SIZE (1024U * 1024U) /*[bytes]*/
- LV_TICK_CUSTOM宏设为1,定义windos.h文件,定义时间函数GetTickCount()
/*Use a custom tick source that tells the elapsed time in milliseconds.
*It removes the need to manually update the tick with `lv_tick_inc()`)*/
#define LV_TICK_CUSTOM 1
#if LV_TICK_CUSTOM
#define LV_TICK_CUSTOM_INCLUDE <Windows.h> /*Header for the system time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (GetTickCount()) /*Expression evaluating to current system time in ms*/
#endif /*LV_TICK_CUSTOM*/
- 将宏LV_USE_LOG设为1
/*Enable the log module*/
#define LV_USE_LOG 1
- 将LV_USE_PERF_MONITOR和LV_USE_MEM_MONITOR设为1
/*1: Show CPU usage and FPS count*/
#define LV_USE_PERF_MONITOR 1
#if LV_USE_PERF_MONITOR
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#endif
/*1: Show the used memory and the memory fragmentation
* Requires LV_MEM_CUSTOM = 0*/
#define LV_USE_MEM_MONITOR 1
#if LV_USE_MEM_MONITOR
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#endif
- 将LV_FONT_MONTSERRAT_12和LV_FONT_MONTSERRAT_16设为1
/*Montserrat fonts with ASCII range and some symbols using bpp = 4
*https://fonts.google.com/specimen/Montserrat*/
#define LV_FONT_MONTSERRAT_8 0
#define LV_FONT_MONTSERRAT_10 0
#define LV_FONT_MONTSERRAT_12 1
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 1
#define LV_FONT_MONTSERRAT_18 0
#define LV_FONT_MONTSERRAT_20 0
#define LV_FONT_MONTSERRAT_22 0
#define LV_FONT_MONTSERRAT_24 0
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
#define LV_FONT_MONTSERRAT_40 0
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 0
- 在lv_config.h中将demo相关例程宏设为1
/*==================
* EXAMPLES
*==================*/
/*Enable the examples to be built with the library*/
#define LV_BUILD_EXAMPLES 1
/*===================
* DEMO USAGE
====================*/
/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
#define LV_USE_DEMO_WIDGETS 1
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 1
#endif
/*Demonstrate the usage of encoder and keyboard*/
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 1
/*Benchmark your system*/
#define LV_USE_DEMO_BENCHMARK 1
#if LV_USE_DEMO_BENCHMARK
/*Use RGB565A8 images with 16 bit color depth instead of ARGB8565*/
#define LV_DEMO_BENCHMARK_RGB565A8 0
#endif
/*Stress test for LVGL*/
#define LV_USE_DEMO_STRESS 1
/*Music player demo*/
#define LV_USE_DEMO_MUSIC 1
#if LV_USE_DEMO_MUSIC
#define LV_DEMO_MUSIC_SQUARE 0
#define LV_DEMO_MUSIC_LANDSCAPE 0
#define LV_DEMO_MUSIC_ROUND 0
#define LV_DEMO_MUSIC_LARGE 0
#define LV_DEMO_MUSIC_AUTO_PLAY 0
#endif
/*Flex layout demo*/
#define LV_USE_DEMO_FLEX_LAYOUT 0
点击项目菜单,点击属性
点击C/C++,选择常规,在附加包含目录中加入lvgl_folder,点击应用
在main.cpp中换成以下内容,并将main.cpp文件重命名为main.c
#include "lvgl/lvgl.h"
#include "lvgl/demos/music/lv_demo_music.h"
#include "lv_drivers/win32drv/win32drv.h"
#define IDI_LVGL 101
int main()
{
lv_init();
if (!lv_win32_init(
GetModuleHandleW(NULL),
SW_SHOW,
800,
480,
LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCE(IDI_LVGL))))
{
return -1;
}
lv_win32_add_all_input_devices_to_group(NULL);
lv_demo_music();
while (!lv_win32_quit_signal)
{
lv_task_handler();
Sleep(1);
}
return 0;
}
将C/C++中预编译头,选择不使用预编译头
在C++预处理器中新增加如下内容
在链接器,输入,附加依赖项加入以下内容
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib