为什么 C 中的 PAINTSTRUCT 是 PASCAL 中的 TpaintStruct?

发布于 2024-12-15 09:52:35 字数 685 浏览 1 评论 0原文

我正在查看从 C 移植到 PASCAL (win32 API) 的应用程序,但无法理解为什么 C 中的 PAINTSTRUCT 类型更改为 PASCAL 中的 TpaintStruct。

以下是可以看到的片段:

long FAR PASCAL ClientWndProc(HWND hwnd, UINT msg, UINT mp1, LONG mp2)
{
    static int cxClient, cyClient;
    HBITMAP hbm;
    BITMAP bm;
    PAINTSTRUCT ps;
    ...

变成

function ClientWndProc(hwnd: WinTypes.HWND; msg: Word; mp1: Word; mp2: Longint): Longint; export;

var
    hdc: WinTypes.HDC;
    hdcMem: WinTypes.HDC;
    hbm: WinTypes.HBITMAP;
    bm: TBITMAP;
    ps: TpaintStruct;
    ...

我需要自己移植一个应用程序。同样的事情也应该适用于 TEXTMETRIC 类型吗?我应该在 PASCAL 中将其称为 TtextMetric 吗?

I was looking through an application being ported from C to PASCAL (win32 API) and cannot understand, why the type PAINTSTRUCT in C changes to TpaintStruct in PASCAL.

Here are the snippets where it could be seen:

long FAR PASCAL ClientWndProc(HWND hwnd, UINT msg, UINT mp1, LONG mp2)
{
    static int cxClient, cyClient;
    HBITMAP hbm;
    BITMAP bm;
    PAINTSTRUCT ps;
    ...

turns into

function ClientWndProc(hwnd: WinTypes.HWND; msg: Word; mp1: Word; mp2: Longint): Longint; export;

var
    hdc: WinTypes.HDC;
    hdcMem: WinTypes.HDC;
    hbm: WinTypes.HBITMAP;
    bm: TBITMAP;
    ps: TpaintStruct;
    ...

I need to port one app myself. Should the same thing apply to TEXTMETRIC type as well? Should I call it TtextMetric in PASCAL?

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

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

发布评论

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

评论(3

纵山崖 2024-12-22 09:52:35

Delphi(以及之前的 Turbo Pascal,IIRC)一直习惯于使用 T 为类型添加前缀,例如 TStringListTButtonTCustomFormTDateTime 等等。

您可以在 Windows.pas 单元中找到已为您声明的 TTextMetric(和 TPaintStruct),以及许多标准 WinAPI 函数。

(顺便说一下,WinTypes 已被弃用。它是 Delphi 1 中针对 16 位应用程序的旧版本,在更高版本的 Delphi 中自动被 Windows 取代。)

Delphi (and Turbo Pascal before it, IIRC) has always had the custom of prefixing types with T, as in TStringList, TButton, TCustomForm, TDateTime, and so forth.

You can find TTextMetric (and TPaintStruct) declared for you already in the Windows.pas unit, along with many of the standard WinAPI functions.

(WinTypes is deprecated, by the way. It's an old carryover from Delphi 1 for 16 bit apps, and is automatically replaced by Windows in later versions of Delphi.)

心病无药医 2024-12-22 09:52:35

这样做只是为了更好地符合 Pascal 的命名约定。如果您愿意,您可以遵循它,您的代码将看起来更像 Pascal,但如果您不这样做,也不会发生任何不好的事情。

It's just so it will fit better with Pascal's naming convention. You can follow it if you want and your code will look more Pascal-like, but nothing bad will happen if you don't.

清风夜微凉 2024-12-22 09:52:35

Pascal 最初有一个统一的标识符命名空间。这意味着 X 作为类型和 X 作为变量名、字段等会发生冲突。

为了弥补 API 在 C 中的工作方式不同这一事实(因此未能真正与语言无关),引入了一种约定,以 T 为前缀类型。

据我所知,这已经为 Turbo Vision 完成了,Turbo Vision 是为其添加了 OOP 的包到(涡轮)帕斯卡。据我所知,这是 C++ 的移植。

后来,在德尔福,这个方案得到了扩展。 (例如使用“A”作为参数名称)。但是 Delphi 中的一些匈牙利符号也可能对 GUI 设计者有利。

据我所知,仅在 D4 中,Delphi 允许字段类型标识符与字段名称相同。

Pascal originally had an unified namespace for identifiers. That means that X as a type and X as an variablename, field etc would clash.

To remedy APIs that exploited the fact that this works differently in C (and thus failed to be truely language agnostic), a convention was introduced to prefix types with T.

Afaik this was already done for Turbo Vision, the package for which OOP was added to (Turbo)Pascal. Which, afaik, was a port from C++.

Later, in Delphi this was scheme was expanded. (using e.g. "A" for parameter names). But some of the hungarian notation in Delphi might have been for the GUI designer's benefit too.

Afaik only in D4, Delphi allowed fieldtype identifiers to be the same as fieldnames.

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