如何为窗体的标题栏、系统菜单图标和最小化、最大化和关闭按钮设置自定义光标?

How to set custom cursor for the form's title bar, system menu icon and minimize, maximize and close buttons?

是否有 Windows API 可以为表单的标题栏、系统菜单图标以及最小化、最大化和关闭按钮设置自定义光标?

我有一个函数可以为给定控件加载和设置光标:

type

 TFrm_Main = class(TForm)
   ....
 private
  procedure SetCursor_For(AControl: TControl; ACursor_FileName: string;
    Const ACurIndex: Integer);
 ...
 end;
 const
   crOpenCursor = 1;
   crRotateCursor = 2;
   crCursor_Water = 3;

 var
   Frm_Main: TFrm_Main;
 ...
 procedure TFrm_Main.SetCursor_For(AControl: TControl; ACursor_FileName: 
  string; const ACurIndex: Integer);
 begin
   Screen.Cursors[ACurIndex] := Loadcursorfromfile(PWideChar(ACursor_FileName));
   AControl.Cursor := ACurIndex;
 end;

我正在以这种方式使用它的形式:

SetCursor_For(Frm_Main, 'Cursors\Cursor_Rotate.ani', crRotateCursor);

但我缺少为特定表单部分(如表单标题栏、系统菜单图标以及最小化、最大化和关闭按钮)设置光标的方法。有没有办法为这些表单部件设置光标?

处理 WM_SETCURSOR message and test the message parameter's HitTest field for one of the following hit test code values, and set the cursor by using SetCursor function returning True to the message Result (Windows API macros TRUE and FALSE coincidentally match to the Delphi's Boolean 类型值,因此您只能在那里进行类型转换):

例如:

type
  TForm1 = class(TForm)
  private
    procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
  end;

implementation

procedure TForm1.WMSetCursor(var Msg: TWMSetCursor);
begin
  case Msg.HitTest of
    HTCAPTION:
    begin
      Msg.Result := LRESULT(True);
      Winapi.Windows.SetCursor(Screen.Cursors[crHandPoint]);
    end;
    HTSYSMENU:
    begin
      Msg.Result := LRESULT(True);
      Winapi.Windows.SetCursor(Screen.Cursors[crHelp]);
    end;
    HTMINBUTTON:
    begin
      Msg.Result := LRESULT(True);
      Winapi.Windows.SetCursor(Screen.Cursors[crUpArrow]);
    end;
    HTMAXBUTTON:
    begin
      Msg.Result := LRESULT(True);
      Winapi.Windows.SetCursor(Screen.Cursors[crSizeAll]);
    end;
    HTCLOSE:
    begin
      Msg.Result := LRESULT(True);
      Winapi.Windows.SetCursor(Screen.Cursors[crNo]);
    end;
  else
    inherited;
  end;
end;