c# - 我们能得到已经打开的NSWindow的类名吗?

标签 c# objective-c cocoa nswindow

我们有获取 C# 类名的代码,例如

// Get Window class
var windowClass = new StringBuilder(256);
Win32.GetClassName((IntPtr) hwnd, windowClass, windowClass.Capacity);
 String windowClassName = windowClass.ToString();

如何在 Objective C 中转换它?

最佳答案

简短回答:该代码没有 Mac 版本,因为在 Mac 上窗口没有这种意义上的“类名”。您询问的是 Mac 没有的 Windows API 详细信息。

<小时/>

Anoop Vaidya 的答案对于 Objective-C 中“类”的含义是正确的,但对于 Windows 中“窗口类”的含义则不正确。

Here's what a window class in Windows looks like.窗口类定义了很多东西;以下只是其中一些:

  • lpfnWndProc: A pointer to the window procedure. You must use the CallWindowProc function to call the window procedure. For more information, see WindowProc.

  • hIcon: A handle to the class icon. This member must be a handle to an icon resource. If this member is NULL, the system provides a default icon.

  • hCursor: A handle to the class cursor. This member must be a handle to a cursor resource. If this member is NULL, an application must explicitly set the cursor shape whenever the mouse moves into the application's window.

  • hbrBackground: A handle to the class background brush. [lots and lots of details follow on that one]

  • lpszMenuName: Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have no default menu.

  • hIconSm: A handle to a small icon that is associated with the window class. If this member is NULL, the system searches the icon resource specified by the hIcon member for an icon of the appropriate size to use as the small icon.

这与 Objective-C 类非常不同。

类(Objective-C 使用的术语)是对象的配方。类定义该类的任何对象拥有哪些实例变量(成员)、属性和方法。每个对象都有一个与之关联的类; Objective-C 意义上的类并不特定于窗口对象。

相比之下,Windows 中的“窗口类”定义了许多特定于窗口的属性。让我们看看上面的那些,看看它们的 Mac 等效项是什么:

  • 窗口过程: 据我所知,它定义了窗口的外观和对事件的响应。粗略的 Mac 等效项是窗口对象的类(在 Objective-C 意义上):NSWindow 或其任何子类。 NSWindow 子类并不多,而且几乎没有自定义子类,因为我们可以自定义各个窗口的大多数方面,而无需创建自定义 NSWindow 子类。
  • 图标(小或其他):Mac 上的大多数窗口都没有图标。文档窗口确实如此,在这种情况下,它称为代理图标,因为标题栏中的图标是窗口正在显示的文件的代理。您可以通过 telling it what file the icon should be a proxy for 设置窗口的代理图标.
  • 光标:在 Mac 上,you set the cursor at the view level 。如果您希望在整个窗口(的内容区域)中使用相同的光标,则可以将其设置在窗口的内容 View 中。
  • 背景画笔:每个窗口都有一个backgroundColor属性,它接受一个 NSColor 对象。 NSColor 反过来又提供了许多预定义的背景颜色,用作窗口背景(以及其他用途)。
  • 菜单:在 Windows 上,每个窗口都有自己的菜单栏,并且它们都有不同的菜单。在 Mac 上,只有一个菜单栏,并且大多数应用程序不会在窗口之间更改菜单栏的内容。 (当它们这样做时,通常表明该端口的作者没有足够关心尊重平台差异。)您可以这样做,但您必须自己通过更改应用程序的 mainMenu 的内容来完成此操作。当主窗口发生变化时。

“窗口类”的大多数其他成员都是更多 Windows API 细节,没有 Objective-C 等效项。

您应该仔细阅读 Apple 的 OS X Human Interface Guidelines 。 Windows 和 Mac 之间的 Windows(除其他外)工作方式存在很多差异,这些界面选择一直影响着整个 API 设计。

关于c# - 我们能得到已经打开的NSWindow的类名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20493131/

相关文章:

javascript - 在 JavaScript 中获取 ASP.NET 标签的文本或值

c# - 从模块中向 dotnetnuke 中的用户友好 url 添加条目

c# - LAB 到 RGB 使用 Lcms2 给出奇怪的结果

iphone - 更改 VIewControllers 停止动画

objective-c - 在 Objective-C 中,我有一个包含一个字母的 NSString。如何获取该字母的 ASCII 值?

javascript - 什么是 WKErrorWebViewInvalidated?

macos - CFBundleCopyExecutableURL 不返回绝对 URL

c# - 向 Linq-to-SQL 对象添加功能以执行常见选择

objective-c - 在 Objective C 中,为什么我的核心数据对象永远不会被释放?

cocoa - 需要一些有关 Cocoa MVC/KVO 模式的提示