程序中使用自定義的鼠標(biāo)
發(fā)表時(shí)間:2024-06-16 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]一.建立工程與一個(gè)資源檔用Image Editor編輯一個(gè)鼠游標(biāo) (Fild New Resource File)新建一個(gè) CURSOR_1 的 CURSOR, 設(shè)定好它的 Hot Spot (Cursor Set Hot Spot)存檔時(shí)注意要和建立的Project存在同一個(gè)目錄...
一.建立工程與一個(gè)資源檔
用Image Editor編輯一個(gè)鼠游標(biāo)
(Fild New Resource File)
新建一個(gè) CURSOR_1 的 CURSOR, 設(shè)定好它的 Hot Spot
(Cursor Set Hot Spot)
存檔時(shí)注意要和建立的Project存在同一個(gè)目錄
在本例我們先假定為 MyCursor.res
二. 程序部分
定義一個(gè)常數(shù)crMyCursor, 這個(gè)常數(shù)您必須設(shè)成大於零
的任何整數(shù), 以 LoadCursor() 函數(shù)將自訂的鼠標(biāo)資源
load 進(jìn)來, 以下為源代碼:
// unit.pas
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls, Forms, Dialogs;
const
crMyCursor = 1; (* 宣告一個(gè)常數(shù) *)
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
{$R mycursor.res}//這行$R不可少, 否則自訂的鼠游標(biāo)就出不來了
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
//將鼠標(biāo)資源 load 進(jìn)來
Screen.Cursors[crMyCursor] := LoadCursor (hInstance,'CURSOR_1');
Cursor := crMyCursor;//指定 form1 的 cursor 為自訂鼠標(biāo)
Button1.Cursor := crMyCursor;//指定Button1的cursor為自訂鼠標(biāo)
end;
end.