Create a cross platform Windows, Mac OS X application

℡╲_俬逩灬. 提交于 2019-11-29 19:47:00
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 Guidelines include how the controls should be arranged, how button labels should be phrased, what standard shortcut keys should be used, etc.

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

IMHO, a better approach is to use an MVC design, 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.

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.

Edit: Real Studio is now Xojo.

wxWidgets is 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.

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.

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!

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.

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.

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.

My suggestion, use Python. Python integrates with both Objective-C and C# (IronPython). Just avoid a lot of the brand new bleeding edge features of the language and you're ok.

Granted, it won't be mindlessly easy. But I'd argue that it shouldn't be mindlessly easy. It becomes very apparent when designers don't take into consideration how their application will work when it gets ported to another platform.

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

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

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:

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.

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.

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.

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.

The upcoming QT-Creator might be worth a look: link text

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.

thanks for all your answers. I've been doing some research and playing around with WPF and CAnimation etc. It looks like using a C/C++ model and doing the GUI individually for each platform is the best way to go. Thanks for all your help.

Also check out fltk , wxWidgets is very good & rich but also very big...

As others have mentioned is is definitely possible to create good looking cross platform GUI in Java on both Windows and Mac. However if you want your app to blend in and behave in a way that makes it "feel" like an application designed from the ground up for the platform it is running on, you really have to develop the GUI and user experience for each version of the application separately.

If you analyze what your application is going to do and figure that there is a significant portion of code/logic that could be shared between platforms then write that portion in a portable way in a language that is available on both systems. C, C++, Java, Python, Ruby, etc. If there isn't a significant portion, ie most of the code is going to be for the GUI then there is less of a case for sharing any code at all.

In the case that there is a significant portion of common code, I would suggest looking into Python and Ruby as implementation languages as there are Cocoa bindings for those languages on the Mac and on Windows with the use of IronPython and IronRuby you could use reuse that code in a .Net application as well.

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.

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.

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 not getting the best out of each platform.

Java or Mono come to my mind. Some people may argue that java graphical toolkits are not the cuttest out there but it seems to be, at least to me, the easiest way to port your application to several platforms and avoid deployment difficulties.

Mono, on the other hand, could be a little bit more difficult to port as you would have to write at least the gui twice if you plan to have native widgets (either winforms or GTK for windows and CocoaSharp for Max) but you could write the backend only once and develop a frontend for each platform.

As I said, Java GUI toolkits might not feel "native" inside OSX or even on Windows but they sure work on both platforms, you could use either Swing or AWT.

As for mono, you can use GTK or Winforms for both windows and OSX but they still will not feel native, you can, however use CocoaSharp which are bindings to the Cocoa framework but Im not sure about the status of the project (read: functionality support)

I second Java. It is designed as a cross-platform solution.

Others have mentioned Adobe Air.

Similar to Adobe Air is Silverlight. I believe it is (or will be) completely cross platform.

You can create fantastic looking cross platform applications with Java Swing. It just requires slightly more effort to learn to do so.

Here, take a look at some of these links.

  1. http://jidesoft.com/products/component.htm
  2. http://www.xerto.com/imagery.php
  3. http://www.jgraph.com/screenshots.html
  4. http://www.javootoo.com/
  5. http://www.formdev.com/screenshots/
  6. http://www.jidesoft.com/products/oss.htm

The guys at Magnetism Studios have a nice write up on using Cocotron to build a Windows executable with Xcode.

I have no experience with Cocotron, but if I needed to write a windows app —with a Mac development background— this would be the first thing I'd try.

If you choose C++ language, I would definitely recommend Qt for that. Your application can be deployed under Windows and Mac as requested in the OP, but also Linux, and now, with the latest version on smartphones using iOs, Windows RT and Android.

It's well documented and very active on the web (including on SO).

The only negative point I see is Qt creator tool which, IMHO, is less user friendly than historical tools (like Visual Studio for instance ), but you are not actually forced to use it as an IDE for Qt development.

For completeness, it's now worth adding Unity to the list.

It would be very hard to create a native-looking app for either platform and the general GUI tools are far from mature. But, it's not just a game engine and you can write in C#/Mono, make use of a decent range of libs and deploy to Win and OSX fairly painlessly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!