Windows Platform Guide
The Windows backend uses the native Win32 API and GDI/GDI+ for all drawing. It is written in C++ and compiled with MSVC or BCC. This is the most mature and feature-complete backend in HarbourBuilder.
| Language | C++ |
|---|---|
| Lines of code | ~7,100 |
| HB_FUNC functions | ~135 |
| Native API | Win32 API (CreateWindowEx, GDI) |
| Scintilla | 5.6.1 (dynamic DLL) |
| Supported OS | Windows 10, Windows 11 |
Architecture Overview
#xcommand preprocessor"] B --> C["TForm, TControl
Harbour OOP classes"] C --> D["HB_FUNC Bridge
~135 functions"] D --> E["Win32 Backend
C++ / CreateWindowEx"] E --> F["GDI / GDI+
Drawing"] E --> G["Scintilla 5.6.1
DLL (code editor)"] style A fill:#58a6ff,stroke:#388bfd,color:#0d1117 style B fill:#8b5cf6,stroke:#7c3aed,color:#fff style C fill:#f59e0b,stroke:#d97706,color:#0d1117 style D fill:#f59e0b,stroke:#d97706,color:#0d1117 style E fill:#0078d4,stroke:#005a9e,color:#fff style F fill:#0078d4,stroke:#005a9e,color:#fff style G fill:#555,stroke:#333,color:#fff
Native Window Creation
Every HarbourBuilder window and control is a native Win32 window created via CreateWindowEx().
The backend registers custom window classes at startup:
// win32_backend.cpp - Window class registration void RegisterClasses( HINSTANCE hInstance ) { WNDCLASSEX wc = { sizeof( WNDCLASSEX ) }; wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 ); wc.lpszClassName = "HBBUILDER_FORM"; RegisterClassEx( &wc ); wc.lpszClassName = "HBBUILDER_BUTTON"; RegisterClassEx( &wc ); // ... additional classes for EDIT, STATIC, etc. }
Controls are standard Win32 common controls: BUTTON, EDIT, STATIC,
COMBOBOX, LISTBOX, msctls_progress32, msctls_trackbar32,
SysTreeView32, SysListView32, and RichEdit.
Event Handling (WndProc)
The Windows backend uses a central WndProc (window procedure) that receives all messages
from the OS. It dispatches them to Harbour event handlers:
// win32_backend.cpp - Message dispatch LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_COMMAND: FireEvent( hWnd, EVENT_CLICK, CT_BUTTON ); break; case WM_LBUTTONDOWN: FireEvent( hWnd, EVENT_MOUSEDOWN, (int) LOWORD( lParam ), (int) HIWORD( lParam ) ); break; case WM_KEYDOWN: FireEvent( hWnd, EVENT_KEYDOWN, (int) wParam ); break; case WM_PAINT: FireEvent( hWnd, EVENT_PAINT ); break; case WM_CLOSE: if( !FireCloseQuery( hWnd ) ) return 0; // Cancel close break; // ... additional message handling } return DefWindowProc( hWnd, msg, wParam, lParam ); }
Dark Mode Support
HarbourBuilder on Windows follows the system theme. Dark mode is implemented using:
DwmSetWindowAttribute()— Enables dark title bars on Windows 10/11 by settingDWMWA_USE_IMMERSIVE_DARK_MODE.- Dark window class styles — When the system is in dark mode, the backend registers window classes with dark background brushes.
- GDI dark colors — Control colors use dark palette values (near-black backgrounds, light text).
- Scintilla dark theme — The code editor uses a dark lexer style matching the IDE theme.
// win32_backend.cpp - Dark title bar void EnableDarkTitleBar( HWND hWnd ) { BOOL dark = TRUE; DwmSetWindowAttribute( hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark, sizeof( dark ) ); }
HarbourBuilder reads the Windows theme setting from the registry
(HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme)
at startup and configures all controls accordingly.
Scintilla Integration
The Windows backend uses Scintilla 5.6.1 as a dynamic library:
| File | Location | Purpose |
|---|---|---|
Scintilla.dll | bin/ | Core Scintilla editing component |
Lexilla.dll | bin/ | Lexer library (syntax highlighting) |
Scintilla is loaded at runtime via LoadLibrary() and GetProcAddress(). The
backend creates a Scintilla window as a child of the code editor tab and communicates with it
via SendMessage().
// Loading Scintilla at runtime HMODULE hSci = LoadLibrary( "Scintilla.dll" ); SCI_CREATE fnCreate = (SCI_CREATE) GetProcAddress( hSci, "Scintilla_DirectFunction" ); // Creating the editor window HWND hEditor = CreateWindowEx( 0, "Scintilla", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE, 0, 0, 800, 600, hParent, NULL, hInstance, NULL );
Compiler Options
Supported Compilers
| Compiler | Version | Notes |
|---|---|---|
| MSVC 2022 | 19.3x | Recommended. Full C++17 support, best optimization. |
| MSVC 2019 | 19.2x | Fully supported. Available via Visual Studio 2019 or Build Tools. |
| MSVC Community | Latest | Free edition, identical compiler to Pro/Enterprise. |
| MSVC BuildTools | Latest | Command-line only. Good for CI/CD pipelines. |
| BCC | 7.7 | Embarcadero Borland C++ Compiler. Alternative to MSVC. |
Build Script
The build_win.bat script handles the entire build process:
- Compiler detection — Scans for MSVC installations (2019, 2022, Community, BuildTools) and BCC.
- Environment setup — Calls
vcvarsall.batto set up the compiler environment. - Harbour compilation — Builds Harbour from source if not already present.
- Scintilla build — Compiles Scintilla and Lexilla DLLs.
- IDE compilation — Compiles the HarbourBuilder IDE source.
- Linking — Links against
user32.lib,gdi32.lib,comctl32.lib,dwmapi.lib, and the Harbour runtime.
:: build_win.bat - Build process set HBDIR=C:\harbour call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 harbour hbbuilder.prg /n /q /gc1 cl /O2 /c hbbuilder.c win32_backend.cpp /I%HBDIR%\include /I.\include link hbbuilder.obj win32_backend.obj /SUBSYSTEM:WINDOWS ^ user32.lib gdi32.lib comctl32.lib dwmapi.lib ^ %HBDIR%\lib\win\msvc64\harbour.lib
Platform-Specific Features
| Feature | Windows Implementation |
|---|---|
| Rich Edit control | RichEdit20W / RichEdit50W (msftedit.dll) |
| Common dialogs | GetOpenFileName(), GetSaveFileName(), ChooseFont(), ChooseColor() |
| System tray | Shell_NotifyIcon() with NOTIFYICONDATA |
| Registry access | RegOpenKeyEx(), RegQueryValueEx() |
| File associations | Registry-based under HKEY_CLASSES_ROOT |
| Drag and drop | DragAcceptFiles() / WM_DROPFILES |
| Clipboard | OpenClipboard(), SetClipboardData() |
| Printing | Win32 Print API (PrintDlg(), StartDoc()) |
| Dark title bars | DwmSetWindowAttribute() with DWMWA_USE_IMMERSIVE_DARK_MODE |
Known Limitations
- Manifest requirement — Windows applications need an embedded manifest for visual styles (ComCtl32 v6) and DPI awareness. HarbourBuilder includes this in the build.
- DPI scaling — The backend is DPI-aware but control positioning uses pixel coordinates. High-DPI displays may require manual size adjustments.
- RichEdit version — The RichEdit control depends on
msftedit.dllwhich may not be available on very old Windows versions (pre-Windows 8). - Windows XP/Vista/7/8 — Not officially supported. The backend targets Windows 10+ APIs. Some features (dark title bars via DWM) require Windows 10 build 18985+.
Dependencies
| Library | Purpose |
|---|---|
user32.lib | Window management, messages, controls |
gdi32.lib | Drawing, fonts, bitmaps |
comctl32.lib | Common controls (TreeView, ListView, ProgressBar, etc.) |
comdlg32.lib | Common dialogs (Open, Save, Font, Color) |
dwmapi.lib | Desktop Window Manager (dark title bars) |
gdiplus.lib | GDI+ for advanced graphics |
ole32.lib | COM initialization, clipboard |
shell32.lib | Shell functions, drag-and-drop |