Skip to content

Instantly share code, notes, and snippets.

@mythosil
Created July 27, 2011 06:54
Show Gist options
  • Save mythosil/1108816 to your computer and use it in GitHub Desktop.
Save mythosil/1108816 to your computer and use it in GitHub Desktop.
cocoa sample for showing statusbar
/*
* statusbar.m
* sample for showing something to status-bar
*
* How to compile and run.
* $ gcc statusbar.m -framework Cocoa
* $ ./a.out
*/
#import <Cocoa/Cocoa.h>
@interface StatusBar : NSObject {
NSStatusItem* item;
}
- (void)sayHello;
@end
@implementation StatusBar
- (id)init
{
if ( (self = [super init]) ) {
NSStatusBar* bar = [NSStatusBar systemStatusBar];
item = [[bar statusItemWithLength:NSVariableStatusItemLength] retain];
[item setTitle:@"title"];
[item setToolTip:@"tooltip"];
[item setHighlightMode:YES];
NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"Menu"] autorelease];
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle:@"MenuItem"
action:@selector(sayHello)
keyEquivalent:@""] autorelease];
[menuItem setTarget:self];
[menu addItem:menuItem];
[item setMenu:menu];
}
return self;
}
- (void)dealloc
{
[item release];
[super dealloc];
}
- (void)sayHello
{
NSLog(@"Hello");
}
@end
int main(int argc, char** argv)
{
NSAutoreleasePool* pool;
pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
StatusBar* bar = [[[StatusBar alloc] init] autorelease];
[NSApp run];
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment