再一次来自程序资源的动画(* .ani)游标(Delphi 2010) [英] Once again about animation (*.ani) cursors from program resources (Delphi 2010)

查看:113
本文介绍了再一次来自程序资源的动画(* .ani)游标(Delphi 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个资源文件, Cur.rc 。它包含

  CUR1 21MYCURSOR.ANI

mycursor.ani 是一个存在的文件。这是一个普通的.ani动画游标。



我使用

  Brcc32 cur.rc 

导致文件 cur.res在我项目的Unit1(我也尝试过该项目的.dpr文件)中,我添加了

  {$ R cur.res} 

在FormCreate事件中,

  Screen.Cursors [8]:= LoadCursor(HInstance,'CUR1'); 
Screen.Cursor:= 8;
// p.s. 8 - 例如,可以是0 .... n或常数

我运行应用程序。光标应该更改为我的动画光标。



这应该很简单。我已经尝试了不同来源的几个不同的游标文件。但是它不起作用。



如果从文件加载,它可以工作:

  Screen.Cursors [8]:= LoadCursorFromFile('d:\1.ani'); 
Screen.Cursor:= 8;

如何从资源加载动画游标?为什么不加载普通光标?






这将无法正常工作。显然,没有办法从资源中加载动画光标,而不必首先使用文件。



尽管如此:

  // MyCursor.rc 
BGCURSOR ANICURSORD:\TEMP\Background.ani

// Unit1.pas
{$ R MyCursor.res MyCursor.rc}

procedure TForm1.FormCreate(Sender:TObject);
var
Res:TResourceStream;
FileName:string;
HC:HCURSOR;
const
BGCursor = 8; //可以从0..32767
开始
Res:= TResourceStream.Create(MainInstance,'BGCURSOR','ANICURSOR');
try
FileName:= ExtractFilePath(ParamStr(0))+'BGCursor.ani';
Res.SaveToFile(FileName);
HC:= LoadCursorFromFile(PChar(FileName));
Screen.Cursors [BGCursor]:= HC;
Screen.Cursor:= BGCursor;
finally
DeleteFile(FileName);
Res.Free;
结束
结束






我写了两个答案后,因为评论不希望适用。



PS在Delphi 2010上编写,但我认为,就像Delphi 7一样。



基本问题:



仅适用于Panel1。
完整集合中的初始代码,此处为文本,如果长度为:



完整示例已尝试:

  1。 3个面板 - 从表格开始,每个人都被指定为游标。 
2.仅在文件
上的第一个或者加载光标时工作3.完整集(小程序,游标等)中的全部 - exe(执行) - 也有

完整集中的初始代码,此处为文本,如果长度为:

 界面

使用
Windows,消息,SysUtils,变体,类,图形,控件,表单,
对话框,StdCtrls,ExtCtrls;

Const
CurConst = 8; // 8 ..例如,8就像我:)
CurConst1 = 7;
CurConst2 = 6;

type
TForm1 = class(TForm)
Panel1:TPanel;
Panel2:TPanel;
Button1:TButton;
Panel3:TPanel;
procedure FormCreate(Sender:TObject);
procedure Button1Click(Sender:TObject);
private
{私人声明}
public
{公开声明}
end;

var
Form1:TForm1;
cur:HCursor;

执行

{$ R * .dfm}
{$ R My.res}

程序TForm1.Button1Click(发件人: TObject);
var
s:string;
begin
s:= IncludeTrailingPathDelimiter(extractfilepath(paramstr(0)))+'sc1.ani';
showmessage('Temp value:'+ s);
Screen.Cursors [CurConst]:= LoadCursorFromFile(pchar(s));
panel1.Cursor:= CurConst;
panel2.Cursor:= CurConst;
panel3.Cursor:= CurConst;
结束

procedure TForm1.FormCreate(Sender:TObject);
begin
// panel 1
Screen.Cursors [CurConst]:= LoadCursor(HInstance,'V_0');
panel1.Cursor:= CurConst;
//面板2
Screen.Cursors [CurConst1]:= LoadCursor(HInstance,'V_1');
panel2.Cursor:= CurConst1;
// panel 2
Screen.Cursors [CurConst2]:= LoadCursor(HInstance,'V_2');
panel3.Cursor:= CurConst2;
结束

结束。

DownLoad(完整的项目代码): http://www.sendspace.com/file/jbzrpx (关闭弹出窗口,向下看);镜像:注意 - 任何支付它是没有必要的(在缓慢的参考下载(大小4 mb)) http://rapidshare.com/files/455515706/TestCursor.zip (没有病毒 - 测试Symantec - 11.6.3000 SEP)一般来说,完整集中的初始代码将会明白。 p>

解决方案

显然,api的资源加载器比文件加载器有些挑剔,或者要求有点不同。



我可以让您的光标在您提供的完整项目代码下载中工作,甚至不用触摸代码,感谢可执行文件包括:




  • 在十六进制编辑器中打开sc1.ani。
  • 找到文件中的第二个双字(第一个是签名RIFF)。双字是'62 0F 00 00',这是3938,这是文件大小。将其修改为5A 0F 00 00,即'3930',现在它表示长度标识符后剩余字节的总数。保存ani文件。
  • 资源黑客中打开可执行文件,或兼容资源编辑器,并将V_1替换为修改后的文件。
  • 保存可执行文件并运行。



您可以使用 Greenfish图标编辑器打开动画光标,然后再次保存。似乎产生兼容的文件。


I create a resource file, Cur.rc. It contains

CUR1   21   "MYCURSOR.ANI"

mycursor.ani is a file that exists. It's a normal .ani animated cursor.

I compile the resource file using

Brcc32 cur.rc  

which results in the file cur.res

In Unit1 of my project (I tried the project's .dpr file as well), I added

{$R cur.res} 

In the FormCreate event,

Screen.Cursors[8]:=LoadCursor(HInstance, 'CUR1');
Screen.Cursor := 8;
// p.s. 8 - for an example, can be 0.... n or a constant

I run the application. The cursor should change to my animated cursor.

This should be simple. I've tried several different cursor files from different sources. But it doesn't work.

It works if you load from a file:

Screen.Cursors [8]:=LoadCursorFromFile('d:\1.ani'); 
Screen.Cursor:=8;

How do I load the animated cursor from a resource? Why doesn't it work like loading a normal cursor?


This won't work. Apparently, there's no way to load an animated cursor from a resource without going to a file first.

This works, though:

// MyCursor.rc
BGCURSOR ANICURSOR "D:\TEMP\Background.ani"

// Unit1.pas
{$R MyCursor.res MyCursor.rc}

procedure TForm1.FormCreate(Sender: TObject);
var
  Res: TResourceStream;
  FileName: string;
  HC: HCURSOR;
const
  BGCursor = 8;  // Can be anything from 0..32767
begin
  Res := TResourceStream.Create(MainInstance, 'BGCURSOR', 'ANICURSOR');
  try
    FileName := ExtractFilePath(ParamStr(0)) + 'BGCursor.ani';
    Res.SaveToFile(FileName);
    HC := LoadCursorFromFile(PChar(FileName));
    Screen.Cursors[BGCursor] := HC;
    Screen.Cursor := BGCursor;
  finally
    DeleteFile(FileName);
    Res.Free;
  end;
end;


I write it after two answers because comments do not wish to be applied.

P.S. Wrote on Delphi 2010, but I think, as on Delphi 7 will go.

The basic question:

Works only for Panel1. Initial code in the complete set, here text, if to whom long:

The full example has tried to make:

1. 3 panels - at form start on everyone are appointed the cursor.
2. Works only on the first or at loading of the cursor from a file
3. All in the complete set (the small program, cursors, etc.) - exe (executed) - too there

Initial code in the complete set, here text, if to whom long:

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

Const
  CurConst = 8; // 8 .. example, 8 is like me :)
  CurConst1 = 7;
  CurConst2 = 6;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Panel3: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  cur: HCursor;

implementation

{$R *.dfm}
{$R My.res}

procedure TForm1.Button1Click(Sender: TObject);
var 
  s: string;
begin
  s:=IncludeTrailingPathDelimiter(extractfilepath(paramstr(0)))+'sc1.ani';
  showmessage('Temp value: '+ s);
  Screen.Cursors[CurConst]:=LoadCursorFromFile(pchar(s));
  panel1.Cursor:=CurConst;
  panel2.Cursor:=CurConst;
  panel3.Cursor:=CurConst;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // panel 1
  Screen.Cursors[CurConst] := LoadCursor(HInstance,'V_0');
  panel1.Cursor:=CurConst;
  // panel 2
  Screen.Cursors[CurConst1] := LoadCursor(HInstance,'V_1');
  panel2.Cursor := CurConst1;
  // panel 2
  Screen.Cursors[CurConst2] := LoadCursor(HInstance,'V_2');
  panel3.Cursor := CurConst2;
end;

end.

DownLoad (full project code): http://www.sendspace.com/file/jbzrpx (close popup window, look down); mirror: The attention - anything to pay it is not necessary (is downloaded under the slow reference (the size 4 mb)) http://rapidshare.com/files/455515706/TestCursor.zip (no viruses - testing Symantec - 11.6.3000 SEP) In general there an initial code in the complete set - will understand.

解决方案

Apparently the resource loader of the api is somewhat pickier than the file loader, or the requirements are a bit different.

I was able to make your cursors work in the full project code download you provided, without even touching the code, thanks to the executable included:

  • Open 'sc1.ani' in a hex editor.
  • Locate the second double word in the file (the first is the signature 'RIFF'). The double word is '62 0F 00 00' which is 3938, this is the file size. Modify it to become '5A 0F 00 00', that is '3930', now it denotes the total number of remaining bytes after the length identifier. Save the ani file.
  • Open the executable in 'Resource Hacker' or compatible resource editor, and replace 'V_1' with the modified file.
  • Save the executable and run.


You can use Greenfish Icon Editor to open your animated cursors and then save again. It seems to produce compatible files.

这篇关于再一次来自程序资源的动画(* .ani)游标(Delphi 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆