|Apr 12, 2008, 07:52 AM||#1|
Converting Windows program to Mac
I would like to convert some programs from Windows.
The programs use the Windows API (would work from Windows 95 to Windows
XP) and are heavily text-based. One important part converts a mouse-
click in a text window to the nearest line number and character ordinal
position, for example line 3 at character position 189. This is easy to do under Windows; just receive and interpret a few event messages sent by Windows to the text window (procedure).
is mouse-click to character-coordinate conversion similar?, easy to
do under Mac OS X?
I am a total Mac OS newbie and do not even own a a Mac (mini). Will go out and buy one if the answer to Q1 is affirmative!
|Apr 12, 2008, 08:27 AM||#3|
You haven't stated whether you'll be using Carbon or Cocoa. Carbon will look similar and easy since it's a C-based API just like Win32, but in the long run it isn't worth it since it's virtually being deprecated by Apple.
I'd suggest Cocoa, which may be a bit tough initially since you'll have to learn Objective-C, but it's pretty easy once you get going.
NSTextView (which is the main control for handling large amounts of text input) contains a method called characterIndexForInsertionAtPoint, which takes a single argument of type NSPoint, which you can be used with [NSEvent mouseLocation]. Once you have the character index, you can then use normal NSString methods and determine the line number and character index for that line.
Edit: robbieduncan beat me to it
|May 5, 2008, 07:00 AM||#4|
Many thanks for your advice.
The programs I am converting are written in procedural (non-OO) C++
without using MFC or NET frameworks. There are about 100 dialogs many of them non-trivial, i.e. values of certain fields determine the value sets and
mode of display of other fields. There are about 150 source files, so
at least by my standards the programs are quite large.
I also need to continue to support the programs on Windows.
I think I have two choices:
1. totally rewrite the GUI using Cocoa or Carbon for Mac and keep the
Windows programs without changes. Drawback:
two GUIs to support for the remaining lifetime of the
2. the algorithmic stuff (ca 25%) should translate without any changes.
The problem area is handling the GUI events which is different
under Windows. I have looked at Carbon and (think I) can see how to
rewrite the GUI on Windows to use and installl event handlers the way
it is done on Mac. End result: only one GUI to look after.
For this choice I could not use Cocoa for the GUI.
Not sure which alternative is best OR if there are better ways.
|May 5, 2008, 07:14 AM||#5|
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
|May 6, 2008, 02:18 AM||#6|
I've converted a lot of code from Windows (Win32) to Mac OS. Despite Carbon being "closer" to Win32, I actually find it easier to move code to Cocoa. The initial confusion is that much of what you do by hand under Windows (WinMain setup, query event loop and message dispatch to the dialog handler or your window's WndProc event handler) is done for you. If you dig deep enough you'll find much of this is handled automatically in the NSApplication class and Cocoa run loop. As far as processing events, each Cocoa view class (including text views) have explicit methods to handle events rather than having to decode wparam and lparam values sent to your event handler function. For example, Cocoa implements a drawRect: method which is equivalent to WM_PAINT, mouseDown: which is equivalent to WM_LBUTTONDOWN etc.
I can understand wanting to maintain only one code base, but there will always be differences at the interface level. Check out Model-View-Controller if you haven't already. This is a very good way of organizing your code to minimise code changes from one platform to the next,
Also, setting up and maintaining interfaces using Interface Builder is far easier than using Visual Studio with Win32 (which seems geared towards MFC and .NET).
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Converting Mac ti Windows formatted iPod||milomak||iPod||3||Apr 9, 2013 01:58 PM|
|Please help - Trying to run a Windows program on a Mac||Calpurnia33||Windows, Linux & Others on the Mac||0||Dec 26, 2012 06:48 PM|
|Converting Terminal Window Program to Desktop||jamesadrian||Mac OS X 10.7 Lion||0||Sep 24, 2012 11:57 AM|
|Is it easy to program Windows programs on a Mac?||macuser1232||Mac Programming||12||Jun 30, 2012 06:57 AM|
All times are GMT -5. The time now is 02:50 AM.