# Win32 Code::Block LVGL

## Create Win32 Project

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729733605444/7c6e5459-93a4-4b75-a46a-2f48a99202c7.png align="center")

Frame based

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729733634564/dd85923f-498f-4579-a7b5-5521e6e137ce.png align="center")

GNU GCC Compiler

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729733703859/18e2f2a9-a494-4d0f-93c5-0cc1987974b3.png align="center")

Run

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729733749659/2809b006-9cb7-419f-84cc-afbdefbaf3c5.png align="center")

Remove Console: Right Click Project → `Properties…`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729733999778/87117ad1-41d1-4e6b-a49d-2ae66465bb3d.png align="center")

Build targets → Debug → Type: `GUI application`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729733984451/b3af5bf9-68db-4d51-9b8f-2153b8b45209.png align="center")

Build → `Rebuild (Ctrl+F11)`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729734100897/468ffbf5-b5d0-48cc-8185-51c35b3b6687.png align="center")

Run

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729734146049/ee29d29e-b86b-45f1-8f08-61a5cb3b5107.png align="center")

## Add LGVL

```bash
cd Win32CodeBlockLVGL
git submodule init
git submodule add https://github.com/lvgl/lvgl.git lvgl
cp lvgl/lv_conf_template.h lv_conf.h
```

Edit `lv_conf`

```diff

diff --git a/lv_conf.h b/lv_conf.h
old mode 100644
new mode 100755
index 914189f..410786c
--- a/lv_conf.h
+++ b/lv_conf.h
@@ -12,7 +12,7 @@
  */

 /* clang-format off */
-#if 0 /* Set this to "1" to enable content */
+#if 1 /* Set this to "1" to enable content */

 #ifndef LV_CONF_H
 #define LV_CONF_H
@@ -106,7 +106,7 @@
  * - LV_OS_WINDOWS
  * - LV_OS_MQX
  * - LV_OS_CUSTOM */
-#define LV_USE_OS   LV_OS_NONE
+#define LV_USE_OS   LV_OS_WINDOWS

 #if LV_USE_OS == LV_OS_CUSTOM
     #define LV_OS_CUSTOM_INCLUDE <stdint.h>
@@ -1173,7 +1173,7 @@
 #endif

 /** LVGL Windows backend */
-#define LV_USE_WINDOWS    0
+#define LV_USE_WINDOWS    1

 /** Use OpenGL to open window on PC and handle mouse and keyboard */
 #define LV_USE_OPENGLES   0
```

`Add files recursively…`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729734770274/3d65ff5c-a24b-4336-8a51-1b4bf4b1b014.png align="center")

Choose `lvgl` directory

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729734856130/cf8c0f91-2a70-4be5-b319-d41c193b471b.png align="center")

Add files

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729734920619/1b03828b-1788-46b9-980f-d55167809e3d.png align="center")

Choose `lv_conf.h`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729735005384/e0a3b19c-e61d-4368-a92c-8ce64aacb031.png align="center")

Rebuild (Ctrl+F11)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729735207726/6a7246c1-7505-4e3c-a35e-fe5b3b671a45.png align="center")

```bash
lvgl\demos\benchmark\assets\img_benchmark_avatar.c
    |12|fatal error: 
    lvgl/lvgl.h: No such file or directory|
```

Project → `Build options…`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729735331738/ef6b23f2-026e-4eeb-accb-dd4706c67ea2.png align="center")

Win32CodeBlockLVGL(or choose Debug/Release)

Compiler settings → Compiler Flags → Check `-std=c17`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729735401901/96ca404b-ee76-438a-b9d5-664372ef1d79.png align="center")

CodeBlock\_LVGL → Compiler settings → `#defines`

```bash
WINVER=0x0601
WIN32
_WIN32
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729735590919/e718d00d-e8d7-46f9-8ecd-1c1fd932c66f.png align="center")

CodeBlock\_LVGL → Search directories `. lvgl`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729735725778/bab93aa6-b69b-42f6-a4ce-a40f9e02d3e3.png align="center")

## Hello LVGL

`main.c`

```c
#include <stdlib.h>
#include <unistd.h>

#include "lvgl/lvgl.h"

static const wchar_t * title = L"LVGL port Windows CodeBlocks.      https://lvgl.io | https://docs.lvgl.io";

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    /*Initialize LVGL*/
    lv_init();

    /*Initialize the HAL for LVGL*/
    lv_display_t * display = lv_windows_create_display(title, 800, 480, 100, FALSE, FALSE);
    lv_windows_acquire_pointer_indev(display);

    /*Output prompt information to the console, you can also use printf() to print directly*/
    LV_LOG_USER("LVGL initialization completed!");


    lv_obj_t * label = lv_label_create(lv_screen_active());

    // Set the label text
    lv_label_set_text(label, "Hello, LVGL!");

    // Align the label in the center
    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

    while (1) {
        /* Periodically call the lv_task handler.
         * It could be done in a timer interrupt or an OS task too.*/
        lv_task_handler();
        usleep(5000);       /*Just to let the system breath*/
    }
    return 0;
}

```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729737639734/06c6ff25-62ea-4b06-ba22-435efab0ea1d.png align="center")

## Source Code

## [jiaxianhua/Win32CodeBlockLVGL](https://github.com/jiaxianhua/Win32CodeBlockLVGL)
