No results
3
Home
dxtr edited this page 2026-10-17 04:57:32 +02:00
cl-win32
Win32 for Common Lisp: window classes and window procedures, windows, message loops, DPI, keyboard and pointer state, input methods and the clipboard, through user32, kernel32 and imm32. Handles are integers, strings are Lisp strings, and a failed call signals a condition.
It is the layer cl-windowing's Win32 backend is built on, and knows nothing about it.
(asdf:load-system :cl-win32)
(defpackage #:example
(:use #:cl)
(:local-nicknames (#:win32 #:cl-win32)))
(in-package #:example)
;; Windows calls this with each message for the windows of its classes.
(win32:define-window-procedure example-procedure (window message wparam lparam)
(declare (ignore wparam lparam))
(cond ((= message win32:+wm-close+) (win32:destroy-window window) 0)
((= message win32:+wm-destroy+) (win32:post-quit-message 7) 0)
;; NIL: the default handling.
(t nil)))
(win32:set-thread-dpi-awareness :per-monitor-aware-v2)
(win32:register-window-class "example" 'example-procedure)
(let ((window (win32:create-window "example" :title "Hello" :width 640 :height 400)))
(win32:show-window window)
(prog1 (list (win32:window-text window)
(win32:window-dpi window)
;; As if the user closed the window.
(progn (win32:post-message window win32:+wm-close+)
(win32:run-message-loop)))
(win32:unregister-window-class "example")))
;; => ("Hello" 96 7) on a display at 100%
Pages
Start here
- Getting Started: requirements, loading, and a first window, step by step.
- Concepts: handles, window classes and procedures, messages, and why windows belong to threads.
Guides
- Window Procedures and Classes: defining window procedures, what they return, and registering classes.
- Windows: creating, sizing, titling and destroying windows, popups, styles and placement, displays, and fullscreen.
- Messages and Message Loops: posting and sending messages, running a loop, and taking messages apart.
- DPI: sizes in pixels, scales, and windows that move between displays.
- Keyboard and Pointer: virtual keys, key state, scancodes, capture and leaving, cursors, holding the pointer, and raw mouse motion.
- Input Methods and the Clipboard: input methods for Chinese, Japanese and other scripts, and the clipboard's text.
- Event Objects: flags that one thread sets and another waits for.
- Recipes: windows on a thread of their own, waking a loop, resizing, keys and drags.
Reference
- API Reference: every exported symbol of
cl-win32. - Errors:
win32-error, and errors in window procedures. - Lifetimes and Threads: what to release, and which thread may do what.
- Raw FFI Layer:
cl-win32/ffi, for what the idiomatic layer does not cover. - Platforms and Testing: requirements, Windows versions, and running the test suite.
Systems
| System | What it is |
|---|---|
cl-win32 |
The library. Use this one. |
cl-win32/ffi |
Raw bindings to user32, kernel32 and imm32, one Lisp function per C function. |
cl-win32/test |
The Parachute test suite. |
License
MIT.