nsstatusbar/item

nilobject

Registered
hey,
i'm only just learning c and obj-c and am trying to make a menu extra like the ppp, monitors and sound menus in CoreServices. i have all the code for the menuitems to work, but i can't figure out how to get a menu up there.
my current source looks like this:

#include <Cocoa/Cocoa.h>

int main(void){
NSStatusBar *menuBar = [NSStatusBar systemStatusBar];
NSStatusItem *bpaMenuStatusItem = [[menuBar statusItemWithLength:NSVariableStatusItemLength] retain];

[bpaMenuStatusItem setTitle: NSLocalizedString(@"Bigpond",@"")];
[bpaMenuStatusItem setHighlightMode:YES];
return 1;
}

---------
this is copied almost fully from the apple tech docs on status bars.
when i run the code i get this error:
*** _NSAutoreleaseNoPool(): Object 0x90a70 of class NSCFData autoreleased with no pool in place - just leaking

so i'm assuming that means i haven't alocated it some memory? do i need to malloc it or something? or is that only in c? i've tried searching for source code to help me, but noone seems to have any.

any help would be the greatest thing ever, as this is driving me insane.

thanks
nilobject
 
You need to make a full-fledged Cocoa Application (if this isn't - I can't tell if this is just a commandline program or just your main.m in a Cocoa app).

You should add this code (notice the similarity to your code) to your controller classes (you should make one) which you instantiate in IB:

Code:
- (void)awakeFromNib
{
    NSStatusBar *menuBar = [NSStatusBar systemStatusBar];
    NSStatusItem *bpaMenuStatusItem = [[menuBar statusItemWithLength:NSVariableStatusItemLength] retain];

    [bpaMenuStatusItem setTitle: NSLocalizedString(@"Bigpond",@"")];
    [bpaMenuStatusItem setHighlightMode:YES];
}

Then all will be well.

HTH,
Matt Fahrenbacher
 
Back
Top