0

I'm making a cross platform application that's written in C++. I am looking to basically create a Window on a macos app from scratch in the main method. What I mean by this is if I create a new Cocoa Storyboard Obj-C app, it gives me main.m. In main.m, it calls NSApplicationMain, which in turn does something that starts up a window.

My question is how do I emulate what NSApplicationMain does but starting a different window?

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • 2
    `NSApplicationMain` does a lot more for the lifetime of your app than just creating a window (e.g. it sets up a run loop for your app). The initial window you're seeing is almost certainly a byproduct of there being a window in the default storyboard in your app, which you can delete if you'd like. Instead, you can intercept [`applicationDidFinishLaunching`](https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428385-applicationdidfinishlaunching) and create any windows you want there. Is that sufficient for your usecase? – Itai Ferber Oct 15 '20 at 19:56
  • Aha! Yes! I will try that! Thank you! – personmanperson Oct 15 '20 at 19:57
  • @ItaiFerber I have deleted the storyboard, and also in the app settings set main view to empty. THen in applicationDidFinishLaunching I created a new NSWindowController through the contrustor and showed it, but no window appears – personmanperson Oct 15 '20 at 20:17
  • Also, I'm planning to custom draw everything, so I insatiate a new NSWindowController that is not attached with any Nibv – personmanperson Oct 15 '20 at 20:17
  • 1
    One of the things the storyboard file does for you by default is set up an instance of your `AppDelegate` (if you've stuck with the default template) as your application's delegate. If you delete it, you'll need to do that manually in `main.m`, prior to the call to `NSApplicationMain`: `AppDelegate *delegate = [[AppDelegate alloc] init]; [[NSApplication sharedApplication] setDelegate:delegate]; return NSApplicationMain(argc, argv);` – Itai Ferber Oct 15 '20 at 22:14
  • You can combine objc and c++ in a .mm file and compile with clang. What language are you going to use for the window and how will you handle events? – apodidae Oct 16 '20 at 02:58

0 Answers0