Reference application · Windows 10+ · C++20

Build a real native Notepad.

Start from the maintained template, then add one safe vertical slice at a time: document state, Unicode files, commands, editor workflows, persistence, accessibility, tests, and packaging.

Starttemplates/basic-app
ToolchainVisual Studio 2026 or 2022
ResultInstallable x64 or ARM64 executable
ProofReal hidden-window GUI workflow
Step 1

Prove the untouched template first

Copy-Item -Recurse .\templates\basic-app ..\mwfl-notepad-tutorial
Set-Location ..\mwfl-notepad-tutorial
cmake -S . -B build -G "Visual Studio 18 2026" -A x64 `
  -DMWFL_SOURCE_DIR=D:/GitHub/mwfl
cmake --build build --config Debug

Visual Studio 2022 is equally supported; use generator Visual Studio 17 2022 and a separate build directory.

Step 2

Compose the document surface

SetLayout(mwfl::Column()
    .Add(toolbar_, mwfl::Auto())
    .Add(editor_, mwfl::Stretch())
    .Add(status_, mwfl::Auto()));

All wrappers are window members. The edit control stretches; native toolbar and status-bar measurements are converted through the Per-Monitor-V2 DIP layout.

Step 3

Make destructive actions safe

DocumentState decides whether a transition may proceed. The application asks Save, Discard, or Cancel before New, Open, close-window, and Exit. It marks a path or saved state only after I/O succeeds.

ReadTextFile validates UTF-8/UTF-16. WriteTextFileAtomic flushes a sibling temporary file, checks the original FileStamp, and atomically replaces the destination.

Step 4

Share commands, do not copy callbacks

commands_.Add(mwfl::Command(kSave, L"&Save", [this] {
    static_cast<void>(SaveDocument(false));
}).SetShortcut({FVIRTKEY | FCONTROL, 'S'}));

The same command supplies menu, toolbar, accelerator, checked/visible state, and callback. The focused Agent recipe adds the persisted Always on Top command without inventing an API.

Step 5

Verify the real executable

cmake --preset vs2026-x64
cmake --build --preset x64-debug --target mwfl_notepad
ctest --preset x64-debug -R "mwfl.notepad_gui" --output-on-failure

The hidden-window workflow covers launch, edit notification, atomic save, cancel, discard, reopen, command state, MSAA names, theme and DPI refresh, 50 repeated document cycles, resource growth, and close.

Step 6

Install or package it

cmake --build --preset x64-release
cmake --install build\presets\vs2026-x64 --config Release --prefix build\install
& .\build\install\bin\mwfl_notepad.exe

The CPack ZIP includes the executable, library, public headers, CMake package files, licenses, and documentation.

Continue

Use the detailed checklist