Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

fpc-directui-demo

LCL 없이 순수 Free Pascal/Win32 로 만든 최소 DirectUI 스켈레톤 (windowless 컨트롤, GDI 더블버퍼, per-monitor DPI v2, 한글 유니코드)

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

fpc-directui-demo

Read this in another language: 한국어

A minimal DirectUI skeleton written in pure Free Pascal — no LCL, no third-party widget set. It shows how a handful of raw Win32 API calls can replace what LCL's TApplication / TForm normally do.

A single native window (one HWND) hosts windowless controls (two buttons and a label) that are painted and hit-tested by hand, with GDI double-buffering, per-monitor DPI v2 awareness, and correct Unicode (Korean) text rendering.

Why this exists

Most Pascal GUIs reach for the LCL or the VCL, where every button is a real window. DirectUI takes the opposite approach used by modern, fluid UIs: the OS owns exactly one window, and everything inside it is your own retained scene graph that you draw and route events to. This repository is a deliberately tiny, readable reference for that pattern on Windows — small enough to read in one sitting, complete enough to click.

The renderer is intentionally isolated behind a neutral TPainter API (FillRectangle / FrameRectangle / DrawText), so the GDI backend can be swapped for Direct2D by rewriting only those method bodies.

Features

  • No LCL dependency — links against the FPC Windows unit only.
  • One HWND, many controls — windowless button/label tree, hit-tested by the form.
  • Static WndProc ↔ instance bridge via GWLP_USERDATA.
  • Flicker-free GDI double-buffering (WM_ERASEBKGND intercepted).
  • Per-monitor DPI v2 with graceful fallback on older Windows.
  • Correct Korean text rendering (Unicode-clean throughout).
  • Renderer abstraction ready for a Direct2D swap.

Project layout

Path Role
src/ Sources (.lpr / .pas)
bin/ Build output — directui_demo.exe
build/ Intermediate artifacts (.o / .ppu / .a), regenerable
doc/ Documentation (detailed FPC porting notes)
build.ps1 Build script (Win64)

Sources (src/)

Unit Responsibility
directui_demo.lpr Entry point — builds the form/controls and wires events
duiapp.pas TApplication — DPI setup, message pump, termination
duiforms.pas TForm — owns the single HWND, WndProc bridge, message dispatch, double-buffered paint, per-monitor DPI v2
duicontrols.pas Windowless control tree (TControl / button / label)
duipaint.pas Renderer abstraction (TPainter, GDI double buffer) — the Direct2D swap point

Build

Requires FPC 3.2.2 at C:\DEV\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe.

From PowerShell:

powershell
# Build -> bin\directui_demo.exe
.\build.ps1

# Clean, rebuild, and run
.\build.ps1 -Clean -Run

Manual invocation:

pascal
fpc -Twin64 -Mdelphiunicode -O2 -FEbin -FUbuild -Fusrc src\directui_demo.lpr

Run

Launch bin\directui_demo.exe. A single window appears with a label and two buttons — "증가 (+1)" (increment) and "초기화" (reset) — that respond to hover/press and update a click counter.

Prefer a prebuilt binary? Grab directui_demo.exe from the Releases page.

Notes on the FPC port

The original code was Delphi-flavoured (Winapi.*). Building it on FPC 3.2.2 required a few adjustments — most importantly, {$codepage utf8} in every unit so Korean string literals decode correctly. See doc/README.md for the full list.