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.

Backend Statistics
LanguageC++
Lines of code~7,100
HB_FUNC functions~135
Native APIWin32 API (CreateWindowEx, GDI)
Scintilla5.6.1 (dynamic DLL)
Supported OSWindows 10, Windows 11

Architecture Overview

graph TB A["Harbour .prg"] --> B["hbbuilder.ch
#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:

// win32_backend.cpp - Dark title bar
void EnableDarkTitleBar( HWND hWnd )
{
   BOOL dark = TRUE;
   DwmSetWindowAttribute(
      hWnd,
      DWMWA_USE_IMMERSIVE_DARK_MODE,
      &dark,
      sizeof( dark )
   );
}
System theme detection

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:

FileLocationPurpose
Scintilla.dllbin/Core Scintilla editing component
Lexilla.dllbin/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

CompilerVersionNotes
MSVC 202219.3xRecommended. Full C++17 support, best optimization.
MSVC 201919.2xFully supported. Available via Visual Studio 2019 or Build Tools.
MSVC CommunityLatestFree edition, identical compiler to Pro/Enterprise.
MSVC BuildToolsLatestCommand-line only. Good for CI/CD pipelines.
BCC7.7Embarcadero Borland C++ Compiler. Alternative to MSVC.

Build Script

The build_win.bat script handles the entire build process:

  1. Compiler detection — Scans for MSVC installations (2019, 2022, Community, BuildTools) and BCC.
  2. Environment setup — Calls vcvarsall.bat to set up the compiler environment.
  3. Harbour compilation — Builds Harbour from source if not already present.
  4. Scintilla build — Compiles Scintilla and Lexilla DLLs.
  5. IDE compilation — Compiles the HarbourBuilder IDE source.
  6. 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

FeatureWindows Implementation
Rich Edit controlRichEdit20W / RichEdit50W (msftedit.dll)
Common dialogsGetOpenFileName(), GetSaveFileName(), ChooseFont(), ChooseColor()
System trayShell_NotifyIcon() with NOTIFYICONDATA
Registry accessRegOpenKeyEx(), RegQueryValueEx()
File associationsRegistry-based under HKEY_CLASSES_ROOT
Drag and dropDragAcceptFiles() / WM_DROPFILES
ClipboardOpenClipboard(), SetClipboardData()
PrintingWin32 Print API (PrintDlg(), StartDoc())
Dark title barsDwmSetWindowAttribute() with DWMWA_USE_IMMERSIVE_DARK_MODE

Known Limitations

Dependencies

LibraryPurpose
user32.libWindow management, messages, controls
gdi32.libDrawing, fonts, bitmaps
comctl32.libCommon controls (TreeView, ListView, ProgressBar, etc.)
comdlg32.libCommon dialogs (Open, Save, Font, Color)
dwmapi.libDesktop Window Manager (dark title bars)
gdiplus.libGDI+ for advanced graphics
ole32.libCOM initialization, clipboard
shell32.libShell functions, drag-and-drop

On This Page

Getting Started Component Palette IDE Features Tutorials Reference Platforms Architecture Overview Native Window Creation Event Handling (WndProc) Dark Mode Support Scintilla Integration Compiler Options Supported Compilers Build Script Platform-Specific Features Known Limitations Dependencies