Created
July 27, 2011 06:54
-
-
Save mythosil/1108816 to your computer and use it in GitHub Desktop.
cocoa sample for showing statusbar
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
/* | |
* 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