- Before you start
- C++ SDK, CMake and an x64 toolchain
- What you will build
- Run and edit a native window
Build requirements
Install the Visual Studio 2022 Desktop development with C++ workload, CMake and the Windows x64 C++ SDK. Extract the starter project. Replace the example Kui_DIR path below with the cmake directory in your SDK.
The CMake project
The Kui::Kui imported target provides headers and link dependencies. kui_copy_runtime_dlls copies runtime libraries for the selected configuration. The consumer must use the matching CRT: Release /MD or Debug /MDd.
cmake_minimum_required(VERSION 3.20)
project(forge_kui_first_window LANGUAGES CXX)
if(NOT CMAKE_CXX_STANDARD)
message(FATAL_ERROR "Set CMAKE_CXX_STANDARD to match the selected SDK package.")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Kui 3 REQUIRED)
add_executable(first_window main.cpp)
target_link_libraries(first_window PRIVATE Kui::Kui)
kui_copy_runtime_dlls(first_window)
Window and document
Platform::init initializes the platform and Window::create creates a window. The window’s Document loads HTML; show displays the window and Platform::run processes messages. This starter button has no application callback yet. Lesson three adds event handling.
#include <kui/kui.h>
int main() {
kui::Platform::init();
kui::WindowConfig config;
config.title = "Forge KUI";
config.width = 900;
config.height = 640;
auto window = kui::Window::create(config);
if (!window) return 1;
window->document()->loadHTML(R"(
<style>body { padding:48px; font-family:sans-serif; }
button { padding:12px 24px; }</style>
<h1>Hello KUI</h1><button>Save settings</button>
)");
window->show();
return kui::Platform::run();
}
Build and run
Open PowerShell in the project directory. Configuration should report the discovered Kui version. The executable and runtime libraries are placed in build/Release. Running the program displays the Hello KUI heading and a save button.
$cxxStandard = Read-Host SDK-standard
cmake -S . -B build -A x64 "-DCMAKE_CXX_STANDARD=$cxxStandard" -DKui_DIR=G:/SDK/kui/cmake
cmake --build build --config Release --parallel 4
.\build\Release\first_window.exeStartup problems
If KuiConfig.cmake is missing, check Kui_DIR. For a missing kui.dll, check the runtime-copy step and working directory. For a CRT mismatch, check the CMake configuration and SDK variant. If no window appears, check the Window::create result, show and the event loop.
Practice and acceptance
Use these actions to check completion; there is no need to copy the same code into another project.
- Locate the SDK cmake folder and the project CMakeLists.txt.
- Change the heading, rebuild and see the updated native window.
- Launch from build/Release and verify it is the current executable.
Something unclear?
Report an issue on this page →