In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system.
I've never seen this model. I did see this one: I'm not that old. At that time I was a student. When I began to work as a Software engineer, we already had Intel 386, MS-Dos, Microsoft Windows 3.1. Since that I'm the biggest fun of Microsoft - Visual C++, MFC, ATL, COM, DCOM, COM+,.NET, C#,...
Few months ago I bought iPhone. Then Mac mini. I made my first applications for this phone. Then, for my Mac... Goodbye, Microsoft?
I think I found a very easy way to step in to the world of the Apple programming. In this short article I want to show how to begin, how to make a first Mac OS X program. I'm not going to scare anyone, I will not talk about Objective-C, I will not use Cocoa. These are very amazing things, but it is, obviously, not the easiest start.
We all began from the super language - our old and respectful C. From my point of view, it is extremely easy to begin programming for Mac OS X from Carbon - an old procedural 32bit API for developing Mac OS X application.
Project Hello
In case you have a Mac and Xcode installed on it, it will take 2 seconds to make a window application on Mac:
1. Create new project - File menu -> New Project...
2. Choose Carbon Application template in the Application section in the New Project wizard and press Choose button (in the bottom-right corner).
3. Set the project name and press Save button.
4. Press Build and Go.
Here are few images illustrating these steps above:
It runs. The window knows how to minimize and maximize itself. The application has the standard Apple menu.
Source code
The application source code is in main.c file. Actually, everything from this file can be removed and replaced by the following code:
int main (int argc, char* argv[]){ IBNibRef nibRef; WindowRef window; // Create a nib reference to a nib file. CreateNibReference (CFSTR ("main"), &nibRef); SetMenuBarFromNib (nibRef, CFSTR("MenuBar")); CreateWindowFromNib (nibRef, CFSTR("MainWindow"), &window); // Dispose of the nib reference as soon as you don’t need it any more. DisposeNibReference (nibRef); // Make the unarchived window visible. ShowWindow (window); // Start the event loop. RunApplicationEventLoop is a // Carbon Event Manager function. RunApplicationEventLoop (); return 0;}
Build and Go: I do remember very well how looks the minimal window application for Microsoft Windows.
Conclusion
It is a first and trivial experience in the Mac OS X development. But it gives an optimistic feeling, a confidence that the knowledge in C allows to study Mac OS, to make programs for Apple immediately, without long pauses for Objective-C and Cocoa books.
Comments (0)