C# 创建跨平台的 Windows、Mac OS X 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/252514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 20:02:37  来源:igfitidea点击:

Create a cross platform Windows, Mac OS X application

c#.netobjective-ccocoarealbasic

提问by armahg

I would like to build an application that runs on both Windows and Mac OS X. I would also like it to leverage the best of what the platform it runs on has to offer with regards to Frameworks, API's etc. Is there a way to do this without having to write Objective-C code and then C# code? I've been thinking of C++ as an alternative but I was wondering if there was anything else out there. The app will be GUI based (though I don't know exactly what it will do yet)

我想构建一个可以在 Windows 和 Mac OS X 上运行的应用程序。我还希望它利用它所运行的平台在框架、API 等方面所提供的最好的东西。有没有办法做这无需编写 Objective-C 代码,然后编写 C# 代码?我一直在考虑将 C++ 作为替代方案,但我想知道是否还有其他方法。该应用程序将基于 GUI(虽然我还不知道它会做什么)

采纳答案by Sherm Pendley

It's good that you're thinking of portability early on - it's vastly more difficult to "bolt it on" after the fact.

很高兴您尽早考虑可移植性 - 事后“固定”要困难得多。

There are various cross-platform kits available, but IMHO all of them fall a bit short of providing a "native" look and feel on all the supported platforms. On the Mac (what I use), proponents of such kits always want to mention that they're using native controls. That's a good start, but it's not the whole journey. Other issues addressed by Apple's Human Interface Guidelinesinclude how the controls should be arranged, how button labels should be phrased, what standard shortcut keys should be used, etc.

有各种跨平台套件可用,但恕我直言,所有这些套件都无法在所有支持的平台上提供“本机”外观和感觉。在 Mac(我使用的)上,此类套件的支持者总是想提及他们使用的是本机控件。这是一个好的开始,但这不是整个旅程。Apple 的人机界面指南解决的其他问题包括控件的排列方式、按钮标签的措辞方式、应使用的标准快捷键等。

Even Microsoft had to learn the hard wayabout the dangers of trying to write a cross-platform GUI, with the ill-fated Word 6.0 for Mac.

甚至 Microsoft 也不得不艰难地学习尝试使用命运多舛的 Word 6.0 for Mac 编写跨平台 GUI 的危险。

IMHO, a better approach is to use an MVCdesign, with the model layer written in standard, portable C++, and the view and controller layers using the native toolkit for each platform. For the Mac version, Carbon and C++ throughout used to be an interesting option that is now not supported anymore, so you would want to use Cocoa, using Objective-C in the view and Objective-C++ in your controllers to bridge the language gap. Your Windows version could likewise compile your model as "managed C++", and use any .NET language for controllers and views.

恕我直言,更好的方法是使用MVC设计,模型层用标准的、可移植的 C++ 编写,视图和控制器层使用每个平台的本机工具包。对于 Mac 版本,Carbon 和 C++ 一直是一个有趣的选项,现在不再受支持,因此您可能希望使用 Cocoa,在视图中使用 Objective-C,在控制器中使用 Objective-C++ 来弥合语言差距。您的 Windows 版本同样可以将您的模型编译为“托管 C++”,并为控制器和视图使用任何 .NET 语言。

回答by BenB

For the GUI, I'd look into SDL or QT.

对于 GUI,我会研究 SDL 或 QT。

Also, check out mono http://mono-project.com/Main_Page

另外,请查看单声道http://mono-project.com/Main_Page

回答by James Van Huis

As long as you are not tied to languages, it looks like Java is a good candidate. Pair that up with SWT for the GUI, and you will have a native looking app on any OS you like.

只要您不依赖于语言,Java 似乎是一个不错的选择。将它与用于 GUI 的 SWT 配对,您将在您喜欢的任何操作系统上拥有一个具有本机外观的应用程序。

回答by Robert S.

Take a look at Real Studio. Seriously. You can write an app in Real Studio and deploy it on Windows, Mac OS X, and Linux.

看看真正的工作室。严重地。您可以在 Real Studio 中编写应用程序并将其部署在 Windows、Mac OS X 和 Linux 上。

Edit: Real Studio is now Xojo.

编辑: Real Studio 现在是Xojo

回答by Ana Betts

If you're a Windows developer, use either Qt or C# Winforms; if you're a Mac developer, you could try Cocotron (http://www.cocotron.org/), but it's not 100% finished yet, though commercial apps have been shipped with it.

如果您是 Windows 开发人员,请使用 Qt 或 C# Winforms;如果您是 Mac 开发人员,您可以尝试 Cocotron ( http://www.cocotron.org/),但它还没有 100% 完成,尽管商业应用程序已经随附。

回答by Jamie Love

wxWidgetsis a cross platform C++ library, which is a practical choice. But I agree with Sherm - all cross platform libraries do create an inferior UI to native applications.

wxWidgets是一个跨平台的C++库,是一个实用的选择。但我同意 Sherm - 所有跨平台库都创建了比本机应用程序差的 UI。

It's made harder by each OS having different UI semantics (button orders etc), so while you may achieve a good look, getting the 'feel' right on each platform via one view layer is almost bound to be impossible.

每个操作系统都具有不同的 UI 语义(按钮顺序等),这使得它变得更加困难,因此虽然您可以获得漂亮的外观,但通过一个视图层在每个平台上获得正确的“感觉”几乎是不可能的。

Depending on what you end up doing, you may find a web interface better (e.g. embed a web server in your app and serve HTTP pages to a browser). You avoid the L&F issues then!

根据您最终要做的事情,您可能会发现一个更好的网络界面(例如,在您的应用程序中嵌入一个网络服务器并向浏览器提供 HTTP 页面)。那么你就避免了 L&F 问题!

Alternatively, you can decide you're just going to have a completely non-standard L&F, and go for something like wxWidgets, or Tcl/Tk.

或者,您可以决定只拥有一个完全非标准的 L&F,并使用 wxWidgets 或 Tcl/Tk 之类的东西。

回答by MusiGenesis

I'm planning to do a similar thing, and I'm considering creating a C#/.NET Windows application and then porting it to OS X using Mono. My application already has a completely (except for the title bar and corner buttons) custom-drawn user interface, so the cosmetic OS differences shouldn't affect me too much.

我打算做一个类似的事情,我正在考虑创建一个 C#/.NET Windows 应用程序,然后使用 Mono 将它移植到 OS X。我的应用程序已经有一个完全(除了标题栏和角按钮)自定义绘制的用户界面,因此外观操作系统差异应该不会对我产生太大影响。

I'm not sure what you mean by leveraging the best of each platform in terms of frameworks and APIs and so forth. In general, writing a cross-platform application means writing to a least common denominator, and thus means notgetting the best out of each platform.

我不确定在框架和 API 等方面利用每个平台的最佳优势是什么意思。通常,编写跨平台应用程序意味着编写最小公分母,因此意味着不能充分利用每个平台。

回答by Jay

If you do decide to go with C++ there are a number of good cross-platform GUI libraries that will allow you to avoid having to duplicate the GUI code for each platform. For example:

如果您决定使用 C++,那么有许多优秀的跨平台 GUI 库可以让您避免为每个平台复制 GUI 代码。例如:

There are a number of other similar projects but those are some of the better and more well-known ones. For the remainder of your code, anything system-specific will of course have to be written using separate C++ code to interface with Win32 APIs or OS X's system API where necessary. That being said, you may find you're able to avoid much of the system-specific code by using extensive libraries like Boost.

还有许多其他类似的项目,但这些是一些更好和更知名的项目。对于您的其余代码,当然必须使用单独的 C++ 代码编写任何特定于系统的代码,以便在必要时与 Win32 API 或 OS X 的系统 API 接口。话虽如此,您可能会发现通过使用诸如Boost 之类的扩展库,您可以避免许多特定于系统的代码。

Other suggestions would be things like using a configuration file instead of the Windows registry or a plist file on the mac. Instead, shoot for platform-agnostic approaches wherever possible to minimize the places where you have to write code using system APIs.

其他建议是使用配置文件而不是 Windows 注册表或 Mac 上的 plist 文件。相反,尽可能采用与平台无关的方法,以尽量减少必须使用系统 API 编写代码的地方。

回答by titaniumdecoy

You should use the best tools available for each OS.

您应该使用适用于每个操作系统的最佳工具。

C/C++ code can be separated from the GUI and used in each separately developed program.

C/C++ 代码可以从 GUI 中分离出来,并在每个单独开发的程序中使用。

Before you make a decision, take a look at cross-platform apps that have been developed with portable toolkits such as Qt or wxWidgets. In my experience they are never as polished as their native counterparts, especially on the mac.

在您做出决定之前,请查看使用 Qt 或 wxWidgets 等便携式工具包开发的跨平台应用程序。根据我的经验,它们从来没有像它们的本地同类产品那样精致,尤其是在 mac 上。

回答by dkretz

Adobe Flex, with the AIR libraries, does a good job of giving you a single, highlevel development environment for this sort of thing. I've written several utilities that people use on both platforms interchangeably.

带有 AIR 库的 Adob​​e Flex 在为此类事情提供单一的高级开发环境方面做得很好。我编写了几个实用程序,人们可以在两个平台上交替使用它们。

You also get reasonable portability to a browser thrown in, too, if that's of interest. But I think it's a pretty good solution without considering that benefit.

如果感兴趣的话,您还可以获得对浏览器的合理可移植性。但我认为这是一个很好的解决方案,而无需考虑该好处。