关于头文件定义编号的问题

发布于 2024-08-18 01:29:06 字数 445 浏览 2 评论 0原文

我从未尝试过在没有 GUI 设计器的情况下开发 GUI,现在我正在通过《Palm OS 编程:开发人员指南》一书学习如何开发 Palm OS 应用程序。在它上面我有这段代码,它是一些 GUI 项目的声明:

#define HelloWorldForm 1000
#define HelloWorldButtonButton 1003
#define HelloWorldMenuBar 1000

#define GoodnightMoonAlert 1101

#define FirstBeep 1010

#define SecondBeepmore 1000

我想知道一些事情:

  • 我需要以某种顺序执行此操作?
  • 为什么我需要申报这个数字?
  • 他们会在哪些方面帮助我?
  • 他们有什么与他们的物品类型相关的东西吗?

I never tried to do a GUI without a GUI designer and now I'm learning how to develop Palm OS applications with the book Palm OS Programming: The Developers Guide. And on it I have this code that is a declaration of some GUI items:

#define HelloWorldForm 1000
#define HelloWorldButtonButton 1003
#define HelloWorldMenuBar 1000

#define GoodnightMoonAlert 1101

#define FirstBeep 1010

#define SecondBeepmore 1000

I want to know some things:

  • I need to do this in a type of order?
  • Why I need to declare this numbers?
  • In what they are going to help me?
  • They have anything connected to the type of item they are?

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

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

发布评论

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

评论(3

南街九尾狐 2024-08-25 01:29:06

它们是资源 ID。您不需要定义此类宏,但如果您不这样做,则当您尝试在代码中引用 UI 小部件时,您将不得不使用原始整数值。例如,获取指向 UI 控件的指针的典型方法是调用:

FormType* formP = FrmGetActiveForm();
UInt16 index = FrmGetObjectIndex(formP, objectID);
ControlType* controlP = FrmGetObjectPtr(formP, index);

您需要获取指向 UI 小部件的指针,以便执行诸如读取其状态(例如复选框)、更改 资源 ID 和从 FrmGetObjectPtr 返回的

指针所做的操作之间不存在类型安全;您有责任跟踪哪个 ID 对应于哪种类型的控件(常见做法是使用描述性名称)。

They resource IDs. You aren't required to define such macros, but if you don't, you'll instead have to use the raw integer values when you try to refer to the UI widgets in code. For example, the typical way you'd get a pointer to a UI control would be to call:

FormType* formP = FrmGetActiveForm();
UInt16 index = FrmGetObjectIndex(formP, objectID);
ControlType* controlP = FrmGetObjectPtr(formP, index);

You'd need to get pointers to the UI widgets in order to do things such as reading their states (such as for checkboxes), changing text labels, showing or hiding them dynamically, etc.

There's no type safety between the resource IDs and what you do with the pointer you get back from FrmGetObjectPtr; it's your responsibility to keep track of which ID corresponds to which type of control (the common practice is to use descriptive names).

柠檬色的秋千 2024-08-25 01:29:06

这些可能是与 GUI 元素相关的“人类可读的快捷方式”(似乎以 C 宏的形式):所述元素可能仅通过主机系统中的整数引用。您没有向我们提供太多可以在此处使用的详细信息。

这种技术的优点通常与更容易维护(等等)相关。

Those are probably "human readable shortcuts" (in the form of C macros it seems) associated with GUI elements: the said elements are probably only referenced through integers in the host system. You didn't provide us with much details to work with here.

The advantage of such technique is usually associated with easier maintenance (amongst others).

你爱我像她 2024-08-25 01:29:06

它们提供了一些好处。

  1. 记录代码。您愿意在源代码中进行类似 LoadForm(1000);LoadForm(HelloWorldForm); 的调用吗?
  2. 它们实际上可能被定义资源的文件使用。如果您需要对资源重新编号(也许您正在合并两个项目,这两个项目都使用 1000 表示不同的形式),则只需修改一个位置的值。

They provide a couple of benefits.

  1. Documenting the code. Would you rather have a call like LoadForm(1000); or LoadForm(HelloWorldForm); in your source code?
  2. They may actually be used by the file that defines the resources. If you ever need to renumber the resources (perhaps you are merging two projects that both used 1000 for different forms), you would only need to modify the value in a single place.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文