Created
August 13, 2020 23:19
-
-
Save peterhellberg/2b2d559e07ec0a715ad2f73b47274790 to your computer and use it in GitHub Desktop.
Trimmed down https://stackoverflow.com/a/59596600 to make it even more minimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on https://stackoverflow.com/a/59596600 | |
// Minimal Pure C code to create a window in Cocoa | |
// $ clang minimal.c -framework Cocoa -o minimal.app | |
#include <objc/runtime.h> | |
#include <objc/message.h> | |
#include <Carbon/Carbon.h> | |
#define cls objc_getClass | |
#define sel sel_getUid | |
#define msg ((id (*)(id, SEL, ...))objc_msgSend) | |
#define cls_msg ((id (*)(Class, SEL, ...))objc_msgSend) | |
int main(int argc, char *argv[]) | |
{ | |
id app = cls_msg(cls("NSApplication"), sel("sharedApplication")); | |
msg(app, sel("setActivationPolicy:"), 0); | |
struct CGRect frameRect = {0, 0, 512, 256}; | |
id window = msg( | |
cls_msg(cls("NSWindow"), sel("alloc")), | |
sel("initWithContentRect:styleMask:backing:defer:"), | |
frameRect, 0, 2, false); | |
msg(window, sel("makeKeyAndOrderFront:"), nil); | |
msg(app, sel("activateIgnoringOtherApps:"), true); | |
msg(app, sel("run")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot of the window in all its glory: