CoreFoundation Examples

This is a work in progress, but I've completed at least the first example of simple program displaying MessageBox using only CoreFoundation framework (not using Cocoa and Objective-C) on my previous post.


Actually you can do a lot of experiments using function CFUserNotificationCreate() with different parameters, and examine the differences. But if you only need to display simple notifications like information box, then you may want to write a function that can be called multiple times with simple parameters, like:
SInt32 InfoBox(CFStringRef strTitle, CFStringRef strMessage);
Alternatively, you can also use a slightly different function, which is more simple and easy to memorize,
like the one I use in another MessageBox example.

Read the official documentation for CFUserNotification from your Xcode installation, try Help menu from your computer (activate the Xcode window first). You can find it under Help -> Developer Documentation, then Search for CFUserNotification, then experiment with various parameters you can find there. You can also find the documentation from the official Apple's website.

So far we were just writing a simple MessageBox codes, which only display a message without handling any user response. Actually Mac's CFUserNotification API, as well as the higher level interface NSAlertPanel and friends can be use as a simple user interface, if your application does not require too many Widgets. The CFUserNotificationCreate() function can include options like a RadioButton, CheckBox, and even ProgressBar, like the one I use in the following figure:

CFUserNotification with ProgressIndicator.

The MessageBox itself can have more than one button with your own choice of text to display, and the button order is really up to you. The common use of displaying more than one button is asking user response, which can have default value so that the user can just hit Return (or Enter) key to dismiss the Dialog Box with default answer. Click on the following picture to display the code:

Notification with 3 buttons.


1 comment:

  1. HI, I am quite new to the Core Foundation Framework for MAC OSx. I want to learn more about this and tried out the code for the above example of 'CFUserNotification with progress Indicator only". This is not working out , can u help share the sample code for this.

    Thank u in Advance!!
    Regards
    Paul

    ReplyDelete