Tuesday, October 24, 2017

Showing a Cocoa UI Alert Panel in pure C

You can display an AlertPanel even if you have a strictly command line app. In the example below it shows a NSPanel called from pure C.


    id app = NULL;

    id pool = (id)objc_getClass("NSAutoreleasePool");

    if (!pool)
    {
        return -1;
    }
    pool = objc_msgSend(pool, sel_registerName("alloc"));
    if (!pool)
    {
        return -1;
    }
    pool = objc_msgSend(pool, sel_registerName("init"));

    app = objc_msgSend((id)objc_getClass("NSApplication"),

                       sel_registerName("sharedApplication"));

    NSRunAlertPanel(CFSTR("Test"),

                    CFSTR("Your App is running!"),
                    CFSTR("Ok"), NULL, NULL);
    
    objc_msgSend(pool, sel_registerName("release"));

No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...