如何将光标类型更改为Excel网格光标?

Hik*_*Din 2 delphi

我怎么能改变一个TStringGridExcel网格光标的光标类型

Excel游标不是delphi或system32中的游标类型.

我使用了光标所在的swat示例中的代码extrares.res

Screen.Cursors[crMaletUp] := LoadCursor(HInstance, 'Malet');
Screen.Cursors[crMaletDown] := LoadCursor(HInstance, 'MaletDown');
Screen.Cursor := TCursor(crMaletUp);
Run Code Online (Sandbox Code Playgroud)

在其他方面,我使用其他代码,但提供帮助,但它不起作用

procedure TForm1.Button1Click(Sender: TObject);
begin
  bmpMask := TBitmap.Create;
  bmpColor := TBitmap.Create;

  bmpMask.LoadFromFile('SquareMask.bmp');
  bmpColor.LoadFromFile('Square.bmp');

  with iconInfo do
  begin
    fIcon := false;
    xHotspot := 15;
    yHotspot := 15;
    hbmMask := bmpMask.Handle;
    hbmColor := bmpColor.Handle;
  end;

  Screen.Cursors[crMyCursor] := CreateIconIndirect(iconInfo);

  Screen.Cursor := crMyCursor;

  bmpMask.Free;
  bmpColor.Free;
end;
Run Code Online (Sandbox Code Playgroud)

Ian*_*oyd 6

我想我会回答这个问题,因为没有其他人愿意.

我有一个功能,修复了一些Delphi的内置游标(使用标准的 Windows游标).但我也用它来添加一些新的自定义游标.我将减少我的功能只添加两个新游标:

  • crColorPicker: 在此输入图像描述 (颜色选择器光标)
  • crExcelCross: 在此输入图像描述 (Excel十字光标)

首先,我需要ExcelCross.cur在Visual Studio中创建一个:

在此输入图像描述

现在创建一个新的资源脚本文件wumpa.rc,我将在其中指定我的两个游标文件:

wumpa.rc

ColorPicker    CURSOR   "ColorPicker.cur"
ExcelCross     CURSOR   "ExcelCross.cur"
Run Code Online (Sandbox Code Playgroud)

wumpa.rc使用Project - > Add to project将该文件添加到我的项目中.

现在我声明两个全局常量来表示我的新游标.喜欢crHourGlass,或者crNo,我们现在将拥有crColorPickercrExcelCross:

const   
   {Cursor Constants}
   crColorPicker =  1003;
   crExcelCross = 1004;
Run Code Online (Sandbox Code Playgroud)

现在我们必须CURSOR在运行时加载这两个资源:

procedure LoadNewCursors;
var
    i: Integer;
    cursorHandle: HCURSOR;
begin
    //Load ColorPicker cursor
    cursorHandle := LoadCursor(hInstance, 'ColorPicker');
    if CursorHandle <> 0 then
        Screen.Cursors[crColorPicker] := cursorHandle
    else
        Screen.Cursors[crColorPicker] := Screen.Cursors[crNone];

    //Load Excel Cross cursor
    cursorHandle := LoadCursor(hInstance, 'ExcelCross');
    if CursorHandle <> 0 then
        Screen.Cursors[crExcelCross] := cursorHandle
    else
        Screen.Cursors[crExcelCross] := Screen.Cursors[crNone];
end;

initialization
    LoadNewCursors;
Run Code Online (Sandbox Code Playgroud)

有了这个工作,我可以设置我的StringGrid使用crExcelCross:

procedure TForm1.FormCreate(Sender: TObject);
begin
    StringGrid1.Cursor := crExcelCross;
end;
Run Code Online (Sandbox Code Playgroud)

ba-zinga,你有一个Excel十字光标:

在此输入图像描述

注意:任何代码都将发布到公共域中.无需归属.