明辉站/网站教程/内容

程序中使用自定义的鼠标

网站教程2024-02-15 阅读
[摘要]一.建立工程与一个资源档用Image Editor编辑一个鼠游标  (Fild New Resource File)新建一个 CURSOR_1 的 CURSOR, 设定好它的 Hot Spot  (Cursor Set Hot Spot)存档时注意要和建立的Project存在同一个目录...
一.建立工程与一个资源档
用Image Editor编辑一个鼠游标
  (Fild New Resource File)
新建一个 CURSOR_1 的 CURSOR, 设定好它的 Hot Spot
  (Cursor Set Hot Spot)
存档时注意要和建立的Project存在同一个目录
在本例我们先假定为 MyCursor.res
二. 程序部分
定义一个常数crMyCursor, 这个常数您必须设成大於零
的任何整数, 以 LoadCursor() 函数将自订的鼠标资源
load 进来, 以下为源代码:
// unit.pas
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls, Forms, Dialogs;
const
crMyCursor = 1; (* 宣告一个常数 *)
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
{$R mycursor.res}//这行$R不可少, 否则自订的鼠游标就出不来了
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
//将鼠标资源 load 进来
Screen.Cursors[crMyCursor] := LoadCursor (hInstance,'CURSOR_1');
Cursor := crMyCursor;//指定 form1 的 cursor 为自订鼠标
Button1.Cursor := crMyCursor;//指定Button1的cursor为自订鼠标
end;
end.

……

相关阅读