FROM : Eric Schlegel
DATE : Sun Nov 04 17:25:36 2007
On Nov 3, 2007, at 5:15 PM, Robert Nikander wrote:
> Okay... I've got a menu to show up, but the behavior seems to depend
> on the location of the executable file, which I don't understand.
>
> If I put the code below in a file called "cocoa.m" and compile it
> from the command line with:
>
> gcc -o cocoa cocoa.m -framework Cocoa
>
> and I run it like this:
>
> ./cocoa
>
> then no menu shows up. But if I copy the binary into a bundle
> directory, like this:
>
> cp cocoa CocoaTest.app/Contents/MacOS/CocoaTest
>
> and run that same binary, at the different location:
>
> ./CocoaTest.app/Contents/MacOS/CocoaTest
>
> then the menu bar shows up.
>
> Why the difference? Does a cocoa binary have to run from within a
> bundle directory?
mach-o binaries on Mac OS X (whether they're Carbon or Cocoa) must be
run from within a bundle in order to get the normal GUI interface and
process management behavior. That includes being able to click on the
app's windows to make it active and get a menubar.
It's recommended to just use a bundle, but if you really want to use a
flat file, you can call TransformProcessType (HIServices/Processes.h)
from main() to make the app foreground-capable.
-eric
DATE : Sun Nov 04 17:25:36 2007
On Nov 3, 2007, at 5:15 PM, Robert Nikander wrote:
> Okay... I've got a menu to show up, but the behavior seems to depend
> on the location of the executable file, which I don't understand.
>
> If I put the code below in a file called "cocoa.m" and compile it
> from the command line with:
>
> gcc -o cocoa cocoa.m -framework Cocoa
>
> and I run it like this:
>
> ./cocoa
>
> then no menu shows up. But if I copy the binary into a bundle
> directory, like this:
>
> cp cocoa CocoaTest.app/Contents/MacOS/CocoaTest
>
> and run that same binary, at the different location:
>
> ./CocoaTest.app/Contents/MacOS/CocoaTest
>
> then the menu bar shows up.
>
> Why the difference? Does a cocoa binary have to run from within a
> bundle directory?
mach-o binaries on Mac OS X (whether they're Carbon or Cocoa) must be
run from within a bundle in order to get the normal GUI interface and
process management behavior. That includes being able to click on the
app's windows to make it active and get a menubar.
It's recommended to just use a bundle, but if you really want to use a
flat file, you can call TransformProcessType (HIServices/Processes.h)
from main() to make the app foreground-capable.
-eric
| Related mails | Author | Date |
|---|---|---|
| Robert Nikander | Nov 3, 18:12 | |
| Jeff Johnson | Nov 3, 18:37 | |
| Jeff Johnson | Nov 3, 18:46 | |
| mmalc crawford | Nov 3, 19:29 | |
| Robert Nikander | Nov 3, 19:54 | |
| Robert Nikander | Nov 3, 20:08 | |
| mmalc crawford | Nov 4, 00:13 | |
| Robert Nikander | Nov 4, 01:15 | |
| Eric Schlegel | Nov 4, 17:25 | |
| Robert Nikander | Nov 4, 18:05 |






Cocoa mail archive

