【问题标题】:How to set custom cursor for the form's title bar, system menu icon and minimize, maximize and close buttons?如何为表单的标题栏、系统菜单图标以及最小化、最大化和关闭按钮设置自定义光标?
【发布时间】:2018-09-10 12:32:00
【问题描述】:

是否有用于为表单的标题栏、系统菜单图标以及最小化、最大化和关闭按钮设置自定义光标的 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);

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

【问题讨论】:

  • 从您的公开数据中,我可以看到您从未对任何答案进行过投票,也从未接受过对您的问题的任何答案。也许你不明白我的意思,所以请看someone-answers

标签: delphi winapi vcl


【解决方案1】:

处理WM_SETCURSOR消息并测试消息参数的HitTest字段是否有以下命中测试代码值之一,并使用返回True消息的SetCursor函数设置光标Result(Windows API 宏 TRUEFALSE 恰好匹配 Delphi 的 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2013-04-17
    • 2020-10-02
    • 2011-05-29
    • 1970-01-01
    • 2011-02-02
    相关资源
    最近更新 更多