准备用LoadCursor函数加载自定义光标(用image editor写好的MyCursor.res放在项目的相同目录下),不知道为什么总是实现不了,报“加载资源文件中的光标资源出错”。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
{$R MyCursor.res}const
crMyCursor = 1;procedure TForm1.FormCreate(Sender: TObject);
Var
ResultCursor:Integer;
begin
ResultCursor:=LoadCursor(Hinstance, 'MyCursor');
if ResultCursor<>0 then
begin
Screen.Cursors[crMyCursor] := ResultCursor;
form1.Cursor := crMyCursor;
end
else
ShowMessage('加载资源文件中的光标资源出错!') ;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
{$R MyCursor.res}const
crMyCursor = 1;procedure TForm1.FormCreate(Sender: TObject);
Var
ResultCursor:Integer;
begin
ResultCursor:=LoadCursor(Hinstance, 'MyCursor');
if ResultCursor<>0 then
begin
Screen.Cursors[crMyCursor] := ResultCursor;
form1.Cursor := crMyCursor;
end
else
ShowMessage('加载资源文件中的光标资源出错!') ;
end;end.
加个PChar试试,我这里没Delphi,没办法帮你试。
begin
Screen.Cursors[crMycursor] := LoadCursor(hInstance, MAKEINTRESOURCE('MyCursor'));
form11.Cursor := crMyCursor;
end;
procedure TForm1.FormCreate(Sender: TObject);
Var
ResultCursor:Integer;
begin
ResultCursor:=LoadCursor(Hinstance, MAKEINTRESOURCE('MyCursor'));
if ResultCursor<>0 then
begin
Screen.Cursors[crMyCursor] := ResultCursor;
form1.Cursor := crMyCursor;
end
else
ShowMessage('加载资源文件中的光标资源出错!') ;
end;
我測試了你的代碼沒有問題,請看看你的*.res資源文件有沒有問題?你的資源文件裡面的光標的名稱要和代碼上的一樣哦.代碼上是"MyCursor",所以資源文件上的也要和它一樣.