Search code examples
delphiwinapicursordelphi-xe4

How to use custom cursor in window non-client area using Delphi


I have custom Delphi VCL control that intercepts WM_NCHITTEST message and returns HTCAPTION to make control movable on its parent window.

That part works fine, but returning HTCAPTION also resets my custom cursor to Windows default one when hovering over that control. Is there any way I can use HTCAPTION and still show my custom cursor?

Note: I know how to implement control movement without using HTCAPTION and solve cursor issue that way


Solution

  • Use a WM_SETCURSOR message handler:

    procedure TCustomVCLControl.WMSetCursor(var Message: TWMSetCursor);
    begin
      SetCursor(Screen.Cursors[cr..]);
      Message.Result := 1;
    end;