我是否仅限于 Delphi 7 下 Controls.pas 中定义的光标编号?

发布于 2024-11-09 14:15:25 字数 268 浏览 0 评论 0原文

我在 Windows 7 下使用 Delphi 7 下载文件。

我想在下载过程中更改光标。

我设置了 Screen.Cursor := crHourGlass; ,但是,在查看 Controls.pas 中的常量光标编号后,我想知道是否还有其他数字我可以使用将光标更改为我不想将光标添加到我的资源文件中,我只想使用无需添加资源即可使用的标准数字 )。

I am using Delphi 7 under Windows 7 to download files.

I want to change the cursor during the download.

I set the Screen.Cursor := crHourGlass; , but , after looking at the constant cursor numbers in Controls.pas, I was wondering whether there are other numbers I can use to change the cursor into ( I don't want to add a cursor to my resource file, I just want to use standard numbers which I can use without having to add resources ).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无法回应 2024-11-16 14:15:25

其他数字是否有意义
完整光标

否。除了内置光标常量之外的其他数字将生成默认光标它与 TCursor(crDefault) 相同(换句话说 - HCURSOR(Screen.Cursors[crDefault]))。这些内置游标驻留在应用程序资源中,并在 VCL 启动时预加载。要添加自定义光标,您必须添加 CURSOR 资源,然后加载它并将其添加到 VCL。

procedure TForm1.FormCreate(Sender: TObject); platform;
const
  crCustom = 42;
var
  Cursor: HCURSOR;
begin
  Cursor := LoadCursor(HInstance, 'CUSTOM');
  Win32Check(Cursor <> 0);  // required error check
  Screen.Cursors[crCustom] := Cursor;
  { Done, newly added crCustom is ready to use }

  Self.Cursor := crCustom; // for example - lets show custom cursor

  { also, TScreen object will manage resource handle }
  { and perform cleanup for you, so DestroyCursor call is unnecessary }
end;

间接游标构造的更复杂示例 注意 :示例有很多缺陷:1) DestroyIcon 调用是错误的 2) 如果在所有 API 调用之后进行错误检查,他们会注意到这一点

does other numbers produce meaning
full cursors

No. Other numbers besides built-in cursors constants will produce a default cursor which is identical to TCursor(crDefault) (in other terms - HCURSOR(Screen.Cursors[crDefault])). These built-in cursors resides in the application resources and preloaded on VCL startup. To add custom cursor you HAVE to add CURSOR resource and then load it and add it to VCL.

procedure TForm1.FormCreate(Sender: TObject); platform;
const
  crCustom = 42;
var
  Cursor: HCURSOR;
begin
  Cursor := LoadCursor(HInstance, 'CUSTOM');
  Win32Check(Cursor <> 0);  // required error check
  Screen.Cursors[crCustom] := Cursor;
  { Done, newly added crCustom is ready to use }

  Self.Cursor := crCustom; // for example - lets show custom cursor

  { also, TScreen object will manage resource handle }
  { and perform cleanup for you, so DestroyCursor call is unnecessary }
end;

More complicated example with indirect cursor construction NB: example have numerous flaws: 1) DestroyIcon call is erroneous 2) they'd noticed it if there was error checking after all API calls

锦爱 2024-11-16 14:15:25

“标准数字”(crHourglasscrDefault 等)是 Delphi 的 VCL 提供的预定义光标。您可以定义自己的定义并通过 Windows API 从资源或文件将它们加载到应用程序中,但是没有任何神奇的未发布的 TCursor 定义(或杂散数字)具有任何意义。尝试将 Screen.Cursors[] 设置为未知数字而不首先加载光标将导致数组越界错误,最坏的情况是访问冲突导致显示默认光标(请参阅 Forms.pas 中的 TScreen.GetCursors)。

简单说明:TCursorRec 在 VCL 源代码中定义为包含指向下一条记录的指针、索引和游标句柄 (HCURSOR) 的记录。它基本上是一个单链表,当您通过访问 Cursors 列表来请求游标时,VCL 会从第一项开始遍历列表,然后依次逐步浏览,直到找到符合以下条件的索引:与您请求的索引相匹配(此时它将光标设置为该项目的 HCURSOR 值),或者确定未分配您请求的索引,在这种情况下它返回默认光标。

The "standard numbers" (crHourglass, crDefault, etc) are the predefined cursors that are provided by Delphi's VCL. You can define your own and load them into the application from a resource or from file via the Windows API, but there are no magic unpublished TCursor definitions (or stray numbers) that will mean anything. Trying to set Screen.Cursors[] to an unknown number without first loading a cursor will cause an array out of bounds error at minimum, and an access violation at the worst result in the default cursor being displayed (see TScreen.GetCursors in Forms.pas).

Quick explanation: TCursorRec is defined in the VCL source as a record containing a pointer to the next record, an index, and a cursor handle (HCURSOR). It's basically a singly-linked list, and when you ask for a cursor by accessing the Cursors list, the VCL looks through the list starting at the first item and sequentially stepping through until it either finds an index that matches the one you requested (at which point it sets the cursor to that item's HCURSOR value), or determines that the index you requested isn't assigned, in which case it returns the default cursor.

请止步禁区 2024-11-16 14:15:25

crHourGlass 的类型为 TCursor,它是一个整数别名(或多或少)。它是一个索引,可用于设置库存游标。

您可以使用添加游标,

Screen.Cursors[Number] := ...   needs to be a HCURSOR.

因此如果您有新游标的句柄,则可以在 Delphi 中使用它。

请注意,crXXX 常量和 TCursor 类型是在 Controls 中定义的,而 Screen 类是在 Forms 中定义的。所以你可以自己看看代码。

crHourGlass is of type TCursor, which is an integer alias (more or less). It is an Index that can be used to set a cursor from stock.

You can add cursors using

Screen.Cursors[Number] := ...   needs to be a HCURSOR.

So if you have a handle to a new cursor, you can use that in Delphi.

Note that the crXXX constants an the TCursor type are defined in Controls and the Screen class is defined in Forms. So you can see the code for yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文