Xcode allows to get a window on the Mac very fast:
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijteu8-W-usp2ZyQy4QUweGtRyTaXq9NMEQhamFo-YEZP-Q-5DR0T_QLZaWwx3pGRgFP8kjNJWeLJgweP7PG64oVfT3tDEvt0JZbtunZdBKBkaKEb8EhgqQS7PIxromWb6DwFNAbFVggw/s320/Picture+2.png)
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[])Now it is much shorter - simply one function (as it should be in the procedural language) with few lines of code:
{
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;
}
1. Call CreateNibReference function to create the resource object. Call DisposeNibReference in order to release it.
2. Call SetMenuBarFromNib function in order to set the application menu.
3. Call CreateWindowFromNib to create the window from the resource.
4. Call ShowWindow to show the window.
5. Use RunApplicationEventLoop function to start the application event loop.
For a test purpose I can comment (or delete) three window related lines and the function will look like:
int main (int argc, char* argv[])Now this code compiled and launched creates only the menu.
{
IBNibRef nibRef;
CreateNibReference (CFSTR ("main"), &nibRef);
SetMenuBarFromNib (nibRef, CFSTR("MenuBar"));
DisposeNibReference (nibRef);
RunApplicationEventLoop ();
return 0;
}
Let's remove everything:
int main (int argc, char* argv[])Build and Go:
{
RunApplicationEventLoop ();
return 0;
}
I do remember very well how looks the minimal window application for Microsoft Windows.
Apple Carbon programming. Quick start.
No comments:
Post a Comment