简体   繁体   English

在 Delphi 7 的表格上显示动画.ani cursor

[英]Showing an animated .ani cursor on a form in Delphi 7

My application is loading list items from a database in the background with a separate thread.我的应用程序正在使用单独的线程在后台从数据库中加载列表项。 During the loading process the user can interact with the application, so I don't want to change the default cursor.在加载过程中,用户可以与应用程序交互,所以我不想更改默认的 cursor。 Still, to visually signal the loading process, I'd like to display the Windows busy (hourglass, IDC_WAIT) cursor on my form like an animated image.尽管如此,为了直观地显示加载过程,我想在我的表单上显示 Windows 忙碌(沙漏,IDC_WAIT)cursor,就像动画图像一样。 What would be the easiest way to do that?最简单的方法是什么? I was thinking of converting to a GIF and displaying in a GIFImage but I'd like to display the default Windows cursor (thus getting the resource from the system dynamically).我正在考虑转换为 GIF 并在 GIFImage 中显示,但我想显示默认的 Windows cursor (从而动态地从系统获取资源)。

Note: I'm using Delphi7.注意:我使用的是 Delphi7。

Just a partial solution: Declare variables只是部分解决方案:声明变量

h: HICON;
FFrameIdx: Integer;

Then load the cursor:然后加载 cursor:

h := LoadImage(0, MakeIntResource(OCR_WAIT), IMAGE_CURSOR, 0, 0, LR_SHARED);

Then draw the current frame in the OnPaint handler:然后在OnPaint处理程序中绘制当前帧:

DrawIconEx(Canvas.Handle, 100, 100, h, 0, 0, FFrameIdx, 0, DI_NORMAL);

To animate it, you can use a TTimer with this code:要对其进行动画处理,您可以将TTimer与以下代码一起使用:

Inc(FFrameIdx);
Invalidate; // or something more suitable

To try this, you can just put the variables in a new VCL application's main form class (below private ), put the LoadImage in the form's OnCreate handler and the DrawIconEx in the OnPaint handler.要尝试此操作,您只需将变量放入新 VCL 应用程序的主窗体 class(在private下方)中,将LoadImage放在窗体的OnCreate处理程序中,将DrawIconEx放在OnPaint处理程序中。

But if you want to use this in a real app, you'd better create a new custom control with it.但是如果你想在一个真正的应用程序中使用它,你最好用它创建一个新的自定义控件。

Obviously, you need to replace FFrameIdx with FFrameIdx mod FFrameCount or Inc(FFrameIdx) with FFrameIdx:= Succ(FFrameIdx) mod FFrameCount , where FFrameCount is the number of frames in the animated cursor.显然,您需要将FFrameIdx替换为FFrameIdx mod FFrameCountInc(FFrameIdx)替换为FFrameIdx:= Succ(FFrameIdx) mod FFrameCount ,其中FFrameCount是动画 cursor 中的帧数。

You should also set the timer's Interval to match the cursor's frame rate.您还应该设置计时器的Interval以匹配光标的帧速率。

录屏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM