Win32/64 Interface

From Lazarus wiki
Jump to navigationJump to search
Windows logo - 2012.svg

This article applies to Windows only.

See also: Multiplatform Programming Guide

English (en) русский (ru)


The win32/64 interface is arguably the most polished and well developed interface of Lazarus, being also the most used one considering the number of downloads. Despite being the most complete, there are still some problems with it that need fixing.

Another important point about the win32/64 interface is that it is currently undergoing migration to unicode.

Win64: please see warning here on not using certain FPC/Lazarus Win64 versions.

Current issues


The scrolling is currently done by moving child controls instead of the client area as the LCL expects. For example in some cases it looks as if the children are being scrolled in reverse. The truth is that the scrolling is pretty much broken. Scrolling the child controls is incompatible with the other widgetsets and also has this drawback: Moving one child after the other generates several move messages. The LCL receives the messages and has to react each time (for instance it has to realign all anchored children). For a single widgetset you can attempt to overcome this problem, but the solution will never work well for all the other widgetsets. This approach works for Delphi's VCL, but not for the LCL. Therefore another approach must be implemented:


A solution would be to insert a 'client area' window between each child's window and its parent window. The child windows are placed on the 'client area' window, and when the children are scrolled the 'client area' window gets moved instead. This is already done by the other widgetsets.

Mattias: I will implement this eventually, but my winapi interface knowledge is limited and I have a lot of other Lazarus tasks already, so I can't say when I will implement it.

Related bug reports

Focus indication on themed controls

Controls (TCheckBox, TButton, TRadioButton, etc) loose their focus indication when the application is using themes.

Hints to solve

  • According to Paul it isn't related to WM_PAINT

Related bug reports

Navigating controls with the arrow keys

Related bug reports

Implementation details

This list explains how specific parts of the LCL are implemented on the Win32 interface to help people find the appropriate code in it to do bug fixes.

Background color of Standard Controls

See also: Windows_CE_Development_Notes#TRadioButton_and_TGroupBox

One might notice that on Windows there is no implementation for TWSWin32WinControl.SetColor and neither does it have for most standard controls (GroupBox, RadioButton, CheckBox, etc), even thougth those controls can have their background color changed.

The reason is that this is implemented by handling a WM_CTLCOLOR* message. Most standard controls (GroupBox, RadioButton, CheckBox, etc) will send a WM_CTLCOLORSTATIC message. On this message one can set the background color and a handle to the brush used to paint the control must be returned.

Another important detail about this is that child controls have their messages sent to the WindowProc of their parent. So, if one has a Form with a GroupBox and a couple of CheckBoxes inside the GroupBox the messages of the GroupBox will go to the Form and the messages of the CheckBoxes will go to the GroupBox (including the WM_CTLCOLORSTATIC message). To overcome this the win32 widgetset uses SetWindowLong to reset the WindowProc of controls with child controls to our centralized WindowControl on


See also: Windows_CE_Development_Notes#TCheckListBox

  • TWin32WSCustomCheckListBox implements some minimal methods
  • TWin32WSCustomListBox implements handle creating and most methods
  • TWin32CheckListBoxStrings is the main TStrings descendent for this class

On Windows, a TCheckListBox is a normal window of the class 'LISTBOX' which has the LBS_OWNERDRAWFIXED style set. When the listbox is created a WM_MEASUREITEM message will be sent, and after a WM_DRAWITEM message will be sent whenever an item needs to be painted. In the handler for this message a message LM_DRAWITEM message will be created.

The LM_DRAWITEM message is then intercepted by TWin32WidgetSet.CallDefaultWndHandler and handled in it's internal function:

procedure DrawCheckListBoxItem(CheckListBox: TCheckListBox; Data: PDrawItemStruct);

And here is the real code to paint the TCheckListBox items.

Note: This is kind of ugly, maybe this code should be moved to the LCL so we have a generic code to paint items in case the widgetset doesn't do it itself.

MSDN Docs about the LISTBOX:


Processing user messages in your window

write me

Processing non-user messages in your window

To have a custom processing of messages <= WM_USER you should use SetWindowLong from the Windows unit. It will return the address of the current WndProc, so you can just have your WndProc like this:

 if Msg = WM_COPYDATA then
 else CallOldWindowProc;

And you don't lose anything. With a clever code you can even use the same wndproc for any control, just take care to call the correct old wndproc in each case.


By intercepting the WM_NCHITTEST message you can avoid dragging the window.

Note: The part were the function interacts with "WM_NCHITTEST" has a very strange result in Windows XP. You will be unable to move the window. In Vista on the other hand, you still can. Commenting this section out seems to do no harm, and you are able to move the program's window in Windows XP.

  PrevWndProc: WNDPROC;
function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
  if uMsg=WM_NCHITTEST then
    result:=Windows.DefWindowProc(Ahwnd, uMsg, WParam, LParam);  //not sure about this one
    if result=windows.HTCAPTION then result:=windows.HTCLIENT;
  result:=CallWindowProc(PrevWndProc,Ahwnd, uMsg, WParam, LParam);

//install our message handler
procedure TForm1.FormCreate(Sender: TObject);

Other Interfaces

Platform specific Tips

Interface Development Articles